feat(analytics): make period selector functional with api-level filtering - #105
Merged
MistryVishwa merged 1 commit intoJul 18, 2026
Conversation
…ring Pass the selected period (week/month/all) to /api/user/stats as a ?period= query param. The API now filters usage logs, sessions, notes, and quiz attempts to the selected window and returns period-scoped values for learningHours, quizzesTaken, aiChats, flashcardSessions, and the activity chart. The page refetches and shows skeletons on every period change. Also fixes a pre-existing dataKey mismatch on the Weekly Activity chart XAxis (day -> label). Closes MistryVishwa#91
|
@Mohammad-Hassan027 is attempting to deploy a commit to the vishwamistrylearning-1037's projects Team on Vercel. A member of the Team first needs to authorize it. |
MistryVishwa
approved these changes
Jul 18, 2026
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.
Description
The Analytics page had a period selector (This Week / This Month / All Time)
that was purely decorative — the fetch always called
/api/user/statswith no query parameter, so the stats cards and activity chart never
changed regardless of selection.
This PR wires up the selector end-to-end:
API changes (
app/api/user/stats/route.ts):parsePeriod()helper that validates the?period=queryparam (
week|month|all, defaults toweek).GET()now acceptsNextRequestand reads the period from the URL.periodStartcutoff date and filters all data intoperiod-scoped subsets.
learningHours,quizzesTaken,aiChats,flashcardSessions, andweeklyActivity.and filtering it by period would produce misleading results.
Page changes (
app/(dashboard)/analytics/page.tsx):useEffectnow depends on[period]and fetches/api/user/stats?period=${period}.setIsLoading(true)is called before each refetch so skeletonsappear while new data loads.
dataKey="day"→dataKey="label"bug on theWeekly Activity chart XAxis (the API always returned
label).Related Issue: Closes #91
Type of Change
How Has This Been Tested?
cards and activity chart reflect the last 7 days of data only.
stats reflect current calendar month and the chart switches to a
monthly bar view.
returned and the monthly chart is shown.
period switches before data resolves.
npx tsc --noEmit— no new errors introducedin
analytics/page.tsxorapi/user/stats/route.ts.Visual Proof (Screenshots/GIFs/Videos):
N/A — UI layout is unchanged; only the data displayed updates on
period selection. Manual verification against a seeded account
is recommended.
Checklist:
main