feat(chat): add formatted timestamps with Timex

This commit is contained in:
2024-10-30 23:56:39 +00:00
parent 697ba23614
commit 367f306297
3 changed files with 10 additions and 1 deletions

View File

@@ -204,6 +204,7 @@ defmodule SlaxWeb.ChatRoomLive do
<.link class="text-sm font-semibold hover:underline">
<span><%= username(@message.user) %></span>
</.link>
<span class="ml-1 text-xs text-gray-500"><%= message_timestamp(@message) %></span>
<p class="text-sm"><%= @message.body %></p>
</div>
</div>
@@ -215,6 +216,10 @@ defmodule SlaxWeb.ChatRoomLive do
user.email |> String.split("@") |> List.first() |> String.capitalize()
end
defp message_timestamp(message) do
Timex.format!(message.inserted_at, "%-l:%M %p", :strftime)
end
defp assign_message_form(socket, changeset) do
assign(socket, :new_message_form, to_form(changeset))
end