From b05b844b6c0787cfa9e3204f66afd0cfa2137a11 Mon Sep 17 00:00:00 2001 From: Joao P Dubas Date: Wed, 9 Oct 2024 23:50:50 +0000 Subject: [PATCH] feat: handle event to toggle topic on click --- lib/slax_web/live/chat_room_live.ex | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/slax_web/live/chat_room_live.ex b/lib/slax_web/live/chat_room_live.ex index 94a8d67..85e4108 100644 --- a/lib/slax_web/live/chat_room_live.ex +++ b/lib/slax_web/live/chat_room_live.ex @@ -11,7 +11,13 @@ defmodule SlaxWeb.ChatRoomLive do

#<%= @room.name %>

-
<%= @room.topic %>
+
+ <%= if @hide_topic? do %> + [Topic hidden] + <% else %> + <%= @room.topic %> + <% end %> +
@@ -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