summaryrefslogtreecommitdiff
path: root/lib/nola_web/components
diff options
context:
space:
mode:
authorJordan Bracco <href@random.sh>2022-12-20 00:21:54 +0000
committerJordan Bracco <href@random.sh>2022-12-20 19:29:41 +0100
commit2d83df8b32bff7f0028923bb5b64dc0b55f20d03 (patch)
tree1207e67b5b15f540963db05e7be89f3ca950e724 /lib/nola_web/components
parentNola rename, the end. pt 6. Refs T77. (diff)
Nola rename: The Big Move, Refs T77
Diffstat (limited to 'lib/nola_web/components')
-rw-r--r--lib/nola_web/components/component.ex44
-rw-r--r--lib/nola_web/components/event_component.ex43
-rw-r--r--lib/nola_web/components/message_component.ex12
3 files changed, 99 insertions, 0 deletions
diff --git a/lib/nola_web/components/component.ex b/lib/nola_web/components/component.ex
new file mode 100644
index 0000000..fff8263
--- /dev/null
+++ b/lib/nola_web/components/component.ex
@@ -0,0 +1,44 @@
+defmodule NolaWeb.Component do
+ use Phoenix.Component
+
+ @date_time_default_format "%F %H:%M"
+ @date_time_formats %{"time-24-with-seconds" => "%H:%M:%S"}
+ def naive_date_time_utc(assigns = %{at: nil}) do
+ ""
+ end
+
+ def naive_date_time_utc(assigns = %{format: format}) do
+ assigns = assign(assigns, :format, Map.get(@date_time_formats, format, format))
+ ~H"""
+ <time class="component"
+ id={"time-#{:erlang.phash2(@datetime)}"}
+ phx-hook="NaiveDateTimeUTC"
+ data-time-format={get_luxon_format(@format)}
+ datetime={NaiveDateTime.to_iso8601(@datetime)}>
+ <%= Timex.format!(@datetime, @format, :strftime) %>
+ </time>
+ """
+ end
+ def naive_date_time_utc(assigns) do
+ naive_date_time_utc(assign(assigns, :format, "%F %H:%M"))
+ end
+ def get_luxon_format("%H:%M:%S"), do: "TIME_24_WITH_SECONDS"
+
+ def nick(assigns = %{self: false}) do
+ ~H"""
+ <span class="nickname" data-account-id={@account_id} data-user-id={@user_id}>
+ <%= @nick %>
+ </span>
+ """
+ end
+
+ def nick(assigns = %{self: true}) do
+ ~H"""
+ <span class="nickname self" data-account-id={@account_id} data-user-id={@user_id}>
+ You
+ </span>
+ """
+ end
+
+
+end
diff --git a/lib/nola_web/components/event_component.ex b/lib/nola_web/components/event_component.ex
new file mode 100644
index 0000000..8af3c67
--- /dev/null
+++ b/lib/nola_web/components/event_component.ex
@@ -0,0 +1,43 @@
+defmodule NolaWeb.EventComponent do
+ use Phoenix.Component
+
+ def content(assigns = %{event: %{type: :day_changed}}) do
+ ~H"""
+ Day changed:
+ <span class="reason"><%= Date.to_string(@date) %></span>
+ """
+ end
+
+ def content(assigns = %{event: %{type: :quit}}) do
+ ~H"""
+ <NolaWeb.Component.nick self={@self} nick={@user.nick} user_id={@user.id} account_id={@user.account} />
+ has quit:
+ <span class="reason"><%= @reason %></span>
+ """
+ end
+
+ def content(assigns = %{event: %{type: :part}}) do
+ ~H"""
+ <NolaWeb.Component.nick self={@self} nick={@user.nick} user_id={@user.id} account_id={@user.account} />
+ has left:
+ <span class="reason"><%= @reason %></span>
+ """
+ end
+
+ def content(assigns = %{event: %{type: :nick}}) do
+ ~H"""
+ <span class="old-nick"><%= @old_nick %></span>
+ is now known as
+ <NolaWeb.Component.nick self={@self} nick={@user.nick} user_id={@user.id} account_id={@user.account} />
+ """
+ end
+
+ def content(assigns = %{event: %{type: :join}}) do
+ ~H"""
+ <NolaWeb.Component.nick self={@self} nick={@user.nick} user_id={@user.id} account_id={@user.account} />
+ joined
+ """
+ end
+
+
+end
diff --git a/lib/nola_web/components/message_component.ex b/lib/nola_web/components/message_component.ex
new file mode 100644
index 0000000..5d0386b
--- /dev/null
+++ b/lib/nola_web/components/message_component.ex
@@ -0,0 +1,12 @@
+defmodule NolaWeb.MessageComponent do
+ use Phoenix.Component
+
+ def content(assigns) do
+ ~H"""
+ <NolaWeb.Component.naive_date_time_utc datetime={@message.at} format="time-24-with-seconds" />
+ <div class="inline-block font-bold flex-none cursor-default"><%= @message.sender.nick %></div>
+ <div class="inline-block flex-grow cursor-default"><%= @text %></div>
+ """
+ end
+
+end