feat(analytics): persist selected time range in localStorage - #462
Closed
jasnoorgill wants to merge 1 commit into
Closed
feat(analytics): persist selected time range in localStorage#462jasnoorgill wants to merge 1 commit into
jasnoorgill wants to merge 1 commit into
Conversation
Remembers the last-selected 24h/7d/30d range across reloads and new sessions so the user lands back on the window they were inspecting. Same localStorage shape as the theme toggle (key: 'theme') and the locale picker (key: 'freellmapi.locale'). Storage key: 'freellmapi.analytics.range'. Invalid or missing values fall back to the 7d default; storage errors (quota, private mode) are swallowed so the page keeps working.
Contributor
Author
|
Closed in favor of #463 which combines this with the sortable-columns work to avoid rebase churn on the same file. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Persists the selected analytics time range (24h / 7d / 30d) in
localStorageso the user lands back on the window they were inspecting after a reload or
new session. Same persistence pattern as the existing
themetoggle(
client/index.html) and thefreellmapi.localepreference(
client/src/i18n/I18nProvider.tsx).Storage key:
freellmapi.analytics.range. Values are validated against['24h', '7d', '30d']; invalid or missing entries fall back to the existing7d default so a corrupted entry never bricks the page.
localStorageaccess is wrapped in
try/catchfor SSR / private-mode safety (samepattern as
client/src/lib/api.ts:18-26).Motivation
The analytics page is a frequent revisit — most operators land on 7d or 30d,
not the default, and a hard reload (or new browser session) always snapped
them back to 7d. Small but persistent annoyance; the existing
themeandfreellmapi.localepatterns show the project already considersclient-level preferences worth persisting, so this is consistent with the
project's UX conventions.
Changes
client/src/pages/AnalyticsPage.tsxuseEffectimport;useState<TimeRange>('7d')→useState<TimeRange>(loadStoredRange); newuseEffectto persistrangeon change; addedSTORAGE_KEY,TIME_RANGES,DEFAULT_RANGEconstants andloadStoredRange()helper.1 file, +34 / -2. No new dependencies. No server changes. No new
migrations. No i18n changes (the tab labels use existing
analytics.range24h/range7d/range30dkeys).Test plan
npx tsc -binclient/— clean, 0 errors.npx tsc -binserver/— 9 errors inserver/src/routes/keys.tsfromupstream's
multertyping bug (PR I added Agnes AI, but it doesn’t appear in the model list. #438, pre-existing onorigin/mainat
340f414). Not introduced by this PR — same errors reproduce ona clean
git checkout origin/main.npx vitest runinserver/— 524/524 passing, 0 failures, 0 regressions.integration/all-my-prs @ f81f781; therebuilt client bundle (
dist/assets/index-DJVe5VdN.js) contains the newstorage key string and the read+set localStorage calls. Restarted
service,
MainPID=860700running.Manual smoke:
/analytics, click 30d.freellmapi.analytics.rangeis30d.24h.Compatibility
No breaking changes. The default is unchanged (7d). The persistence is
additive — users who never visit the page see no different behaviour. The
localStoragekey is namespaced (freellmapi.*) per the existingconvention.
References operator session 2026-07-04. No upstream issue number yet —
happy to file one if requested.