feat(chat): show joined rooms on index page
This commit is contained in:
@@ -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
|
||||
|
Reference in New Issue
Block a user