Skip to content

Commit 95aae2d

Browse files
committed
refactor: streamline message handling in chat and dashboard components
1 parent 8ce1b3d commit 95aae2d

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

lib/algora_web/components/layouts/user.html.heex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@
109109
<%= if assigns[:threads] && assigns[:threads] != [] do %>
110110
<.separator class="mx-auto my-4 w-2/3" />
111111
<ul role="list" class="space-y-1">
112-
<%= for %{thread: thread, contact: contact, path: path} <- @threads do %>
112+
<%= for %{contact: contact, path: path} <- @threads do %>
113113
<li>
114114
<.link
115115
class="flex justify-center p-2"

lib/algora_web/live/chat/thread_live.ex

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,18 @@ defmodule AlgoraWeb.Chat.ThreadLive do
3131
content
3232
)
3333

34-
{:noreply, push_event(socket, "clear-input", %{selector: "#message-input"})}
34+
{:noreply,
35+
socket
36+
|> Phoenix.Component.update(:messages, &(&1 ++ [message]))
37+
|> push_event("clear-input", %{selector: "#message-input"})}
3538
end
3639

3740
@impl true
3841
def handle_info(%Message{} = message, socket) do
3942
if message.id in Enum.map(socket.assigns.messages, & &1.id) do
4043
{:noreply, socket}
4144
else
42-
{:noreply, assign(socket, :messages, socket.assigns.messages ++ [message])}
45+
{:noreply, Phoenix.Component.update(socket, :messages, &(&1 ++ [message]))}
4346
end
4447
end
4548

lib/algora_web/live/org/dashboard_live.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ defmodule AlgoraWeb.Org.DashboardLive do
534534
if message.id in Enum.map(socket.assigns.messages, & &1.id) do
535535
{:noreply, socket}
536536
else
537-
{:noreply, assign(socket, :messages, socket.assigns.messages ++ [message])}
537+
{:noreply, Phoenix.Component.update(socket, :messages, &(&1 ++ [message]))}
538538
end
539539
end
540540

0 commit comments

Comments
 (0)