mirror of
https://github.com/PeWu/topola-viewer.git
synced 2026-07-17 17:21:48 +00:00
Shift chartType to URL as source of truth
This commit is contained in:
@@ -91,7 +91,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:
|
||||
* [ ] **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.
|
||||
* [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.
|
||||
* [ ] **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.
|
||||
|
||||
@@ -98,8 +98,7 @@ export function App() {
|
||||
* from WikiTree.
|
||||
*/
|
||||
const [showWikiTreeMenus, setShowWikiTreeMenus] = useState(true);
|
||||
/** Type of displayed chart. */
|
||||
const [chartType, setChartType] = useState<ChartType>(ChartType.Hourglass);
|
||||
|
||||
/** Whether to show the error popup. */
|
||||
const [showErrorPopup, setShowErrorPopup] = useState(false);
|
||||
/** Specification of the source of the data. */
|
||||
@@ -122,6 +121,10 @@ export function App() {
|
||||
const navigate = useNavigate();
|
||||
const location = useLocation();
|
||||
|
||||
const args = useMemo(() => getArguments(location), [location]);
|
||||
/** Type of displayed chart. */
|
||||
const chartType = args.chartType;
|
||||
|
||||
/** Prevents the Google Drive "Open with" state from being processed more than once. */
|
||||
const stateProcessed = useRef(false);
|
||||
/** Tracks whether the component is currently mounted to prevent state updates after unmount. */
|
||||
@@ -353,7 +356,6 @@ export function App() {
|
||||
setDetailIndi(args.selection?.id);
|
||||
setStandalone(args.standalone);
|
||||
setShowWikiTreeMenus(args.showWikiTreeMenus);
|
||||
setChartType(args.chartType);
|
||||
setFreezeAnimation(args.freezeAnimation);
|
||||
setConfig(args.config);
|
||||
const currentFetchId = ++fetchIdRef.current;
|
||||
@@ -399,7 +401,6 @@ export function App() {
|
||||
const loadMoreFromWikitree =
|
||||
args.sourceSpec.source === DataSourceEnum.WIKITREE &&
|
||||
(!selection || selection.id !== args.selection?.id);
|
||||
setChartType(args.chartType);
|
||||
setState(
|
||||
loadMoreFromWikitree ? AppState.LOADING_MORE : AppState.SHOWING_CHART,
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user