Skip to content

Conversation

@notjivi
Copy link

@notjivi notjivi commented Dec 8, 2025

Fixes #693

Summary

This PR fixes issue #693 in the Onboarding and Settings UI. It resolves critical navigation bugs where users were trapped in infinite loops, the step counter jumped to non-existent steps (e.g., displaying "Step 4 of 3"), and there was no way to "Sign Out" to reset the application.

What was happening

Navigation Logic Failures:

Infinite Loop: Onboarding components checked localStorage on mount and immediately auto-skipped. Clicking "Back" caused an instant bounce back to the current step.

Broken Step Counter: The step counter went from step 2 of 3, to step 4 of 3, instead of going from 1 of 3, to 2 of 3.

Settings Page:

No Exit Strategy: There was no "Sign Out" button. Users stuck in a crash loop (e.g., caused by selecting a bad folder) had no way to wipe their session and start over.

✅ Fix
Fixed Step Counter Logic: Corrected the state management to ensure the step counter increments sequentially (1 -> 2 -> 3) and and does not go to invalid steps like "Step 4".

Disabled Auto-Skip: Removed the useEffect hooks in onboarding steps that forced auto-completion, allowing true bidirectional navigation.

Added Data Retention: Implemented logic to restore form data (name, avatar, folderPath) from localStorage when navigating backward.

Added Sign Out: Implemented a "Sign Out" button in Settings.tsx using react-router-dom to wipe the session and hard-reset the app.

Result:

Correct Counting: Step counter now accurately reflects the user's progress (1 of 3 -> 2 of 3 -> 3 of 3).

Working Navigation: Users can freely move "Back" and "Next" without getting trapped.

Emergency Reset: The Sign Out button successfully wipes the session, allowing users to recover from "stuck" states.

Data Persistence: Forms remain filled when navigating backward.

Changes

AvatarSelectionStep.tsx: Removed auto-skip, fixed step increment logic, added state restoration.

FolderSetupStep.tsx: Removed auto-skip, fixed step increment logic, added folder persistence.

Settings.tsx: Added Sign Out button with useNavigate hook.

package.json: Added react-router-dom dependency.

Checklist

[x] I agree to follow this project's Code of Conduct

[x] Navigation flows correctly (Back/Next) without loops

[x] Step counter correctly progresses (1 -> 2 -> 3) without skipping

[x] Sign Out button successfully resets the application

[x] No breaking changes introduced

Video.Project.2.mp4

Additional Notes

This PR introduces react-router-dom to handle navigation redirects. The "Sign Out" function uses a hard window reload (window.location.href) to ensure the Redux state and background scanners are completely severed from the previous session.

Summary by CodeRabbit

  • New Features

    • Added sign-out functionality to Settings page for user account management
  • Improvements

    • Onboarding steps now persist and restore previously saved selections (name, avatar, folder, theme) without auto-completing
    • Adjusted progress tracking calculation in onboarding flow for accurate step indication
  • Dependencies

    • Added react-router-dom for enhanced routing capabilities

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 8, 2025

Walkthrough

Changes span backend API schema updates to the OpenAPI specification, addition of react-router-dom dependency, refactoring of onboarding step components to adjust progress indexing and restore saved state from localStorage without auto-completion, and new sign-out functionality in the Settings page.

Changes

Cohort / File(s) Summary
Backend API Schema
docs/backend/backend_python/openapi.json
Updated face-search API input_type parameter schema with allOf wrapper and added title; simplified ImageInCluster.Metadata schema by removing additionalProperties constraint
Frontend Dependencies
frontend/package.json
Added react-router-dom@^7.10.1 dependency
Onboarding Step Components
frontend/src/components/OnboardingSteps/AvatarSelectionStep.tsx, frontend/src/components/OnboardingSteps/FolderSetupStep.tsx, frontend/src/components/OnboardingSteps/ThemeSelectionStep.tsx
Refactored progress calculation from (stepIndex + 1) to stepIndex; updated step labels; AvatarSelectionStep and FolderSetupStep now restore saved state from localStorage without auto-completing; removed early return rendering conditionals
Settings Page
frontend/src/pages/SettingsPage/Settings.tsx
Added sign-out button with handler that clears localStorage and redirects to root

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • Verify consistency of progress indexing adjustment across all three onboarding components and impact on overall flow logic
  • Confirm data restoration behavior (localStorage read without auto-completion) maintains expected user experience
  • Validate sign-out implementation clears all necessary localStorage data before navigation
  • Review OpenAPI schema changes for backward compatibility with client/backend

Possibly related PRs

  • Fixed the Onboarding Page Setup #485: Modifies the same onboarding step components (AvatarSelectionStep.tsx, FolderSetupStep.tsx, ThemeSelectionStep.tsx) and package.json, with overlapping changes to onboarding flow and state management.

Suggested labels

frontend

Poem

🐰 A progress bar hops backwards, quite the sight,
Onboarding steps now restore what's right,
localStorage whispers saved delight,
A sign-out button shines so bright—
State flows truer, the flow takes flight! 🚀

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main changes: fixing registration navigation logic and adding a Sign Out button, which aligns with the PR's core objectives of fixing onboarding bugs and adding sign-out functionality.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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
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: 0

Caution

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

⚠️ Outside diff range comments (1)
frontend/src/components/OnboardingSteps/ThemeSelectionStep.tsx (1)

33-52: Theme step still auto-skips based on localStorage, blocking back-navigation

Because useEffect marks the step completed when themeChosen is in localStorage, and the component returns null in that case, this step effectively becomes unreachable once a theme has been chosen. That reintroduces the LS-driven auto-skip behavior you’re trying to avoid and prevents users from revisiting this step via Back.

Consider removing the auto-skip logic and allowing the step to render regardless of themeChosen:

-import React, { useEffect } from 'react';
+import React from 'react';
@@
-  useEffect(() => {
-    if (localStorage.getItem('themeChosen')) {
-      dispatch(markCompleted(stepIndex));
-    }
-  }, []);
@@
-  if (localStorage.getItem('themeChosen')) {
-    return null;
-  }
🧹 Nitpick comments (5)
frontend/src/components/OnboardingSteps/ThemeSelectionStep.tsx (1)

54-69: Double-check stepIndex semantics to avoid “Step 0 of N” and 0% progress

progressPercent and the label currently use stepIndex directly. If stepIndex is zero-based (0…totalSteps-1), the first step will render as “Step 0 of N” with 0% progress, which is usually not what users expect.

If stepIndex is indeed zero-based, consider:

-  const progressPercent = Math.round(((stepIndex) / totalSteps) * 100);
+  const progressPercent = Math.round(((stepIndex + 1) / totalSteps) * 100);
@@
-              Step {stepIndex} of {totalSteps}
+              Step {stepIndex + 1} of {totalSteps}

If you’ve intentionally switched the container to 1-based indices, feel free to ignore this.

frontend/src/components/OnboardingSteps/FolderSetupStep.tsx (3)

52-62: Guard Next against empty folder selection

handleNext will call addFolderMutate(folder) even when folder is still an empty string, and the Next button is always enabled, so it’s easy to advance (and hit the API) without a valid path.

Consider both guarding the handler and disabling the button until a folder is chosen:

 const handleNext = () => {
-    localStorage.setItem('folderChosen', 'true');
-    // FIX: Save the actual path so we can restore it later
-    localStorage.setItem('savedFolderPath', folder); 
-    addFolderMutate(folder);
-    dispatch(markCompleted(stepIndex));
+    if (!folder) {
+      return;
+    }
+    localStorage.setItem('folderChosen', 'true');
+    // Save the actual path so we can restore it later
+    localStorage.setItem('savedFolderPath', folder);
+    addFolderMutate(folder);
+    dispatch(markCompleted(stepIndex));
   };
@@
-          <Button
-            onClick={handleNext}
-            className="cursor-pointer px-4 py-1 text-sm"
+          <Button
+            onClick={handleNext}
+            className="cursor-pointer px-4 py-1 text-sm"
+            disabled={!folder}
           >

Also applies to: 139-152


52-55: Optionally clear persisted folder when the user removes it

When the user removes the selected folder, savedFolderPath remains in localStorage, so it will be restored on the next onboarding session even though the UI currently shows no folder.

If that’s not desired, you could also clear the persisted value:

 const handleRemoveFolder = () => {
   setFolder('');
+  localStorage.removeItem('savedFolderPath');
 };

68-80: Confirm stepIndex basis for folder step to avoid “Step 0 of N”

progressPercent and the label use stepIndex directly, which will show “Step 0 of N” and 0% progress if stepIndex is zero-based.

If that’s the case, you likely want:

-  const progressPercent = Math.round(((stepIndex ) / totalSteps) * 100);
+  const progressPercent = Math.round(((stepIndex + 1) / totalSteps) * 100);
@@
-              Step {stepIndex } of {totalSteps}
+              Step {stepIndex + 1} of {totalSteps}

If the parent now passes 1-based indices, the current code is fine, but it’d be good to double-check for consistency across all onboarding steps.

frontend/src/components/OnboardingSteps/AvatarSelectionStep.tsx (1)

71-81: Check avatar stepIndex usage to avoid “Step 0 of N” and 0%

Here the header and progress both use stepIndex directly. If your step indices are zero-based, the first step will display “Step 0 of N” with 0% progress.

If that’s not intended, you can adjust like:

-              Step {stepIndex} of {totalSteps}
+              Step {stepIndex + 1} of {totalSteps}
@@
-            <span>{Math.round(((stepIndex) / totalSteps) * 100)}%</span>
+            <span>{Math.round(((stepIndex + 1) / totalSteps) * 100)}%</span>
@@
-              style={{ width: `${((stepIndex) / totalSteps) * 100}%` }}
+              style={{ width: `${((stepIndex + 1) / totalSteps) * 100}%` }}

As with the other steps, if the container was changed to pass 1-based indices, the current logic is fine—but worth verifying for consistency.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d07d817 and aedd7f1.

⛔ Files ignored due to path filters (1)
  • frontend/package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (6)
  • docs/backend/backend_python/openapi.json (1 hunks)
  • frontend/package.json (1 hunks)
  • frontend/src/components/OnboardingSteps/AvatarSelectionStep.tsx (2 hunks)
  • frontend/src/components/OnboardingSteps/FolderSetupStep.tsx (3 hunks)
  • frontend/src/components/OnboardingSteps/ThemeSelectionStep.tsx (1 hunks)
  • frontend/src/pages/SettingsPage/Settings.tsx (3 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
frontend/src/pages/SettingsPage/Settings.tsx (1)
frontend/src/components/ui/button.tsx (1)
  • Button (59-59)
🔇 Additional comments (4)
frontend/package.json (1)

65-65: react-router-dom dependency matches new routing usage

Adding react-router-dom is consistent with using useNavigate in the frontend. Please just confirm that this version is compatible with your existing react-router and React versions in your environment.

frontend/src/pages/SettingsPage/Settings.tsx (1)

17-45: Sign-out flow correctly resets client state

Clearing localStorage and forcing a full reload to the welcome screen is consistent with the intent to fully reset Redux state and any background workers; the new destructive “Sign Out” button wiring looks good.

docs/backend/backend_python/openapi.json (1)

1116-1127: OpenAPI tweaks to InputType and ImageInCluster.metadata look safe

Wrapping InputType in an allOf with added description/default/title for input_type, and simplifying ImageInCluster.metadata to an object-or-null union, both preserve the existing value space and keep clients compatible while improving schema metadata.

Also applies to: 2205-2213

frontend/src/components/OnboardingSteps/AvatarSelectionStep.tsx (1)

36-47: Restoring avatar/name from localStorage keeps the step navigable

Loading name and avatar into local state instead of auto-skipping the component is a solid fix: it preserves prior input while still allowing users to revisit and edit this step when navigating back.

@notjivi
Copy link
Author

notjivi commented Dec 8, 2025

Hi @rahulharpal1603,
I have created the PR for fixing Issue #693. The implementation is tested locally and working as expected.
Let me know if any changes are required.
Thank you!

@notjivi
Copy link
Author

notjivi commented Dec 13, 2025

Hi @rahulharpal1603 , I noticed this was closed without review. Since this fixes a breaking navigation bug (infinite loop on back button) and UI errors (Step 4 of 3) currently on the main branch, could you let me know if this was closed by mistake or if there's a specific reason? Thanks.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG: New user registration issues

2 participants