Start integrating the onboarding flow with backend 13
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
* Progress tracking service - Clean, standardized implementation
|
||||
*/
|
||||
|
||||
import { useCallback, useEffect } from 'react';
|
||||
import { useCallback, useEffect, useRef } from 'react';
|
||||
import { onboardingService } from '../../../../api/services/onboarding';
|
||||
import { createServiceHook } from '../utils/createServiceHook';
|
||||
import type { ProgressTrackingState } from '../core/types';
|
||||
@@ -20,6 +20,7 @@ const useProgressTrackingService = createServiceHook<ProgressTrackingState>({
|
||||
|
||||
export const useProgressTracking = () => {
|
||||
const service = useProgressTrackingService();
|
||||
const initializationAttempted = useRef(false);
|
||||
|
||||
// Load initial progress from backend
|
||||
const loadProgress = useCallback(async (): Promise<UserProgress | null> => {
|
||||
@@ -121,12 +122,13 @@ export const useProgressTracking = () => {
|
||||
}
|
||||
}, []);
|
||||
|
||||
// Auto-load progress on hook initialization
|
||||
// Auto-load progress on hook initialization - PREVENT multiple attempts
|
||||
useEffect(() => {
|
||||
if (!service.data?.isInitialized) {
|
||||
if (!service.data?.isInitialized && !initializationAttempted.current && !service.isLoading) {
|
||||
initializationAttempted.current = true;
|
||||
loadProgress();
|
||||
}
|
||||
}, [loadProgress, service.data?.isInitialized]);
|
||||
}, [service.data?.isInitialized, service.isLoading]); // Remove loadProgress from deps
|
||||
|
||||
return {
|
||||
// State
|
||||
|
||||
Reference in New Issue
Block a user