feat(chat): show joined rooms on index page

This commit is contained in:
2024-11-17 21:40:46 +00:00
parent 9755dc2b9e
commit 3f97444908
2 changed files with 27 additions and 3 deletions

View File

@@ -13,7 +13,7 @@ defmodule SlaxWeb.ChatRoomLive.Index do
<div class="bg-slate-50 border rounded">
<div id="rooms" class="divide-y" phx-update="stream">
<div
:for={{id, room} <- @streams.rooms}
:for={{id, {room, joined?}} <- @streams.rooms}
class="cursor-pointer p-4 flex justify-between items-center group first:rounded-t last:rounded-b"
id={id}
phx-click={JS.navigate(~p"/rooms/#{room}")}
@@ -26,6 +26,12 @@ defmodule SlaxWeb.ChatRoomLive.Index do
</span>
</div>
<div class="text-gray-500 text-sm">
<%= if joined? do %>
<span class="text-green-600 font-bold">✓ Joined</span>
<% end %>
<%= if joined? && room.topic do %>
<span class="mx-1">·</span>
<% end %>
<%= if room.topic do %>
<%= room.topic %>
<% end %>
@@ -40,8 +46,14 @@ defmodule SlaxWeb.ChatRoomLive.Index do
@impl Phoenix.LiveView
def mount(_params, _session, socket) do
rooms = Chat.list_rooms()
socket = socket |> assign(page_title: "All rooms") |> stream(:rooms, rooms)
rooms = Chat.list_rooms_with_joined(socket.assigns.current_user)
socket =
socket
|> assign(page_title: "All rooms")
|> stream_configure(:rooms, dom_id: fn {room, _joined?} -> "rooms-#{room.id}" end)
|> stream(:rooms, rooms)
{:ok, socket}
end
end