feat(worker): ✨ Add profile tracking hook for WorkerAvailabilityPage availability metrics
This commit is contained in:
parent
afccef5a81
commit
dbddd54564
2 changed files with 14 additions and 21 deletions
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue