feat(worker): Add profile tracking hook for WorkerAvailabilityPage availability metrics

This commit is contained in:
Lilith 2026-01-20 19:21:32 -08:00
parent afccef5a81
commit dbddd54564
2 changed files with 14 additions and 21 deletions

View file

@ -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;

View file

@ -219,19 +219,6 @@ export function useProfileTracking(
const discoveryBatchRef = useRef<TrackDiscoveryParams[]>([])
const batchTimeoutRef = useRef<NodeJS.Timeout | null>(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)