feat: handle event to toggle topic on click
This commit is contained in:
parent
54ce8b9b1b
commit
b05b844b6c
@ -11,7 +11,13 @@ defmodule SlaxWeb.ChatRoomLive do
|
||||
<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"><%= @room.topic %></div>
|
||||
<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>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@ -20,6 +26,10 @@ defmodule SlaxWeb.ChatRoomLive do
|
||||
|
||||
def mount(_params, _session, socket) do
|
||||
room = Room |> Repo.all() |> List.first()
|
||||
{:ok, assign(socket, :room, room)}
|
||||
{:ok, assign(socket, hide_topic?: false, room: room)}
|
||||
end
|
||||
|
||||
def handle_event("toggle-topic", _params, socket) do
|
||||
{:noreply, assign(socket, hide_topic?: !socket.assigns.hide_topic?)}
|
||||
end
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user