Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions docs/frontend/state-management.md
Original file line number Diff line number Diff line change
Expand Up @@ -235,3 +235,12 @@ const folder = useSelector((state: RootState) =>
```

This Redux-based architecture provides a scalable and maintainable state management solution that grows with our application's complexity.

## React Hooks Guidelines

When working on frontend components, especially in onboarding flows:

- Always include all external variables, props, and functions used inside a `useEffect` hook in its dependency array.
- Avoid using empty dependency arrays (`[]`) when the effect relies on props, Redux dispatch, context values, or functions returned from custom hooks.
- This helps prevent stale closures, unexpected behavior, and navigation issues during multi-step flows.
- Follow the React Rules of Hooks and ensure ESLint hook rules pass before submitting a PR.
9,966 changes: 9,966 additions & 0 deletions frontend/pnpm-lock.yaml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,12 @@ export const AvatarSelectionStep: React.FC<AvatarNameSelectionStepProps> = ({
const [selectedAvatar, setLocalAvatar] = useState('');

useEffect(() => {
if (localStorage.getItem('name') && localStorage.getItem('avatar')) {
const hasName = localStorage.getItem('name');
const hasAvatar = localStorage.getItem('avatar');
if ( hasName && hasAvatar) {
dispatch(markCompleted(stepIndex));
}
}, []);
}, [dispatch,stepIndex]);

const handleAvatarSelect = (avatar: string) => {
setLocalAvatar(avatar);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export function FolderSetupStep({
if (localStorage.getItem('folderChosen') === 'true') {
dispatch(markCompleted(stepIndex));
}
}, []);
}, [dispatch,stepIndex]);

const { pickSingleFolder, addFolderMutate } = useFolder({
title: 'Select folder to import photos from',
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/components/OnboardingSteps/ServerCheck.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export const ServerCheck: React.FC<ServerCheckProps> = ({ stepIndex }) => {
useEffect(() => {
if (mainBackendLoading || syncMicroserviceLoading) {
dispatch(showLoader('Waiting for servers to start'));
return;
}
Comment on lines 39 to 42

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion | 🟠 Major

Excellent fix: Early return prevents logic bugs during loading.

Adding the early return after dispatching the loader prevents the subsequent success-handling logic from executing while services are still loading. This is an essential fix that ensures proper control flow.

🤖 Prompt for AI Agents
In frontend/src/components/OnboardingSteps/ServerCheck.tsx around lines 39 to
42, ensure the early-return remains: when mainBackendLoading ||
syncMicroserviceLoading is true, dispatch showLoader('Waiting for servers to
start') and immediately return so that the subsequent success-handling logic
does not run while services are still loading; keep this control flow and remove
or guard any downstream success code that would otherwise execute during
loading.

if (mainBackendError || syncMicroserviceError) {
dispatch(hideLoader());
Expand All @@ -53,12 +54,15 @@ export const ServerCheck: React.FC<ServerCheckProps> = ({ stepIndex }) => {
setTimeout(() => {
exit(1);
}, 2000);
return;
}
if (mainBackendSuccess && syncMicroserviceSuccess) {
dispatch(hideLoader());
dispatch(markCompleted(stepIndex));
}
}, [
dispatch,
stepIndex,
mainBackendSuccess,
mainBackendLoading,
mainBackendError,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const ThemeSelectionStep: React.FC<ThemeSelectionStepProps> = ({
if (localStorage.getItem('themeChosen')) {
dispatch(markCompleted(stepIndex));
}
}, []);
}, [dispatch,stepIndex]);
const handleThemeChange = (value: 'light' | 'dark' | 'system') => {
setTheme(value);
};
Expand Down
11 changes: 9 additions & 2 deletions frontend/src/components/OnboardingSteps/UpdateStep.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,26 @@ export const UpdateStep: React.FC<UpdateStepProps> = ({ stepIndex }) => {
const dispatch = useDispatch();

useEffect(() => {
let isMount = true;
// Check for updates on mount
const check = async () => {
if (!isMount) {
return;
}
dispatch(showLoader('Checking for updates...'));
const hasUpdate = await checkForUpdates();
dispatch(hideLoader());

// If no update, mark onboarding step complete
if (!hasUpdate) {
if (isMount && !hasUpdate) {
dispatch(markCompleted(stepIndex));
}
};
check();
}, []);
return () => {
isMount = false;
}
}, [dispatch,stepIndex, checkForUpdates]);

// Show update dialog only if update is available
if (updateAvailable) {
Expand Down
24 changes: 24 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.