Hello there! I have a simple div containing chat messages and It’s works correctly. New messages are displayed, old ones remain too.
<div id="chat-messages" phx-update="append">
<%= for message <- @messages do %>
<p id={message.uuid}><b style="color:red"></b><%= message.content %></p>
<% end %>
</div>
But as soon as I create a function to distinguish between system messages and user messages, when I try to send a new message, the old message is deleted, but the messages themselves are displayed correctly.
I suspect the problem may be that phx-update isn’t working properly. Why is this happening?
Code:
<div id="chat-messages" phx-update="append">
<%= for message <- @messages do %>
<%= display_message(message) %>
<% end %>
</div>
def display_message(%{type: :system, uuid: uuid, content: content}) do
~E"""
<p id={uuid}><b style="color:red"></b><%= content %></p>
"""
end
def display_message(%{uuid: uuid, content: content, username: username}) do
~E"""
<p id={uuid}><b style="color:red"><%= username %>: </b><%= content %></p>
"""
end
Thanks in advance!