summaryrefslogtreecommitdiff
path: root/lib/lsg_web/components/component.ex
blob: 37d75e3b1587b557c952d596366141f0b0c13d3e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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