Skip to content

feat(analytics): make period selector functional with api-level filtering - #105

Merged
MistryVishwa merged 1 commit into
MistryVishwa:mainfrom
Mohammad-Hassan027:feat/91-analytics-period-selector
Jul 18, 2026
Merged

feat(analytics): make period selector functional with api-level filtering#105
MistryVishwa merged 1 commit into
MistryVishwa:mainfrom
Mohammad-Hassan027:feat/91-analytics-period-selector

Conversation

@Mohammad-Hassan027

Copy link
Copy Markdown
Contributor

Description

The Analytics page had a period selector (This Week / This Month / All Time)
that was purely decorative — the fetch always called /api/user/stats
with 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):

  • Added a parsePeriod() helper that validates the ?period= query
    param (week | month | all, defaults to week).
  • GET() now accepts NextRequest and reads the period from the URL.
  • Computes a periodStart cutoff date and filters all data into
    period-scoped subsets.
  • Returns period-scoped values for learningHours, quizzesTaken,
    aiChats, flashcardSessions, and weeklyActivity.
  • Study streak intentionally stays all-time — it is a cumulative metric
    and filtering it by period would produce misleading results.

Page changes (app/(dashboard)/analytics/page.tsx):

  • Stats useEffect now depends on [period] and fetches
    /api/user/stats?period=${period}.
  • setIsLoading(true) is called before each refetch so skeletons
    appear while new data loads.
  • Fixed a pre-existing dataKey="day"dataKey="label" bug on the
    Weekly Activity chart XAxis (the API always returned label).

Related Issue: Closes #91

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update (non-breaking change to add/edit documentation)

How Has This Been Tested?

  • Period selector — Week: Selected "This Week", confirmed stats
    cards and activity chart reflect the last 7 days of data only.
  • Period selector — Month: Selected "This Month", confirmed
    stats reflect current calendar month and the chart switches to a
    monthly bar view.
  • Period selector — All Time: Confirmed all-time aggregates are
    returned and the monthly chart is shown.
  • Loading state: Confirmed skeleton placeholders appear between
    period switches before data resolves.
  • TypeScript: Ran npx tsc --noEmit — no new errors introduced
    in analytics/page.tsx or api/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:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings/lint errors
  • I have checked that my branch is up-to-date with main
  • All tests pass locally with my changes

…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
@vercel

vercel Bot commented Jul 17, 2026

Copy link
Copy Markdown

@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 MistryVishwa added ssoc26 Main tag identifying the repository for Social Summer of Code 2026 Medium 30 Points labels Jul 18, 2026
@MistryVishwa
MistryVishwa merged commit f9468d9 into MistryVishwa:main Jul 18, 2026
1 of 2 checks passed
@Mohammad-Hassan027
Mohammad-Hassan027 deleted the feat/91-analytics-period-selector branch July 19, 2026 03:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Medium 30 Points ssoc26 Main tag identifying the repository for Social Summer of Code 2026

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE] Make analytics period selector functional

2 participants