2022-02-13 21:28:20 -05:00
|
|
|
defmodule LokalWeb.Components.Topbar do
|
2022-01-22 13:01:36 -05:00
|
|
|
@moduledoc """
|
|
|
|
Phoenix.Component for rendering an interactive topbar
|
|
|
|
Assign
|
|
|
|
"""
|
|
|
|
|
|
|
|
use LokalWeb, :component
|
2022-01-22 20:44:38 -05:00
|
|
|
alias LokalWeb.PageLive
|
2021-03-11 21:12:55 -05:00
|
|
|
|
2022-01-22 13:01:36 -05:00
|
|
|
def topbar(assigns) do
|
|
|
|
assigns =
|
|
|
|
%{results: [], title_content: nil, current_user: nil, flash: nil}
|
|
|
|
|> Map.merge(assigns)
|
|
|
|
|
|
|
|
~H"""
|
2021-09-02 23:32:52 -04:00
|
|
|
<header class="mb-8 px-8 py-4 w-full bg-primary-400">
|
2021-03-11 21:12:55 -05:00
|
|
|
<nav role="navigation">
|
|
|
|
<div class="flex flex-row justify-between items-center space-x-4">
|
2021-09-02 23:32:52 -04:00
|
|
|
<div class="flex flex-row justify-start items-center space-x-2">
|
2022-01-22 13:01:36 -05:00
|
|
|
<%= link to: Routes.live_path(LokalWeb.Endpoint, PageLive) do %>
|
2022-01-22 15:00:30 -05:00
|
|
|
<h1 class="leading-5 text-xl text-white hover:underline">
|
|
|
|
Lokal
|
|
|
|
</h1>
|
2021-09-02 23:32:52 -04:00
|
|
|
<% end %>
|
|
|
|
<%= if @title_content do %>
|
|
|
|
<span>|</span>
|
2022-01-22 13:01:36 -05:00
|
|
|
<%= render_slot(@title_content) %>
|
2021-09-02 23:32:52 -04:00
|
|
|
<% end %>
|
|
|
|
</div>
|
2021-03-11 21:12:55 -05:00
|
|
|
<ul class="flex flex-row flex-wrap justify-center items-center
|
|
|
|
text-lg space-x-4 text-lg text-white">
|
|
|
|
<form phx-change="suggest" phx-submit="search">
|
2022-01-22 15:00:30 -05:00
|
|
|
<input
|
|
|
|
type="text"
|
|
|
|
name="q"
|
|
|
|
class="input input-primary"
|
|
|
|
placeholder="Search"
|
|
|
|
list="results"
|
|
|
|
autocomplete="off"
|
|
|
|
/>
|
2021-03-11 21:12:55 -05:00
|
|
|
<datalist id="results">
|
|
|
|
<%= for {app, _vsn} <- @results do %>
|
2022-01-22 15:00:30 -05:00
|
|
|
<option value={app}>
|
|
|
|
"> <%= app %>
|
|
|
|
</option>
|
2021-03-11 21:12:55 -05:00
|
|
|
<% end %>
|
|
|
|
</datalist>
|
|
|
|
</form>
|
2021-09-02 23:32:53 -04:00
|
|
|
<%= if @current_user do %>
|
2021-03-11 21:12:55 -05:00
|
|
|
<li>
|
2022-01-22 15:00:30 -05:00
|
|
|
<%= @current_user.email %>
|
2021-03-11 21:12:55 -05:00
|
|
|
</li>
|
|
|
|
<li>
|
2022-01-22 15:00:30 -05:00
|
|
|
<%= link("Settings",
|
|
|
|
class: "hover:underline",
|
|
|
|
to: Routes.user_settings_path(LokalWeb.Endpoint, :edit)
|
|
|
|
) %>
|
|
|
|
</li>
|
|
|
|
<li>
|
|
|
|
<%= link("Log out",
|
|
|
|
class: "hover:underline",
|
|
|
|
to: Routes.user_session_path(LokalWeb.Endpoint, :delete),
|
|
|
|
method: :delete
|
|
|
|
) %>
|
2021-03-11 21:12:55 -05:00
|
|
|
</li>
|
|
|
|
<%= if function_exported?(Routes, :live_dashboard_path, 2) do %>
|
|
|
|
<li>
|
2022-01-22 15:00:30 -05:00
|
|
|
<%= link("LiveDashboard",
|
|
|
|
class: "hover:underline",
|
|
|
|
to: Routes.live_dashboard_path(LokalWeb.Endpoint, :home)
|
|
|
|
) %>
|
2021-03-11 21:12:55 -05:00
|
|
|
</li>
|
|
|
|
<% end %>
|
|
|
|
<% else %>
|
|
|
|
<li>
|
2022-01-22 15:00:30 -05:00
|
|
|
<%= link("Register",
|
|
|
|
class: "hover:underline",
|
|
|
|
to: Routes.user_registration_path(LokalWeb.Endpoint, :new)
|
|
|
|
) %>
|
2021-03-11 21:12:55 -05:00
|
|
|
</li>
|
|
|
|
<li>
|
2022-01-22 15:00:30 -05:00
|
|
|
<%= link("Log in",
|
|
|
|
class: "hover:underline",
|
|
|
|
to: Routes.user_session_path(LokalWeb.Endpoint, :new)
|
|
|
|
) %>
|
2021-03-11 21:12:55 -05:00
|
|
|
</li>
|
|
|
|
<% end %>
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
</nav>
|
2022-01-22 13:01:36 -05:00
|
|
|
<%= if @flash && @flash |> Map.has_key?(:info) do %>
|
2022-01-22 15:00:30 -05:00
|
|
|
<p class="alert alert-info" role="alert" phx-click="lv:clear-flash" phx-value-key="info">
|
2021-03-11 21:12:55 -05:00
|
|
|
<%= live_flash(@flash, :info) %>
|
|
|
|
</p>
|
|
|
|
<% end %>
|
2022-01-22 13:01:36 -05:00
|
|
|
<%= if @flash && @flash |> Map.has_key?(:error) do %>
|
2022-01-22 15:00:30 -05:00
|
|
|
<p class="alert alert-danger" role="alert" phx-click="lv:clear-flash" phx-value-key="error">
|
2021-03-11 21:12:55 -05:00
|
|
|
<%= live_flash(@flash, :error) %>
|
|
|
|
</p>
|
|
|
|
<% end %>
|
|
|
|
</header>
|
|
|
|
"""
|
|
|
|
end
|
2022-01-22 13:01:36 -05:00
|
|
|
end
|