cannery/lib/cannery_web/components/topbar.ex

109 lines
3.9 KiB
Elixir
Raw Normal View History

2022-02-11 22:47:33 -05:00
defmodule CanneryWeb.Components.Topbar do
2022-01-22 21:40:29 -05:00
@moduledoc """
Component that renders a topbar with user functions/links
"""
use CanneryWeb, :component
2022-01-22 21:40:29 -05:00
alias Cannery.Accounts
alias CanneryWeb.HomeLive
def topbar(assigns) do
assigns =
%{results: [], title_content: nil, flash: nil, current_user: nil} |> Map.merge(assigns)
~H"""
2022-01-31 22:40:07 -05:00
<header class="mb-8 px-8 py-4 w-full bg-primary-400 overflow-x-hidden">
<nav role="navigation">
<div class="flex flex-row justify-between items-center space-x-4">
<div class="flex flex-row justify-start items-center space-x-2">
<%= link to: Routes.live_path(CanneryWeb.Endpoint, HomeLive) do %>
2022-01-22 17:21:10 -05:00
<h1 class="leading-5 text-xl text-white hover:underline">
Cannery
</h1>
<% end %>
<%= if @title_content do %>
<span>|</span>
<%= @title_content %>
<% end %>
</div>
2022-01-31 22:40:07 -05:00
<ul class="flex flex-col sm:flex-row flex-wrap justify-center items-center
space-x-4 text-lg text-white text-ellipsis">
<%= if @current_user do %>
<li>
2022-02-08 23:38:20 -05:00
<%= link(gettext("Tags"),
2022-01-22 17:21:10 -05:00
class: "hover:underline",
to: Routes.tag_index_path(CanneryWeb.Endpoint, :index)
) %>
</li>
<li>
2022-02-08 23:38:20 -05:00
<%= link(gettext("Containers"),
2022-01-22 17:21:10 -05:00
class: "hover:underline",
to: Routes.container_index_path(CanneryWeb.Endpoint, :index)
) %>
</li>
<li>
2022-02-08 23:38:20 -05:00
<%= link(gettext("Ammo"),
2022-01-22 17:21:10 -05:00
class: "hover:underline",
to: Routes.ammo_type_index_path(CanneryWeb.Endpoint, :index)
) %>
</li>
<li>
2022-02-08 23:38:20 -05:00
<%= link(gettext("Manage"),
2022-01-22 17:21:10 -05:00
class: "hover:underline",
to: Routes.ammo_group_index_path(CanneryWeb.Endpoint, :index)
) %>
</li>
<%= if @current_user.role == :admin do %>
<li>
2022-02-08 23:38:20 -05:00
<%= link(gettext("Invites"),
2022-01-22 17:21:10 -05:00
class: "hover:underline",
to: Routes.invite_index_path(CanneryWeb.Endpoint, :index)
) %>
</li>
<% end %>
<li>
2022-01-22 17:21:10 -05:00
<%= link(@current_user.email,
2022-01-31 22:40:07 -05:00
class: "hover:underline truncate",
2022-01-22 17:21:10 -05:00
to: Routes.user_settings_path(CanneryWeb.Endpoint, :edit)
) %>
</li>
<li>
2022-01-22 17:21:10 -05:00
<%= link to: Routes.user_session_path(CanneryWeb.Endpoint, :delete),
method: :delete,
2022-02-08 23:38:20 -05:00
data: [confirm: dgettext("prompts", "Are you sure you want to log out?")] do %>
2022-02-01 01:08:18 -05:00
<i class="fas fa-sign-out-alt"></i>
<% end %>
</li>
<%= if @current_user.role == :admin and function_exported?(Routes, :live_dashboard_path, 2) do %>
<li>
<%= link to: Routes.live_dashboard_path(CanneryWeb.Endpoint, :home) do %>
2022-02-01 01:08:18 -05:00
<i class="fas fa-tachometer-alt"></i>
<% end %>
</li>
<% end %>
<% else %>
<%= if Accounts.allow_registration?() do %>
<li>
2022-02-08 23:38:20 -05:00
<%= link(dgettext("actions", "Register"),
2022-01-22 17:21:10 -05:00
class: "hover:underline",
to: Routes.user_registration_path(CanneryWeb.Endpoint, :new)
) %>
</li>
<% end %>
<li>
2022-02-08 23:38:20 -05:00
<%= link(dgettext("actions", "Log in"),
2022-01-22 17:21:10 -05:00
class: "hover:underline",
to: Routes.user_session_path(CanneryWeb.Endpoint, :new)
) %>
</li>
<% end %>
</ul>
</div>
</nav>
</header>
"""
end
end