Skip to content

Fix: Implement filter and auth credentials persistence on page refresh (#291)#293

Open
surjeetkumar8006 wants to merge 7 commits into
GitMetricsLab:mainfrom
surjeetkumar8006:fix-filter-persistence
Open

Fix: Implement filter and auth credentials persistence on page refresh (#291)#293
surjeetkumar8006 wants to merge 7 commits into
GitMetricsLab:mainfrom
surjeetkumar8006:fix-filter-persistence

Conversation

@surjeetkumar8006
Copy link
Copy Markdown

@surjeetkumar8006 surjeetkumar8006 commented May 17, 2026

Description

This PR resolves issue #291 by implementing localStorage persistence for the tracking dashboard filters and GitHub authentication credentials.

Previously, refreshing the page would reset all selected filters and require the user to re-enter their GitHub username and Personal Access Token.

Changes Made:

  • src/pages/Tracker/Tracker.tsx: Initialized filter states (tab, page, issue/PR state filters, search queries, and dates) using localStorage.getItem and added a useEffect to sync them.
  • src/hooks/useGitHubAuth.ts: Ensured the GitHub username and Token are also stored and retrieved from localStorage so users stay authenticated on reload.
  • tsconfig.app.json: Removed an unsupported TypeScript compiler option to resolve VS Code syntax warnings.

Related Issue

Fixes #291

Checklist

  • Tested the changes locally
  • Verified that filters persist after page reload
  • Verified that authentication credentials persist after page reload

Summary by CodeRabbit

  • New Features

    • GitHub credentials (username & token) are now saved/restored across sessions; a Logout button appears when signed in.
    • Tracker page state (filters, tabs, pagination, repo, date range, search) persists between sessions; Reset Filters only shown when non-defaults are set.
    • New controls to clear previously fetched GitHub data and surface error state.
  • Chores

    • Minor TypeScript config ordering adjusted with no functional changes.

Review Change Stack

@netlify
Copy link
Copy Markdown

netlify Bot commented May 17, 2026

Deploy Preview for github-spy ready!

Name Link
🔨 Latest commit 19b3536
🔍 Latest deploy log https://app.netlify.com/projects/github-spy/deploys/6a101bf49406a80008db4b38
😎 Deploy Preview https://deploy-preview-293--github-spy.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 17, 2026

Warning

Rate limit exceeded

@surjeetkumar8006 has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 29 minutes and 42 seconds before requesting another review.

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 442cc1b8-5983-401f-8fc4-839384b21ab3

📥 Commits

Reviewing files that changed from the base of the PR and between 945cc48 and 19b3536.

📒 Files selected for processing (2)
  • package.json
  • src/hooks/useGitHubAuth.ts
📝 Walkthrough

Walkthrough

Auth hook reads/writes credentials to sessionStorage and exposes getOctokit(), error, and logout; data hook exposes clearData(); Tracker page persists tabs/filters/pagination to localStorage, shows Logout when credentials exist, and clears state/localStorage on reset or logout; tsconfig ordering adjusted.

Changes

State persistence

Layer / File(s) Summary
GitHub auth and Octokit handling
src/hooks/useGitHubAuth.ts
useGitHubAuth reads tracker_username/tracker_token from sessionStorage, writes updates back via useEffect, provides getOctokit() that constructs an Octokit or returns null, surfaces error/setError, and adds logout() to clear state and sessionStorage.
Data hook clear
src/hooks/useGitHubData.ts
useGitHubData exposes clearData() which resets issues/pr arrays, total counts, and clears the error state.
Tracker UI persistence and reset
src/pages/Tracker/Tracker.tsx
Tracker initializes tab, page, filters, and date inputs from localStorage and persists changes; handleResetFilters removes related localStorage keys; handleLogout calls clearData and resets filters; Logout and Reset buttons are conditionally rendered.
tsconfig ordering tweak
tsconfig.app.json
Reorders noFallthroughCasesInSwitch inside compilerOptions; no functional compiler option change.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related issues

Possibly related PRs

Suggested labels

gssoc25, type:feature

Suggested reviewers

  • mehul-m-prajapati

Poem

🐇 I stash the token where the session stays,

tabs and filters nest in local arrays.
Logout hops, clearing crumbs away,
data emptied, defaults come out to play.
Hooray — small paws made state obey!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: implementing persistence for filters and auth credentials on page refresh, directly addressing the linked issue #291.
Description check ✅ Passed The description covers the main changes, related issue reference, and includes a checklist confirming testing. While the template formatting is not perfectly matched, all key information is present.
Linked Issues check ✅ Passed The PR fully addresses the objective in #291 by implementing localStorage/sessionStorage persistence for filters and auth credentials, ensuring they survive page reloads as required.
Out of Scope Changes check ✅ Passed The tsconfig.app.json change (removing unsupported TypeScript compiler option) is a minor supporting fix directly related to resolving VS Code syntax warnings introduced by the main changes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/hooks/useGitHubAuth.ts`:
- Around line 5-6: The hook useGitHubAuth is storing sensitive GitHub
credentials in localStorage via the state initializers for username and token
(the useState calls that read 'tracker_username' and 'tracker_token'), which is
insecure; replace this client-side persistence with a server-side session flow
where the PAT is never stored in browser storage and is instead kept in an
httpOnly cookie or backend session and accessed via authenticated API endpoints
from the frontend; if a backend session cannot be implemented immediately,
change the storage fallback to sessionStorage (read/write
'tracker_username'/'tracker_token' from sessionStorage) as a temporary
mitigation or implement client-side encryption before persisting, but prefer
updating the authentication flow in useGitHubAuth to delegate storage and token
refresh to the server.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: da78dd20-77df-4f11-86fd-cc0aa3ed58e1

📥 Commits

Reviewing files that changed from the base of the PR and between a2452b3 and 4b4e5b3.

📒 Files selected for processing (3)
  • src/hooks/useGitHubAuth.ts
  • src/pages/Tracker/Tracker.tsx
  • tsconfig.app.json

Comment thread src/hooks/useGitHubAuth.ts Outdated
@surjeetkumar8006
Copy link
Copy Markdown
Author

Updated the PR based on review feedback:

  • Replaced localStorage with sessionStorage for GitHub credentials
  • Resolved the Octokit import issue
  • Re-tested filter persistence and authentication flow

All checks are now passing.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/hooks/useGitHubAuth.ts (1)

24-30: ⚠️ Potential issue | 🔴 Critical | ⚡ Quick win

Restore error in the hook return shape to avoid consumer breakage.

useGitHubAuth() no longer returns error, but Tracker.tsx reads it at Line 58. This causes a TypeScript compile error (Property 'error' does not exist ...).

Proposed fix
   return {
     username,
     setUsername,
     token,
     setToken,
+    error,
     getOctokit,
   };
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/hooks/useGitHubAuth.ts` around lines 24 - 30, The hook useGitHubAuth was
changed to stop returning error which breaks consumers like Tracker.tsx that
read error; restore an error state (e.g., const [error, setError] =
useState<Error | null>(null)) inside useGitHubAuth, ensure any failures (such as
in getOctokit) set this error via setError, and include error in the returned
object along with username, setUsername, token, setToken, and getOctokit so
existing callers continue to compile.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@src/hooks/useGitHubAuth.ts`:
- Around line 24-30: The hook useGitHubAuth was changed to stop returning error
which breaks consumers like Tracker.tsx that read error; restore an error state
(e.g., const [error, setError] = useState<Error | null>(null)) inside
useGitHubAuth, ensure any failures (such as in getOctokit) set this error via
setError, and include error in the returned object along with username,
setUsername, token, setToken, and getOctokit so existing callers continue to
compile.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 6d68ef73-dec8-43ae-9c39-234731372d35

📥 Commits

Reviewing files that changed from the base of the PR and between 4b4e5b3 and eb963d2.

📒 Files selected for processing (2)
  • src/hooks/useGitHubAuth.ts
  • src/pages/Tracker/Tracker.tsx

@surjeetkumar8006
Copy link
Copy Markdown
Author

Hi maintainers,
I’ve addressed the review feedback, resolved the security concern by switching credentials storage to sessionStorage, and re-tested the complete persistence flow locally.

All major checks are passing now. Please review when convenient. Thanks!

@surjeetkumar8006
Copy link
Copy Markdown
Author

Description

This PR resolves issue #291 by implementing localStorage persistence for the tracking dashboard filters and GitHub authentication credentials.

Previously, refreshing the page would reset all selected filters and require the user to re-enter their GitHub username and Personal Access Token.

Changes Made:

  • src/pages/Tracker/Tracker.tsx: Initialized filter states (tab, page, issue/PR state filters, search queries, and dates) using localStorage.getItem and added a useEffect to sync them.
  • src/hooks/useGitHubAuth.ts: Ensured the GitHub username and Token are also stored and retrieved from localStorage so users stay authenticated on reload.
  • tsconfig.app.json: Removed an unsupported TypeScript compiler option to resolve VS Code syntax warnings.

Related Issue

Fixes #291

Checklist

  • Tested the changes locally
  • Verified that filters persist after page reload
  • Verified that authentication credentials persist after page reload

Summary by CodeRabbit

  • New Features

    • GitHub authentication credentials (username & token) are now automatically saved and restored across sessions.
    • Tracker page configuration — filters, tabs, pagination, selected repo, date range, and search — is now persisted between sessions for a seamless experience.
  • Chores

    • Minor TypeScript config ordering adjusted with no functional changes.

Review Change Stack

@surjeetkumar8006
Copy link
Copy Markdown
Author

Hi @GitMetricsLab,

I have addressed the CodeRabbit review feedback:

  • Restored the error state in useGitHubAuth hook.
  • Added robust error handling inside getOctokit using a try-catch block to gracefully capture and report any client initialization failures.

All checks are passing successfully now. Please review and merge the PR when convenient. Thank you!

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/hooks/useGitHubAuth.ts (1)

9-12: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

logout() key removal is being undone by the persistence effect.

Line 9–Line 12 always calls setItem, so after Line 32–Line 33 removeItem, the next render writes both keys back as empty strings. Persist with remove-on-empty instead.

Proposed fix
  useEffect(() => {
-    sessionStorage.setItem('tracker_username', username);
-    sessionStorage.setItem('tracker_token', token);
+    if (username) {
+      sessionStorage.setItem('tracker_username', username);
+    } else {
+      sessionStorage.removeItem('tracker_username');
+    }
+
+    if (token) {
+      sessionStorage.setItem('tracker_token', token);
+    } else {
+      sessionStorage.removeItem('tracker_token');
+    }
   }, [username, token]);

Also applies to: 28-34

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/hooks/useGitHubAuth.ts` around lines 9 - 12, The effect in
useGitHubAuth.ts that writes sessionStorage keys ('tracker_username' and
'tracker_token') in the useEffect is overwriting logout()'s removeItem calls;
update the effect in the useGitHubAuth hook so it sets each key only if the
value is non-empty (or non-null/undefined) and calls sessionStorage.removeItem
for empty values instead of sessionStorage.setItem with an empty string; target
the useEffect block that currently calls sessionStorage.setItem for username and
token so it conditionally uses setItem or removeItem for each key.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/hooks/useGitHubData.ts`:
- Around line 242-248: clearData currently only resets lists and totals but
leaves the rateLimited flag and any in-flight request lifecycle intact; update
clearData to also clear rateLimited and abort/reset any active request tracker
(e.g., abortController, activeRequest or inFlightRequest ref) so future fetches
aren’t blocked and stale responses can’t repopulate cleared state. Find the
clearData function and add steps to set rateLimited = false and to cancel or
null out the in-flight request handle used by the fetch logic (the same
controller/ref used around the fetch at or near the earlier fetch logic on line
~99).

---

Outside diff comments:
In `@src/hooks/useGitHubAuth.ts`:
- Around line 9-12: The effect in useGitHubAuth.ts that writes sessionStorage
keys ('tracker_username' and 'tracker_token') in the useEffect is overwriting
logout()'s removeItem calls; update the effect in the useGitHubAuth hook so it
sets each key only if the value is non-empty (or non-null/undefined) and calls
sessionStorage.removeItem for empty values instead of sessionStorage.setItem
with an empty string; target the useEffect block that currently calls
sessionStorage.setItem for username and token so it conditionally uses setItem
or removeItem for each key.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 495714b9-bf49-4dc1-95dc-e3830899e3d5

📥 Commits

Reviewing files that changed from the base of the PR and between eb963d2 and 945cc48.

📒 Files selected for processing (3)
  • src/hooks/useGitHubAuth.ts
  • src/hooks/useGitHubData.ts
  • src/pages/Tracker/Tracker.tsx

Comment thread src/hooks/useGitHubData.ts Outdated
@surjeetkumar8006 surjeetkumar8006 force-pushed the fix-filter-persistence branch from 945cc48 to fc405b6 Compare May 22, 2026 08:45
@surjeetkumar8006
Copy link
Copy Markdown
Author

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 22, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

🐛 Bug Report: Filter persistence broken on page refresh

2 participants