feat(task-timer): add timer start and stop handlers for task management

- Implemented handleTimerStart and handleTimerStop functions to manage task timer state via socket events.
- Updated useTaskSocketHandlers to register new socket event listeners for timer actions.
- Enhanced useTaskTimer to retrieve active timer state from both the old and new task management slices.
- Added activeTimer property to Task type for tracking the start timestamp of active timers.
This commit is contained in:
chamiakJ
2025-07-10 12:27:15 +05:30
parent 70cca5d4c0
commit 6ebdd78855
3 changed files with 60 additions and 1 deletions

View File

@@ -6,6 +6,7 @@ import logger from '@/utils/errorLogger';
import { useAppDispatch } from '@/hooks/useAppDispatch';
import { updateTaskTimeTracking } from '@/features/tasks/tasks.slice';
import { useAppSelector } from '@/hooks/useAppSelector';
import { selectTaskById } from '@/features/task-management/task-management.slice';
export const useTaskTimer = (taskId: string, initialStartTime: number | null) => {
const dispatch = useAppDispatch();
@@ -15,7 +16,10 @@ export const useTaskTimer = (taskId: string, initialStartTime: number | null) =>
const hasInitialized = useRef(false); // Track if we've initialized
const activeTimers = useAppSelector(state => state.taskReducer.activeTimers);
const reduxStartTime = activeTimers[taskId];
const task = useAppSelector(state => selectTaskById(state, taskId));
// Check both the old slice (activeTimers) and new slice (task.timeTracking.activeTimer)
const reduxStartTime = activeTimers[taskId] || task?.timeTracking?.activeTimer;
const started = Boolean(reduxStartTime);
const [timeString, setTimeString] = useState(DEFAULT_TIME_LEFT);