mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-17 23:52:24 +00:00
fix(url): write page state into the query string through one serialised helper
Next 16.4 adopts a native history write a render later. A second write inside that gap was undone when the router adopted the first, and a write computed from useSearchParams started from the URL before the last one. Clearing the vault's filters could therefore leave ?encounter= behind: the debounced search wrote the filters it had rendered back over the clear. @/lib/url-state is now the one way a page writes its own query: each write starts from the live address bar, at most one waits for the router at a time, and later updates queue on top of it and go together once the router has it (or after a short grace). useUrlSearch reads the same live value and reports each adoption. The filter hook (documents, measurements, mood), the open document, the day layer, the timeline's zoom and range, the medication tabs, the AI provider choice, the Coach's ?c= and the one-shot parameter strips all go through it; the filter changes merge into the live filters. A guard refuses raw history writes and router writes built from the rendered params outside the helper. The timeline spec now waits for the values menu to hand focus back before scrolling to the last row; it measured mid-animation and the focus return scrolled the page back.
This commit is contained in:
1 parent
333dfe8746
commit
d8e4cf6000
27 files changed
+846
-276
No files matched your search
@@ -19,7 +19,7 @@
|
||||
* thin and the person has not closed it; empty lanes are never drawn.
|
||||
*/
|
||||
import { useCallback, useMemo, useState } from "react";
|
||||
import { usePathname, useSearchParams } from "next/navigation";
|
||||
import { setAllParams, useUrlSearch, writeUrlState } from "@/lib/url-state";
|
||||
import { CalendarRange, Plus } from "lucide-react";
|
||||
|
||||
import { openDay as openDayLayer } from "@/components/day/day-layer-controller";
|
||||
@@ -151,8 +151,9 @@ export function TimelineView() {
|
||||
const { t } = useTranslations();
|
||||
const { user } = useAuth();
|
||||
const caps = useRecordCapabilities();
|
||||
const pathname = usePathname();
|
||||
const searchParams = useSearchParams();
|
||||
// Read live (`@/lib/url-state`): the router's copy trails a write by a
|
||||
// render, and the zoom, the range and `?day=` are all written here.
|
||||
const searchParams = useUrlSearch();
|
||||
const today = todayKeyIn(user?.timezone);
|
||||
const dayParam = parseDayParam(searchParams.get(DAY_QUERY_PARAM), today);
|
||||
// Life events are written in one's own record only (owner-only routes).
|
||||
@@ -285,14 +286,7 @@ export function TimelineView() {
|
||||
if (open) return;
|
||||
setEditing(null);
|
||||
if (searchParams.has("add")) {
|
||||
const next = new URLSearchParams(searchParams.toString());
|
||||
next.delete("add");
|
||||
const search = next.toString();
|
||||
window.history.replaceState(
|
||||
null,
|
||||
"",
|
||||
search ? `${pathname}?${search}` : pathname,
|
||||
);
|
||||
writeUrlState((params) => params.delete("add"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -312,8 +306,13 @@ export function TimelineView() {
|
||||
(range ? range.to : today);
|
||||
|
||||
function navigate(nextZoom: TimelineZoom, nextRange: TimelineRange | null) {
|
||||
const search = timelineSearch(window.location.search, nextZoom, nextRange);
|
||||
window.history.pushState(null, "", `${pathname}${search}`);
|
||||
writeUrlState(
|
||||
(params) => {
|
||||
const next = timelineSearch(`?${params}`, nextZoom, nextRange);
|
||||
setAllParams(next)(params);
|
||||
},
|
||||
{ mode: "push" },
|
||||
);
|
||||
}
|
||||
|
||||
function setZoom(next: Exclude<TimelineZoom, "range">) {
|
||||
|
||||
Reference in new issue
Block a user