From ccd3dbfa747855a363d4c70f2594ad22dbec65d0 Mon Sep 17 00:00:00 2001 From: Claudio Ortolina Date: Sun, 29 Sep 2024 22:54:57 +0100 Subject: [PATCH] Add top navigation --- lib/music_library_web/components/layouts.ex | 9 +++++++++ .../components/layouts/app.html.heex | 17 +++++++++++++++++ .../controllers/stats_controller.ex | 2 +- .../controllers/stats_html/index.html.heex | 2 -- lib/music_library_web/live/record_live/index.ex | 1 + lib/music_library_web/live/record_live/show.ex | 1 + 6 files changed, 29 insertions(+), 3 deletions(-) diff --git a/lib/music_library_web/components/layouts.ex b/lib/music_library_web/components/layouts.ex index 9388edff..18fe1e2f 100644 --- a/lib/music_library_web/components/layouts.ex +++ b/lib/music_library_web/components/layouts.ex @@ -11,4 +11,13 @@ defmodule MusicLibraryWeb.Layouts do use MusicLibraryWeb, :html embed_templates "layouts/*" + + @base_classes "inline-flex items-center border-b-2 px-1 pt-1 text-sm font-medium" + def nav_link_class(current_section, section) when current_section == section do + [@base_classes, "border-zinc-500 text-gray-900"] + end + + def nav_link_class(_current_section, _section) do + [@base_classes, "border-transparent text-gray-500 hover:border-gray-300 hover:text-gray-700"] + end end diff --git a/lib/music_library_web/components/layouts/app.html.heex b/lib/music_library_web/components/layouts/app.html.heex index 2adb8e14..9093ca6e 100644 --- a/lib/music_library_web/components/layouts/app.html.heex +++ b/lib/music_library_web/components/layouts/app.html.heex @@ -1,3 +1,20 @@ +
<.flash_group flash={@flash} /> diff --git a/lib/music_library_web/controllers/stats_controller.ex b/lib/music_library_web/controllers/stats_controller.ex index d2cdd4f5..7aacb5c5 100644 --- a/lib/music_library_web/controllers/stats_controller.ex +++ b/lib/music_library_web/controllers/stats_controller.ex @@ -6,6 +6,6 @@ defmodule MusicLibraryWeb.StatsController do def index(conn, _params) do records_count = Records.count_records() record = Records.get_latest_record!() - render(conn, :index, records_count: records_count, record: record) + render(conn, :index, records_count: records_count, record: record, nav_section: :dashboard) end end diff --git a/lib/music_library_web/controllers/stats_html/index.html.heex b/lib/music_library_web/controllers/stats_html/index.html.heex index 732c87e3..ed097715 100644 --- a/lib/music_library_web/controllers/stats_html/index.html.heex +++ b/lib/music_library_web/controllers/stats_html/index.html.heex @@ -1,6 +1,4 @@
-

Music Library

-
diff --git a/lib/music_library_web/live/record_live/index.ex b/lib/music_library_web/live/record_live/index.ex index bca77147..41e89c60 100644 --- a/lib/music_library_web/live/record_live/index.ex +++ b/lib/music_library_web/live/record_live/index.ex @@ -25,6 +25,7 @@ defmodule MusicLibraryWeb.RecordLive.Index do {:ok, socket + |> assign(:nav_section, :records) |> assign(:record_list_params, record_list_params) |> stream(:records, records)} end diff --git a/lib/music_library_web/live/record_live/show.ex b/lib/music_library_web/live/record_live/show.ex index 414e5918..789585bb 100644 --- a/lib/music_library_web/live/record_live/show.ex +++ b/lib/music_library_web/live/record_live/show.ex @@ -12,6 +12,7 @@ defmodule MusicLibraryWeb.RecordLive.Show do def handle_params(%{"id" => id}, _, socket) do {:noreply, socket + |> assign(:nav_section, :records) |> assign(:page_title, page_title(socket.assigns.live_action)) |> assign(:record, Records.get_record!(id))} end