slax/lib/slax_web/live/chat_room_live.ex

36 lines
1.0 KiB
Elixir
Raw Normal View History

2024-10-07 23:21:49 +00:00
defmodule SlaxWeb.ChatRoomLive do
@moduledoc false
use SlaxWeb, :live_view
2024-10-09 00:12:59 +00:00
alias Slax.Repo
alias Slax.Chat.Room
2024-10-07 23:21:49 +00:00
def render(assigns) do
~H"""
2024-10-09 00:12:59 +00:00
<div class="flex flex-col flex-grow shadow-lg">
<div class="flex justify-between items-center flex-shrink-0 h-16 bg-white border-b border-slate-300 px-4">
<div class="flex flex-col gap-1.5">
<h1 class="text-sm font-bold leading-none">#<%= @room.name %></h1>
<div class="text-xs leading-none h-3.5" phx-click="toggle-topic">
<%= if @hide_topic? do %>
<span class="text-slate-600">[Topic hidden]</span>
<% else %>
<%= @room.topic %>
<% end %>
</div>
2024-10-09 00:12:59 +00:00
</div>
</div>
</div>
2024-10-07 23:21:49 +00:00
"""
end
2024-10-09 00:12:59 +00:00
def mount(_params, _session, socket) do
room = Room |> Repo.all() |> List.first()
{:ok, assign(socket, hide_topic?: false, room: room)}
end
def handle_event("toggle-topic", _params, socket) do
{:noreply, update(socket, :hide_topic?, &(!&1))}
2024-10-09 00:12:59 +00:00
end
2024-10-07 23:21:49 +00:00
end