feat(chat): simplify socket response

Add helper methods to create the tuples `{:ok, socket}` and
`{:noreply, socket}`, and make them available in `SlaxWeb` module.
This commit is contained in:
2025-02-05 00:05:49 +00:00
parent 2063870a9e
commit 489be57db7
5 changed files with 72 additions and 64 deletions

View File

@@ -62,13 +62,11 @@ defmodule SlaxWeb.ChatRoomLive.Index do
def mount(_params, _session, socket) do
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}
socket
|> assign(page_title: "All rooms")
|> stream_configure(:rooms, dom_id: fn {room, _joined?} -> "rooms-#{room.id}" end)
|> stream(:rooms, rooms)
|> ok()
end
@impl Phoenix.LiveView
@@ -78,7 +76,9 @@ defmodule SlaxWeb.ChatRoomLive.Index do
|> Chat.get_room!()
|> Chat.toggle_room_membership(socket.assigns.current_user)
{:noreply, stream_insert(socket, :rooms, {room, joined?})}
socket
|> stream_insert(:rooms, {room, joined?})
|> noreply()
end
defp open_room(room) do