* Fix Today page task completion issues - Fix completed task border color staying as priority color - Add isInCompletedSection prop to TaskItem for explicit completed state - Tasks in completed section now always show green border regardless of priority - Fixes race condition where status wasn't updated during optimistic UI update - Fix completed task reappearing after unmarking and page refresh - Add defensive check in backend to force clear completed_at when status is not DONE - Add development logging in tasksService for debugging completion toggle - Ensures database state is consistent even if handleCompletionStatus doesn't clear it - Update TaskList and TasksToday components to pass isInCompletedSection prop - Explicitly marks tasks rendered in the completed section - Prevents border color flickering during state transitions * Add comprehensive logging to debug completion issues * Fix duplicate API requests causing completion state issues - Separate state update logic from API call in handleTaskUpdate - Create new updateTaskInState function for state-only updates - Pass onTaskCompletionToggle to completed section to avoid duplicate calls - This fixes the persistence issue where unmarked tasks came back after refresh - Completion toggles now only make ONE API call instead of two * Add debug logging to updateTaskInState
34 lines
1 KiB
JavaScript
34 lines
1 KiB
JavaScript
const { Task } = require('../../../models');
|
|
const { parseStatus } = require('../core/parsers');
|
|
|
|
async function handleCompletionStatus(taskAttributes, status, task) {
|
|
if (status === undefined) return;
|
|
|
|
const newStatus = parseStatus(status);
|
|
const oldStatus = parseStatus(task.status);
|
|
|
|
console.log('[handleCompletionStatus]', {
|
|
taskId: task.id,
|
|
statusParam: status,
|
|
newStatus,
|
|
oldStatus,
|
|
taskCompletedAt: task.completed_at,
|
|
});
|
|
|
|
if (newStatus === Task.STATUS.DONE && oldStatus !== Task.STATUS.DONE) {
|
|
console.log('[handleCompletionStatus] Setting completed_at to NOW');
|
|
taskAttributes.completed_at = new Date();
|
|
} else if (
|
|
newStatus !== Task.STATUS.DONE &&
|
|
oldStatus === Task.STATUS.DONE
|
|
) {
|
|
console.log('[handleCompletionStatus] Clearing completed_at to NULL');
|
|
taskAttributes.completed_at = null;
|
|
} else {
|
|
console.log('[handleCompletionStatus] No completed_at change needed');
|
|
}
|
|
}
|
|
|
|
module.exports = {
|
|
handleCompletionStatus,
|
|
};
|