Deep-review round 1 of E22. - After a 429 the stream sent one POST per new event while a full batch waited; it now stays quiet for 15 s. Past the queue cap the oldest events go, as the comment always said, a refused batch included. - A batch refused after the level was lowered came back into the queue of a later consent in the same tab; each consent is its own session. - A `me` fetch that left before a level or preference change could put the old value back for up to a minute. `updateMeCache` writes the cache and cancels that fetch; usePref goes through it too. - The consent box's buttons and "revert now" took the focus with them to <body>; it returns to the level picker. Watched until the button is gone — in Chrome the saved level arrives in two renders, and a one-shot check spent itself on the first (jsdom never showed it). - The countdown line is no longer a live region re-read every minute. - "Saját napló" rows were keyed by index on a newest-first list, so every new event remounted every row and dropped the focus off a row button.
25 lines
1.5 KiB
TypeScript
25 lines
1.5 KiB
TypeScript
import { useQuery, type QueryClient } from "@tanstack/react-query";
|
|
import { qk } from "./queryKeys";
|
|
import { api, type Me } from "./api";
|
|
|
|
/** Write a change the SERVER already has (or is about to) into the `me` cache — and cancel a `me`
|
|
* fetch still in flight. That fetch may have left before the change was saved (BootGate's 60 s poll,
|
|
* a refetch on window focus); answering after the write, it would put the old value back and hold it
|
|
* until the next poll. Cancelling reverts the query to its latest state, which is this write:
|
|
* react-query takes a manual write as the state to revert to. */
|
|
export function updateMeCache(qc: QueryClient, update: (me: Me) => Me): void {
|
|
qc.setQueryData<Me | null>(qk.me(), (me) => (me ? update(me) : me));
|
|
void qc.cancelQueries({ queryKey: qk.me() });
|
|
}
|
|
|
|
// The signed-in account, read from the qk.me() query cache. BootGate owns the FETCHING query (gated on
|
|
// setup state) and App renders modules only once it has resolved to a real user — so anywhere inside the
|
|
// authenticated module tree the cache is always populated. `enabled:false` makes this a passive
|
|
// observer (no second fetch, which could 503 in setup mode) that still re-renders when the cache
|
|
// updates (login, the 60s refetch, a Google-link round-trip). Lets modules read `me` from a hook
|
|
// instead of having it prop-drilled through App.
|
|
export function useMe(): Me {
|
|
const { data } = useQuery({ queryKey: qk.me(), queryFn: api.me, enabled: false });
|
|
return data as Me;
|
|
}
|