From 1445453a9b3fe9bd22f6180418e74057050dd940 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Przemek=20Wi=C4=99ch?= Date: Thu, 11 Jun 2026 15:24:21 +0200 Subject: [PATCH] Shift `standalone` to URL as source of truth --- docs/APP_REFACTORING_DESIGN.md | 2 +- src/app.tsx | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/APP_REFACTORING_DESIGN.md b/docs/APP_REFACTORING_DESIGN.md index c41db0d..34ff27e 100644 --- a/docs/APP_REFACTORING_DESIGN.md +++ b/docs/APP_REFACTORING_DESIGN.md @@ -92,7 +92,7 @@ To refactor `app.tsx` safely and maintain continuous code correctness, we will m #### Phase 3: Shifting to URL as Single Source of Truth We will gradually eliminate React state variables in `src/app.tsx` and derive them (including settings like `standalone`, `showWikiTreeMenus`, and `freezeAnimation`) directly from the `useLocation()` search query parameters on render: * [x] **Step 3.1a:** Shift `chartType` to URL as SSOT. Derive it using `useMemo` from search parameters, replace calls to `setChartType` with URL updates, and remove the React state variable and sync effect. -* [ ] **Step 3.1b:** Shift `standalone` to URL as SSOT. Derive it directly from search parameters on render and remove its React state variable. +* [x] **Step 3.1b:** Shift `standalone` to URL as SSOT. Derive it directly from search parameters on render and remove its React state variable. * [ ] **Step 3.1c:** Shift `showWikiTreeMenus` to URL as SSOT. Derive it directly from search parameters on render and remove its React state variable. * [ ] **Step 3.1d:** Shift `freezeAnimation` to URL as SSOT. Derive it directly from search parameters on render and remove its React state variable. * [ ] **Step 3.2:** Extract `selection` and `detailIndi` state. Parse them directly from URL params (`indi`, `gen`, and `detail`); update display selectors. Remove React states. Ensure that chart selection changes (`onSelection` callback) explicitly clear or update the `detail` query parameter to match the new selection to avoid getting stuck on the old details viewport. Also update the detail-only selection handler (`onDetailSelection`) to update the `detail` query parameter in the URL. diff --git a/src/app.tsx b/src/app.tsx index dc00f16..0abb1d0 100644 --- a/src/app.tsx +++ b/src/app.tsx @@ -91,8 +91,7 @@ export function App() { const [error, setError] = useState(); /** Whether the side panel is shown. */ const [showSidePanel, setShowSidePanel] = useState(false); - /** Whether the app is in standalone mode, i.e. showing 'open file' menus. */ - const [standalone, setStandalone] = useState(true); + /** * Whether the app should display WikiTree-specific menus when showing data * from WikiTree. @@ -124,6 +123,8 @@ export function App() { const args = useMemo(() => getArguments(location), [location]); /** Type of displayed chart. */ const chartType = args.chartType; + /** Whether the app is in standalone mode, i.e. showing 'open file' menus. */ + const standalone = args.standalone; /** Prevents the Google Drive "Open with" state from being processed more than once. */ const stateProcessed = useRef(false); @@ -354,7 +355,6 @@ export function App() { setSourceSpec(args.sourceSpec); setSelection(args.selection); setDetailIndi(args.selection?.id); - setStandalone(args.standalone); setShowWikiTreeMenus(args.showWikiTreeMenus); setFreezeAnimation(args.freezeAnimation); setConfig(args.config);