defmodule SlaxWeb.ChatRoomLive do @moduledoc false use SlaxWeb, :live_view alias Slax.Chat alias Slax.Chat.Room @impl Phoenix.LiveView def render(assigns) do ~H"""

Slax

Rooms
<.room_link :for={room <- @rooms} room={room} active={room.id == @room.id} />

#<%= @room.name %>

<%= if @hide_topic? do %> [Topic hidden] <% else %> <%= @room.topic %> <% end %>
""" end @impl Phoenix.LiveView def mount(_params, _session, socket) do rooms = Chat.list_rooms() {:ok, assign(socket, hide_topic?: false, rooms: rooms)} end @impl Phoenix.LiveView def handle_params(params, _session, socket) do room = case Map.fetch(params, "id") do {:ok, id} -> Chat.get_room!(id) :error -> Chat.get_first_room!() end {:noreply, assign(socket, hide_topic?: false, room: room)} end @impl Phoenix.LiveView def handle_event("toggle-topic", _params, socket) do {:noreply, update(socket, :hide_topic?, &(!&1))} end attr :active, :boolean, required: true attr :room, Room, required: true @spec room_link(Phoenix.LiveView.Socket.assigns()) :: Phoenix.LiveView.Rendered.t() defp room_link(assigns) do ~H""" <.link class={[ "flex items-center h-8 text-sm pl-8 pr-3", (@active && "bg-slate-300") || "hover:bg-slate-300" ]} patch={~p"/rooms/#{@room}"} > <.icon name="hero-hashtag" class="h-4 w-4" /> <%= @room.name %> """ end end