feat(task-management): enhance task timer synchronization and color handling
- Updated `CustomColordLabel` and `CustomNumberLabel` components to improve color handling by removing the alpha channel logic and implementing a dynamic text color based on background luminance. - Enhanced task management slice to preserve timer state when fetching tasks, ensuring active timers are maintained across updates. - Modified socket handlers to synchronize timer state between task slices, improving consistency in task time tracking. - Refactored `useTaskTimer` hook to streamline local and Redux state synchronization for timer management.
This commit is contained in:
@@ -33,6 +33,7 @@ import {
|
||||
updateTaskDescription,
|
||||
updateSubTasks,
|
||||
updateTaskProgress,
|
||||
updateTaskTimeTracking,
|
||||
} from '@/features/tasks/tasks.slice';
|
||||
import {
|
||||
addTask,
|
||||
@@ -936,6 +937,8 @@ export const useTaskSocketHandlers = () => {
|
||||
const { task_id, start_time } = typeof data === 'string' ? JSON.parse(data) : data;
|
||||
if (!task_id) return;
|
||||
|
||||
const timerTimestamp = start_time ? (typeof start_time === 'number' ? start_time : parseInt(start_time)) : Date.now();
|
||||
|
||||
// Update the task-management slice to include timer state
|
||||
const currentTask = store.getState().taskManagement.entities[task_id];
|
||||
if (currentTask) {
|
||||
@@ -943,13 +946,16 @@ export const useTaskSocketHandlers = () => {
|
||||
...currentTask,
|
||||
timeTracking: {
|
||||
...currentTask.timeTracking,
|
||||
activeTimer: start_time ? (typeof start_time === 'number' ? start_time : parseInt(start_time)) : Date.now(),
|
||||
activeTimer: timerTimestamp,
|
||||
},
|
||||
updatedAt: new Date().toISOString(),
|
||||
updated_at: new Date().toISOString(),
|
||||
};
|
||||
dispatch(updateTask(updatedTask));
|
||||
}
|
||||
|
||||
// Also update the tasks slice activeTimers to keep both slices in sync
|
||||
dispatch(updateTaskTimeTracking({ taskId: task_id, timeTracking: timerTimestamp }));
|
||||
} catch (error) {
|
||||
logger.error('Error handling timer start event:', error);
|
||||
}
|
||||
@@ -975,6 +981,9 @@ export const useTaskSocketHandlers = () => {
|
||||
};
|
||||
dispatch(updateTask(updatedTask));
|
||||
}
|
||||
|
||||
// Also update the tasks slice activeTimers to keep both slices in sync
|
||||
dispatch(updateTaskTimeTracking({ taskId: task_id, timeTracking: null }));
|
||||
} catch (error) {
|
||||
logger.error('Error handling timer stop event:', error);
|
||||
}
|
||||
|
||||
@@ -50,7 +50,11 @@ export const useTaskTimer = (taskId: string, initialStartTime: number | null) =>
|
||||
|
||||
// Timer management effect
|
||||
useEffect(() => {
|
||||
if (started && localStarted && reduxStartTime) {
|
||||
if (started && reduxStartTime) {
|
||||
// Sync local state with Redux state
|
||||
if (!localStarted) {
|
||||
setLocalStarted(true);
|
||||
}
|
||||
clearTimerInterval();
|
||||
timerTick();
|
||||
intervalRef.current = setInterval(timerTick, 1000);
|
||||
|
||||
Reference in New Issue
Block a user