sync editor state with URL for browser back support
Some checks failed
deploy / deploy (push) Has been cancelled
Some checks failed
deploy / deploy (push) Has been cancelled
- add ?edit=page/theme/settings param when opening editor or switching tabs - remove ?edit param when closing editor - restore .themed class on shop_root for editor panel background tokens - collapse editor when navigating back to URL without ?edit param Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
2c3c5050f4
commit
94c6137ab1
@ -80,8 +80,9 @@
|
||||
This shop works without JavaScript, but some features work better with it enabled.
|
||||
</div>
|
||||
</noscript>
|
||||
<%!-- Data attributes live on .shop-container inside LiveView for live updates --%>
|
||||
<div class="shop-root">
|
||||
<%!-- .themed here provides fallback theme tokens; .shop-container.themed inside
|
||||
LiveView has data attributes for live updates --%>
|
||||
<div class="shop-root themed">
|
||||
{@inner_content}
|
||||
</div>
|
||||
</body>
|
||||
|
||||
@ -18,7 +18,7 @@ defmodule BerrypodWeb.PageEditorHook do
|
||||
"""
|
||||
|
||||
import Phoenix.Component, only: [assign: 3]
|
||||
import Phoenix.LiveView, only: [attach_hook: 4, push_navigate: 2]
|
||||
import Phoenix.LiveView, only: [attach_hook: 4, push_navigate: 2, push_patch: 2]
|
||||
|
||||
alias Berrypod.{Media, Settings}
|
||||
alias Berrypod.Pages
|
||||
@ -119,7 +119,12 @@ defmodule BerrypodWeb.PageEditorHook do
|
||||
|> assign(:editor_active_tab, :settings)
|
||||
|> maybe_enter_theme_mode()
|
||||
|
||||
nil ->
|
||||
# No edit param - collapse the editor (supports browser back)
|
||||
assign(socket, :editor_sheet_state, :collapsed)
|
||||
|
||||
_ ->
|
||||
# Unknown edit value - ignore
|
||||
socket
|
||||
end
|
||||
end
|
||||
@ -175,12 +180,30 @@ defmodule BerrypodWeb.PageEditorHook do
|
||||
defp handle_editor_event("editor_set_sheet_state", %{"state" => state_str}, socket) do
|
||||
if socket.assigns.is_admin do
|
||||
state = if state_str == "open", do: :open, else: :collapsed
|
||||
{:halt, assign(socket, :editor_sheet_state, state)}
|
||||
|
||||
socket =
|
||||
socket
|
||||
|> assign(:editor_sheet_state, state)
|
||||
|> sync_edit_url_param(state)
|
||||
|
||||
{:halt, socket}
|
||||
else
|
||||
{:cont, socket}
|
||||
end
|
||||
end
|
||||
|
||||
# Sync URL ?edit param with editor state
|
||||
defp sync_edit_url_param(socket, :collapsed) do
|
||||
path = socket.assigns.editor_current_path || "/"
|
||||
push_patch(socket, to: path)
|
||||
end
|
||||
|
||||
defp sync_edit_url_param(socket, :open) do
|
||||
path = socket.assigns.editor_current_path || "/"
|
||||
tab = socket.assigns.editor_active_tab
|
||||
push_patch(socket, to: "#{path}?edit=#{tab}")
|
||||
end
|
||||
|
||||
# Tab switching for unified editor
|
||||
defp handle_editor_event("editor_set_tab", %{"tab" => tab_str}, socket) do
|
||||
if socket.assigns.is_admin do
|
||||
@ -228,6 +251,12 @@ defmodule BerrypodWeb.PageEditorHook do
|
||||
assign(socket, :editor_active_tab, :settings)
|
||||
end
|
||||
|
||||
# Open the sheet and sync URL with new tab
|
||||
socket =
|
||||
socket
|
||||
|> assign(:editor_sheet_state, :open)
|
||||
|> sync_edit_url_param(:open)
|
||||
|
||||
{:halt, socket}
|
||||
else
|
||||
{:cont, socket}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user