fix(views): keep the applied saved view (or filters) across a reload
loadAccountFilters preferred the starred default view's mirror over the stored filters, so a reload always snapped back to the default even after you'd picked another view. Now your last-applied filters (setFilters persists them on every change) win; the default view only seeds a fresh account that has never stored filters. Re-apply the default from the sidebar to return to it.
This commit is contained in:
parent
6c81419057
commit
25e04d3072
1 changed files with 14 additions and 2 deletions
|
|
@ -118,11 +118,23 @@ function loadInitialPage(): Page {
|
||||||
// the account isn't known yet (first load, before the tab is pinned), start from defaults; the
|
// the account isn't known yet (first load, before the tab is pinned), start from defaults; the
|
||||||
// post-login effect loads the real ones once the id arrives.
|
// post-login effect loads the real ones once the id arrives.
|
||||||
function loadAccountFilters(id: number | null): FeedFilters {
|
function loadAccountFilters(id: number | null): FeedFilters {
|
||||||
|
// Your last-applied filters win, so a reload keeps whatever view you're on (a saved view you
|
||||||
|
// picked, or manual tweaks) — setFilters persists them under LS.filters on every change. The
|
||||||
|
// starred default view only SEEDS a fresh account that has never stored filters: it drives the
|
||||||
|
// very first load, after which that state persists like any other. (Re-apply the default view
|
||||||
|
// from the sidebar to return to it.)
|
||||||
|
const fKey = accountKey(LS.filters, id);
|
||||||
|
let hasStored = false;
|
||||||
|
try {
|
||||||
|
hasStored = !!fKey && localStorage.getItem(fKey) != null;
|
||||||
|
} catch {
|
||||||
|
/* localStorage may be unavailable */
|
||||||
|
}
|
||||||
|
if (hasStored && fKey) return readMerged(fKey, DEFAULT_FILTERS);
|
||||||
const dvKey = accountKey(LS.defaultViewFilters, id);
|
const dvKey = accountKey(LS.defaultViewFilters, id);
|
||||||
const def = dvKey ? readJSON<FeedFilters | null>(dvKey, null) : null;
|
const def = dvKey ? readJSON<FeedFilters | null>(dvKey, null) : null;
|
||||||
if (def) return { ...DEFAULT_FILTERS, ...def };
|
if (def) return { ...DEFAULT_FILTERS, ...def };
|
||||||
const fKey = accountKey(LS.filters, id);
|
return { ...DEFAULT_FILTERS };
|
||||||
return fKey ? readMerged(fKey, DEFAULT_FILTERS) : { ...DEFAULT_FILTERS };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// URL wins over localStorage so a pasted link reproduces the exact view.
|
// URL wins over localStorage so a pasted link reproduces the exact view.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue