Skip to content

Commit 439b6b2

Browse files
authored
Navbar is not a LiveComponent anymore (#52)
The navbar does not have any independent status so it doesn't need to be a LiveComponent. Being a LiveComponent was actually problematic as it was not able to generate the proper dashboard path for linking.
1 parent 8f72ef4 commit 439b6b2

File tree

3 files changed

+80
-86
lines changed

3 files changed

+80
-86
lines changed

lib/error_tracker/web/components/layouts.ex

Lines changed: 79 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ defmodule ErrorTracker.Web.Layouts do
22
@moduledoc false
33
use ErrorTracker.Web, :html
44

5-
alias ErrorTracker.Web.Layouts.Navbar
6-
75
@default_socket_config %{path: "/live", transport: :websocket}
86

97
@css :code.priv_dir(:error_tracker) |> Path.join("static/app.css") |> File.read!()
@@ -19,4 +17,83 @@ defmodule ErrorTracker.Web.Layouts do
1917
config = Application.get_env(:error_tracker, :live_view_socket, [])
2018
Keyword.get(config, key, default)
2119
end
20+
21+
def navbar(assigns) do
22+
~H"""
23+
<nav class="border-gray-400 bg-gray-900">
24+
<div class="container flex flex-wrap items-center justify-between mx-auto p-4">
25+
<.link
26+
href={dashboard_path(@socket)}
27+
class="self-center text-2xl font-semibold whitespace-nowrap text-white"
28+
>
29+
<span class="mr-2">🐛</span>ErrorTracker
30+
</.link>
31+
<button
32+
type="button"
33+
class="inline-flex items-center p-2 w-10 h-10 justify-center text-sm rounded -lg md:hidden focus:outline-none focus:ring-2 text-gray-400 hover:bg-gray-700 focus:ring-gray-500"
34+
aria-controls="navbar-main"
35+
aria-expanded="false"
36+
phx-click={JS.toggle(to: "#navbar-main")}
37+
>
38+
<span class="sr-only">Open main menu</span>
39+
<svg
40+
class="w-5 h-5"
41+
aria-hidden="true"
42+
xmlns="http://www.w3.org/2000/svg"
43+
fill="none"
44+
viewBox="0 0 17 14"
45+
>
46+
<path
47+
stroke="currentColor"
48+
stroke-linecap="round"
49+
stroke-linejoin="round"
50+
stroke-width="2"
51+
d="M1 1h15M1 7h15M1 13h15"
52+
/>
53+
</svg>
54+
</button>
55+
<div class="hidden w-full md:block md:w-auto" id="navbar-main">
56+
<ul class="font-medium flex flex-col p-4 md:p-0 mt-4 border border-gray-400 bg-gray-900 rounded-lg md:flex-row md:space-x-8 rtl:space-x-reverse md:mt-0 md:border-0 md:bg-gray-800">
57+
<.navbar_item to="https://github.com/elixir-error-tracker/error-tracker" target="_blank">
58+
<svg
59+
width="18"
60+
height="18"
61+
aria-hidden="true"
62+
viewBox="0 0 24 24"
63+
version="1.1"
64+
class="inline-block mr-1 align-text-top"
65+
>
66+
<path
67+
fill="currentColor"
68+
d="M12.5.75C6.146.75 1 5.896 1 12.25c0 5.089 3.292 9.387 7.863 10.91.575.101.79-.244.79-.546 0-.273-.014-1.178-.014-2.142-2.889.532-3.636-.704-3.866-1.35-.13-.331-.69-1.352-1.18-1.625-.402-.216-.977-.748-.014-.762.906-.014 1.553.834 1.769 1.179 1.035 1.74 2.688 1.25 3.349.948.1-.747.402-1.25.733-1.538-2.559-.287-5.232-1.279-5.232-5.678 0-1.25.445-2.285 1.178-3.09-.115-.288-.517-1.467.115-3.048 0 0 .963-.302 3.163 1.179.92-.259 1.897-.388 2.875-.388.977 0 1.955.13 2.875.388 2.2-1.495 3.162-1.179 3.162-1.179.633 1.581.23 2.76.115 3.048.733.805 1.179 1.825 1.179 3.09 0 4.413-2.688 5.39-5.247 5.678.417.36.776 1.05.776 2.128 0 1.538-.014 2.774-.014 3.162 0 .302.216.662.79.547C20.709 21.637 24 17.324 24 12.25 24 5.896 18.854.75 12.5.75Z"
69+
>
70+
</path>
71+
</svg>
72+
GitHub
73+
</.navbar_item>
74+
</ul>
75+
</div>
76+
</div>
77+
</nav>
78+
"""
79+
end
80+
81+
attr :to, :string, required: true
82+
attr :rest, :global
83+
84+
slot :inner_block, required: true
85+
86+
def navbar_item(assigns) do
87+
~H"""
88+
<li>
89+
<a
90+
href={@to}
91+
class="whitespace-nowrap flex-0 block py-2 px-3 rounded-lg text-white hover:text-white hover:bg-gray-700 md:hover:bg-transparent md:border-0 md:hover:text-sky-500"
92+
{@rest}
93+
>
94+
<%= render_slot(@inner_block) %>
95+
</a>
96+
</li>
97+
"""
98+
end
2299
end
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<.live_component module={Navbar} id="navbar" {assigns} />
1+
<.navbar id="navbar" {assigns} />
22
<main class="container px-4 mx-auto mt-4 mb-4">
33
<%= @inner_content %>
44
</main>

lib/error_tracker/web/components/layouts/navbar.ex

Lines changed: 0 additions & 83 deletions
This file was deleted.

0 commit comments

Comments
 (0)