|
|
|
|
@ -33,13 +33,6 @@ export function useTimeLimit(): UseTimeLimitReturn {
@@ -33,13 +33,6 @@ export function useTimeLimit(): UseTimeLimitReturn {
|
|
|
|
|
const startTimeRef = useRef<number | null>(null); |
|
|
|
|
const lastUpdateRef = useRef<number>(Date.now()); |
|
|
|
|
|
|
|
|
|
// Fetch limit from server on mount
|
|
|
|
|
useEffect(() => { |
|
|
|
|
getDailyLimit().then(limit => { |
|
|
|
|
setDailyLimit(limit); |
|
|
|
|
}); |
|
|
|
|
}, []); |
|
|
|
|
|
|
|
|
|
// Update state from localStorage and cached server limit
|
|
|
|
|
const updateState = useCallback(() => { |
|
|
|
|
setDailyLimit(getDailyLimitSync()); |
|
|
|
|
@ -48,6 +41,15 @@ export function useTimeLimit(): UseTimeLimitReturn {
@@ -48,6 +41,15 @@ export function useTimeLimit(): UseTimeLimitReturn {
|
|
|
|
|
setLimitReached(isLimitReached()); |
|
|
|
|
}, []); |
|
|
|
|
|
|
|
|
|
// Fetch limit from server on mount
|
|
|
|
|
useEffect(() => { |
|
|
|
|
getDailyLimit().then(limit => { |
|
|
|
|
setDailyLimit(limit); |
|
|
|
|
// Immediately recalculate limitReached with the correct server limit
|
|
|
|
|
updateState(); |
|
|
|
|
}); |
|
|
|
|
}, [updateState]); |
|
|
|
|
|
|
|
|
|
// Start tracking time
|
|
|
|
|
const startTracking = useCallback(() => { |
|
|
|
|
if (limitReached) { |
|
|
|
|
|