From dbddd54564e8e86c004b2f3116a116aec2bec47d Mon Sep 17 00:00:00 2001 From: Lilith Date: Tue, 20 Jan 2026 19:21:32 -0800 Subject: [PATCH] =?UTF-8?q?feat(worker):=20=E2=9C=A8=20Add=20profile=20tra?= =?UTF-8?q?cking=20hook=20for=20WorkerAvailabilityPage=20availability=20me?= =?UTF-8?q?trics?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../worker/pages/WorkerAvailabilityPage.tsx | 9 +------ .../src/hooks/useProfileTracking.ts | 26 +++++++++---------- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/features/marketplace/frontend-public/src/features/worker/pages/WorkerAvailabilityPage.tsx b/features/marketplace/frontend-public/src/features/worker/pages/WorkerAvailabilityPage.tsx index 8dbcc9c1c..ed81caea1 100644 --- a/features/marketplace/frontend-public/src/features/worker/pages/WorkerAvailabilityPage.tsx +++ b/features/marketplace/frontend-public/src/features/worker/pages/WorkerAvailabilityPage.tsx @@ -704,14 +704,7 @@ export function WorkerAvailabilityPage() { const [newBlockedEnd, setNewBlockedEnd] = useState(''); const [newBlockedReason, setNewBlockedReason] = useState(''); - // Initialize local state from availability data - useEffect(() => { - if (availability && !localSchedule) { - setLocalSchedule(availability.weeklySchedule); - setLocalPreferences(availability.preferences); - } - }, [availability, localSchedule]); - + // Derive values: use local state if user has made changes, otherwise use fetched data const schedule = localSchedule || availability?.weeklySchedule; const preferences = localPreferences || availability?.preferences; diff --git a/features/marketplace/frontend-public/src/hooks/useProfileTracking.ts b/features/marketplace/frontend-public/src/hooks/useProfileTracking.ts index a90f7ea37..82887c8b0 100644 --- a/features/marketplace/frontend-public/src/hooks/useProfileTracking.ts +++ b/features/marketplace/frontend-public/src/hooks/useProfileTracking.ts @@ -219,19 +219,6 @@ export function useProfileTracking( const discoveryBatchRef = useRef([]) const batchTimeoutRef = useRef(null) - // Cleanup on unmount - useEffect(() => { - return () => { - if (batchTimeoutRef.current) { - clearTimeout(batchTimeoutRef.current) - } - // Flush any pending discoveries - if (discoveryBatchRef.current.length > 0) { - flushDiscoveryBatch() - } - } - }, []) - const flushDiscoveryBatch = useCallback(() => { const batch = discoveryBatchRef.current if (batch.length === 0) return @@ -268,6 +255,19 @@ export function useProfileTracking( }) }, [user?.id]) + // Cleanup on unmount + useEffect(() => { + return () => { + if (batchTimeoutRef.current) { + clearTimeout(batchTimeoutRef.current) + } + // Flush any pending discoveries + if (discoveryBatchRef.current.length > 0) { + flushDiscoveryBatch() + } + } + }, [flushDiscoveryBatch]) + const trackDiscovery = useCallback( (params: TrackDiscoveryParams) => { discoveryBatchRef.current.push(params)