mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-04-30 19:36:25 +02:00
refactor: use functional setState in useCallback for stable callbacks in onboarding tour and sidebar
This commit is contained in:
parent
3724a1530c
commit
1705e881ec
2 changed files with 32 additions and 20 deletions
|
|
@ -37,8 +37,14 @@ export function useSidebarState(defaultCollapsed = false): UseSidebarStateReturn
|
|||
}, []);
|
||||
|
||||
const toggleCollapsed = useCallback(() => {
|
||||
setIsCollapsed(!isCollapsed);
|
||||
}, [isCollapsed, setIsCollapsed]);
|
||||
setIsCollapsedState(prev => {
|
||||
const next = !prev;
|
||||
try {
|
||||
document.cookie = `${SIDEBAR_COOKIE_NAME}=${next}; path=/; max-age=${SIDEBAR_COOKIE_MAX_AGE}`;
|
||||
} catch {}
|
||||
return next;
|
||||
});
|
||||
}, []);
|
||||
|
||||
// Keyboard shortcut: Cmd/Ctrl + \
|
||||
useEffect(() => {
|
||||
|
|
|
|||
|
|
@ -666,27 +666,33 @@ export function OnboardingTour() {
|
|||
}, [targetEl, isActive]);
|
||||
|
||||
const handleNext = useCallback(() => {
|
||||
if (stepIndex < TOUR_STEPS.length - 1) {
|
||||
retryCountRef.current = 0;
|
||||
setShouldAnimate(true);
|
||||
setStepIndex(stepIndex + 1);
|
||||
} else {
|
||||
// Tour completed - save to localStorage
|
||||
if (user?.id) {
|
||||
const tourKey = `surfsense-tour-${user.id}`;
|
||||
localStorage.setItem(tourKey, "true");
|
||||
retryCountRef.current = 0;
|
||||
setShouldAnimate(true);
|
||||
setStepIndex(prev => {
|
||||
if (prev < TOUR_STEPS.length - 1) {
|
||||
return prev + 1;
|
||||
} else {
|
||||
// Tour completed - save to localStorage
|
||||
if (user?.id) {
|
||||
const tourKey = `surfsense-tour-${user.id}`;
|
||||
localStorage.setItem(tourKey, "true");
|
||||
}
|
||||
setIsActive(false);
|
||||
return prev;
|
||||
}
|
||||
setIsActive(false);
|
||||
}
|
||||
}, [stepIndex, user?.id]);
|
||||
});
|
||||
}, [user?.id]);
|
||||
|
||||
const handlePrev = useCallback(() => {
|
||||
if (stepIndex > 0) {
|
||||
retryCountRef.current = 0;
|
||||
setShouldAnimate(true);
|
||||
setStepIndex(stepIndex - 1);
|
||||
}
|
||||
}, [stepIndex]);
|
||||
retryCountRef.current = 0;
|
||||
setShouldAnimate(true);
|
||||
setStepIndex(prev => {
|
||||
if (prev > 0) {
|
||||
return prev - 1;
|
||||
}
|
||||
return prev;
|
||||
});
|
||||
}, []);
|
||||
|
||||
const handleSkip = useCallback(() => {
|
||||
// Tour skipped - save to localStorage
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue