summaryrefslogtreecommitdiff
path: root/lib/lsg_web/components/component.ex
diff options
context:
space:
mode:
authorhref <href@random.sh>2021-09-03 04:04:21 +0200
committerhref <href@random.sh>2021-09-03 04:04:21 +0200
commit5399fc818cf821c75f9f19fd00bf7905ba7fe7e3 (patch)
tree00408724f9778cc7323b1459782a762626d39b6a /lib/lsg_web/components/component.ex
parentassets.. (diff)
various fixes, web client wip, pubsub events
Diffstat (limited to '')
-rw-r--r--lib/lsg_web/components/component.ex40
1 files changed, 40 insertions, 0 deletions
diff --git a/lib/lsg_web/components/component.ex b/lib/lsg_web/components/component.ex
new file mode 100644
index 0000000..37d75e3
--- /dev/null
+++ b/lib/lsg_web/components/component.ex
@@ -0,0 +1,40 @@
+defmodule LSGWeb.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 = %{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