From dac182ff2ef4d32250049a2678eda1051c2aac0e Mon Sep 17 00:00:00 2001 From: celine Date: Thu, 9 Apr 2026 15:07:51 -0400 Subject: [PATCH] in the theme setter, moved the theme menu to the top of the page, added a back button that drops a warning if there are unsaved changes in the theme --- .../theme-settings/ThemeSettingsContent.tsx | 93 +++++++++++++++---- .../[publication]/theme-settings/page.tsx | 4 +- .../ThemeManager/PublicationThemeProvider.tsx | 2 +- 3 files changed, 79 insertions(+), 20 deletions(-) diff --git a/app/lish/[did]/[publication]/theme-settings/ThemeSettingsContent.tsx b/app/lish/[did]/[publication]/theme-settings/ThemeSettingsContent.tsx index 409682ed..fe4e4581 100644 --- a/app/lish/[did]/[publication]/theme-settings/ThemeSettingsContent.tsx +++ b/app/lish/[did]/[publication]/theme-settings/ThemeSettingsContent.tsx @@ -1,11 +1,12 @@ "use client"; import { useRef, useState } from "react"; +import { useParams, useRouter } from "next/navigation"; import { BaseThemeProvider, CardBorderHiddenContext, } from "components/ThemeManager/ThemeProvider"; -import { ButtonPrimary } from "components/Buttons"; +import { ButtonPrimary, ButtonSecondary } from "components/Buttons"; import { DotLoader } from "components/utils/DotLoader"; import { ToggleGroup } from "components/ToggleGroup"; import { PaintSmall } from "components/Icons/PaintSmall"; @@ -22,10 +23,12 @@ import { useNormalizedPublicationRecord, } from "../dashboard/PublicationSWRProvider"; import { Separator } from "components/Layout"; +import { GoToArrow } from "components/Icons/GoToArrow"; export function ThemeSettingsContent() { let toolbarRef = useRef(null); let [previewMode, setPreviewMode] = useState<"post" | "pub">("post"); + let params = useParams<{ did: string; publication: string }>(); let { data } = usePublicationData(); let { publication } = data || {}; let record = useNormalizedPublicationRecord(); @@ -39,7 +42,18 @@ export function ThemeSettingsContent() { pubBGImage, leafletBGRepeat, showPageBackground, + changes, } = state; + let router = useRouter(); + let [showLeaveWarning, setShowLeaveWarning] = useState(false); + let settingsHref = `/lish/${params.did}/${params.publication}/dashboard?tab=Settings`; + + let hasUnsavedChanges = + changes || + headingFont !== record?.theme?.headingFont || + bodyFont !== record?.theme?.bodyFont || + pageWidth !== (record?.theme?.pageWidth || 624) || + showPageBackground !== !!record?.theme?.showPageBackground; return ( @@ -51,27 +65,74 @@ export function ThemeSettingsContent() { hasBackgroundImage={!!image} pageWidth={pageWidth} > -
+
{/* Theme Setter Panel */}
- - - +
+ { + if (hasUnsavedChanges) { + setShowLeaveWarning(true); + } else { + router.push(settingsHref); + } + }} + > + + + } + > +

Discard unsaved changes?

+

+ You have unsaved changes to your theme. Leaving the page will + lose your edits! +

+
+ router.push(settingsHref)} + > + Discard and Leave + + +
+
+
+ + + +
+
{/* Full-page Preview */} - {loading ? : "Update"} + {loading ? : "Save Changes"}
diff --git a/app/lish/[did]/[publication]/theme-settings/page.tsx b/app/lish/[did]/[publication]/theme-settings/page.tsx index f668745c..3aa3b7e2 100644 --- a/app/lish/[did]/[publication]/theme-settings/page.tsx +++ b/app/lish/[did]/[publication]/theme-settings/page.tsx @@ -46,9 +46,7 @@ export default async function ThemeSettingsPage(props: { publication_rkey={uri.rkey} publication_data={publication_data} > - - - + ); } catch (e) { diff --git a/components/ThemeManager/PublicationThemeProvider.tsx b/components/ThemeManager/PublicationThemeProvider.tsx index 631103ba..55c7f78c 100644 --- a/components/ThemeManager/PublicationThemeProvider.tsx +++ b/components/ThemeManager/PublicationThemeProvider.tsx @@ -93,7 +93,7 @@ export function PublicationBackgroundProvider(props: { return (