From 10285e7bd00f9455f7e69ad90dd872d8c701795e Mon Sep 17 00:00:00 2001 From: JasterV <49537445+JasterV@users.noreply.github.com> Date: Mon, 9 Feb 2026 16:33:21 +0100 Subject: [PATCH] feat: implement header tab-based navigation --- lib/spazio_solazzo_web/components/layouts.ex | 140 +++++++++++++++--- .../admin/booking_management_live.html.heex | 2 +- .../live/admin/dashboard_live.html.heex | 2 +- .../live/admin/walk_in_live.html.heex | 2 +- .../live/assign_path_hook.ex | 17 +++ .../live/landing/coworking_live.html.heex | 2 +- .../live/landing/meeting_live.html.heex | 2 +- .../live/landing/music_live.html.heex | 2 +- .../live/user/profile_live.html.heex | 2 +- lib/spazio_solazzo_web/router.ex | 12 +- 10 files changed, 151 insertions(+), 32 deletions(-) create mode 100644 lib/spazio_solazzo_web/live/assign_path_hook.ex diff --git a/lib/spazio_solazzo_web/components/layouts.ex b/lib/spazio_solazzo_web/components/layouts.ex index 5e6d076..885a298 100644 --- a/lib/spazio_solazzo_web/components/layouts.ex +++ b/lib/spazio_solazzo_web/components/layouts.ex @@ -35,6 +35,11 @@ defmodule SpazioSolazzoWeb.Layouts do default: nil, doc: "the current authenticated user" + attr :current_path, :string, + default: "", + required: false, + doc: "The path in the current URL" + slot :inner_block, required: true def app(assigns) do @@ -53,11 +58,53 @@ defmodule SpazioSolazzoWeb.Layouts do diff --git a/lib/spazio_solazzo_web/live/admin/booking_management_live.html.heex b/lib/spazio_solazzo_web/live/admin/booking_management_live.html.heex index c5ce7e3..0ae1905 100644 --- a/lib/spazio_solazzo_web/live/admin/booking_management_live.html.heex +++ b/lib/spazio_solazzo_web/live/admin/booking_management_live.html.heex @@ -1,4 +1,4 @@ - +
<.back_to_link diff --git a/lib/spazio_solazzo_web/live/admin/dashboard_live.html.heex b/lib/spazio_solazzo_web/live/admin/dashboard_live.html.heex index 67cbbd9..d181282 100644 --- a/lib/spazio_solazzo_web/live/admin/dashboard_live.html.heex +++ b/lib/spazio_solazzo_web/live/admin/dashboard_live.html.heex @@ -1,4 +1,4 @@ - +
diff --git a/lib/spazio_solazzo_web/live/admin/walk_in_live.html.heex b/lib/spazio_solazzo_web/live/admin/walk_in_live.html.heex index 6f9d9cc..7ca8c54 100644 --- a/lib/spazio_solazzo_web/live/admin/walk_in_live.html.heex +++ b/lib/spazio_solazzo_web/live/admin/walk_in_live.html.heex @@ -1,4 +1,4 @@ - +
<.back_to_link diff --git a/lib/spazio_solazzo_web/live/assign_path_hook.ex b/lib/spazio_solazzo_web/live/assign_path_hook.ex new file mode 100644 index 0000000..2a96549 --- /dev/null +++ b/lib/spazio_solazzo_web/live/assign_path_hook.ex @@ -0,0 +1,17 @@ +defmodule SpazioSolazzoWeb.AssignPathHook do + @moduledoc """ + Attach a `handle_params` hook on any live view that injects the current path from the URL into the socket assigns + """ + + import Phoenix.Component + import Phoenix.LiveView + + def on_mount(:default, _params, _session, socket) do + {:cont, attach_hook(socket, :set_current_path, :handle_params, &handle_path_update/3)} + end + + defp handle_path_update(_params, url, socket) do + %{path: path} = URI.parse(url) + {:cont, assign(socket, :current_path, path)} + end +end diff --git a/lib/spazio_solazzo_web/live/landing/coworking_live.html.heex b/lib/spazio_solazzo_web/live/landing/coworking_live.html.heex index de7e0bf..ef61825 100644 --- a/lib/spazio_solazzo_web/live/landing/coworking_live.html.heex +++ b/lib/spazio_solazzo_web/live/landing/coworking_live.html.heex @@ -1,4 +1,4 @@ - + <.page_header booking_path={~p"/book/space/#{@space.slug}"} booking_label="Request a desk" diff --git a/lib/spazio_solazzo_web/live/landing/meeting_live.html.heex b/lib/spazio_solazzo_web/live/landing/meeting_live.html.heex index 64a179b..ea5035c 100644 --- a/lib/spazio_solazzo_web/live/landing/meeting_live.html.heex +++ b/lib/spazio_solazzo_web/live/landing/meeting_live.html.heex @@ -1,4 +1,4 @@ - + <.page_header booking_path={~p"/book/space/#{@space.slug}"} booking_label="Booking request" diff --git a/lib/spazio_solazzo_web/live/landing/music_live.html.heex b/lib/spazio_solazzo_web/live/landing/music_live.html.heex index f4828a0..bc18e4b 100644 --- a/lib/spazio_solazzo_web/live/landing/music_live.html.heex +++ b/lib/spazio_solazzo_web/live/landing/music_live.html.heex @@ -1,4 +1,4 @@ - + <.page_header booking_path={~p"/book/space/#{@space.slug}"} booking_label="Booking request" diff --git a/lib/spazio_solazzo_web/live/user/profile_live.html.heex b/lib/spazio_solazzo_web/live/user/profile_live.html.heex index 7ec3312..7ed380b 100644 --- a/lib/spazio_solazzo_web/live/user/profile_live.html.heex +++ b/lib/spazio_solazzo_web/live/user/profile_live.html.heex @@ -1,4 +1,4 @@ - +
<.back_to_link navigate={~p"/"} diff --git a/lib/spazio_solazzo_web/router.ex b/lib/spazio_solazzo_web/router.ex index 8952eb7..a9fbff8 100644 --- a/lib/spazio_solazzo_web/router.ex +++ b/lib/spazio_solazzo_web/router.ex @@ -31,7 +31,8 @@ defmodule SpazioSolazzoWeb.Router do ash_authentication_live_session :unauthenticated_routes, on_mount: [ - {SpazioSolazzoWeb.LiveUserAuth, :live_user_optional} + {SpazioSolazzoWeb.LiveUserAuth, :live_user_optional}, + SpazioSolazzoWeb.AssignPathHook ] do live "/", PageLive live "/arcipelago", CoworkingLive @@ -41,7 +42,8 @@ defmodule SpazioSolazzoWeb.Router do ash_authentication_live_session :no_user_routes, on_mount: [ - {SpazioSolazzoWeb.LiveUserAuth, :live_no_user} + {SpazioSolazzoWeb.LiveUserAuth, :live_no_user}, + SpazioSolazzoWeb.AssignPathHook ] do live "/sign-in/callback", AuthCallbackLive live "/sign-in", SignInLive @@ -49,7 +51,8 @@ defmodule SpazioSolazzoWeb.Router do ash_authentication_live_session :authenticated_routes, on_mount: [ - {SpazioSolazzoWeb.LiveUserAuth, :live_user_required} + {SpazioSolazzoWeb.LiveUserAuth, :live_user_required}, + SpazioSolazzoWeb.AssignPathHook ] do live "/book/space/:space_slug", SpaceBookingLive live "/bookings/cancel", BookingCancellationLive @@ -58,7 +61,8 @@ defmodule SpazioSolazzoWeb.Router do ash_authentication_live_session :admin_routes, on_mount: [ - {SpazioSolazzoWeb.LiveUserAuth, :live_admin_required} + {SpazioSolazzoWeb.LiveUserAuth, :live_admin_required}, + SpazioSolazzoWeb.AssignPathHook ] do live "/admin/dashboard", Admin.DashboardLive live "/admin/bookings", Admin.BookingManagementLive