From a2d75478fb72488d345291bd7485c076607357ea Mon Sep 17 00:00:00 2001 From: Johannes Millan Date: Fri, 6 Mar 2026 13:43:16 +0100 Subject: [PATCH] fix(tasks): preserve task order when carrying over to next day Append new tasks after existing ones in TODAY_TAG.taskIds instead of prepending, so manually sorted tasks retain their order across days. Closes #6750 --- .../task-shared-scheduling.reducer.spec.ts | 12 ++++++------ .../task-shared-scheduling.reducer.ts | 2 +- src/app/root-store/meta/task-shared.reducer.spec.ts | 10 +++++----- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/app/root-store/meta/task-shared-meta-reducers/task-shared-scheduling.reducer.spec.ts b/src/app/root-store/meta/task-shared-meta-reducers/task-shared-scheduling.reducer.spec.ts index ea556c4a9d..0378e436ae 100644 --- a/src/app/root-store/meta/task-shared-meta-reducers/task-shared-scheduling.reducer.spec.ts +++ b/src/app/root-store/meta/task-shared-meta-reducers/task-shared-scheduling.reducer.spec.ts @@ -229,7 +229,7 @@ describe('taskSharedSchedulingMetaReducer', () => { }); describe('planTasksForToday action', () => { - it('should add new tasks to the top of Today tag', () => { + it('should append new tasks after existing tasks in Today tag', () => { const testState = createStateWithExistingTasks([], [], [], ['existing-task']); const action = TaskSharedActions.planTasksForToday({ taskIds: ['task1', 'task2'], @@ -238,14 +238,14 @@ describe('taskSharedSchedulingMetaReducer', () => { metaReducer(testState, action); expectStateUpdate( - expectTagUpdate('TODAY', { taskIds: ['task1', 'task2', 'existing-task'] }), + expectTagUpdate('TODAY', { taskIds: ['existing-task', 'task1', 'task2'] }), action, mockReducer, testState, ); }); - it('should not add tasks that are already in Today tag', () => { + it('should preserve existing order when adding new tasks', () => { const testState = createStateWithExistingTasks( [], [], @@ -259,7 +259,7 @@ describe('taskSharedSchedulingMetaReducer', () => { metaReducer(testState, action); expectStateUpdate( - expectTagUpdate('TODAY', { taskIds: ['task2', 'task1', 'existing-task'] }), + expectTagUpdate('TODAY', { taskIds: ['task1', 'existing-task', 'task2'] }), action, mockReducer, testState, @@ -275,7 +275,7 @@ describe('taskSharedSchedulingMetaReducer', () => { metaReducer(testState, action); expectStateUpdate( - expectTagUpdate('TODAY', { taskIds: ['task2', 'parent-task'] }), + expectTagUpdate('TODAY', { taskIds: ['parent-task', 'task2'] }), action, mockReducer, testState, @@ -363,7 +363,7 @@ describe('taskSharedSchedulingMetaReducer', () => { // subtask1 should NOT be added (parent1 is in Today) // subtask2 SHOULD be added (parent2 is not in Today) expectStateUpdate( - expectTagUpdate('TODAY', { taskIds: ['subtask2', 'parent1'] }), + expectTagUpdate('TODAY', { taskIds: ['parent1', 'subtask2'] }), action, mockReducer, testState, diff --git a/src/app/root-store/meta/task-shared-meta-reducers/task-shared-scheduling.reducer.ts b/src/app/root-store/meta/task-shared-meta-reducers/task-shared-scheduling.reducer.ts index a68c755998..cb8881e3d0 100644 --- a/src/app/root-store/meta/task-shared-meta-reducers/task-shared-scheduling.reducer.ts +++ b/src/app/root-store/meta/task-shared-meta-reducers/task-shared-scheduling.reducer.ts @@ -248,7 +248,7 @@ const handlePlanTasksForToday = ( { id: TODAY_TAG.id, changes: { - taskIds: unique([...newTasksForToday, ...todayTag.taskIds]), + taskIds: unique([...todayTag.taskIds, ...newTasksForToday]), }, }, ]); diff --git a/src/app/root-store/meta/task-shared.reducer.spec.ts b/src/app/root-store/meta/task-shared.reducer.spec.ts index 0fdd82b7b2..8ad3880575 100644 --- a/src/app/root-store/meta/task-shared.reducer.spec.ts +++ b/src/app/root-store/meta/task-shared.reducer.spec.ts @@ -1866,7 +1866,7 @@ describe('taskSharedMetaReducer', () => { }); describe('planTasksForToday action', () => { - it('should add new tasks to the top of Today tag', () => { + it('should append new tasks after existing tasks in Today tag', () => { const testState = createStateWithExistingTasks([], [], [], ['existing-task']); const action = TaskSharedActions.planTasksForToday({ taskIds: ['task1', 'task2'], @@ -1874,13 +1874,13 @@ describe('taskSharedMetaReducer', () => { }); expectStateUpdate( - expectTagUpdate('TODAY', { taskIds: ['task1', 'task2', 'existing-task'] }), + expectTagUpdate('TODAY', { taskIds: ['existing-task', 'task1', 'task2'] }), action, testState, ); }); - it('should not add tasks that are already in Today tag', () => { + it('should preserve existing order when adding new tasks', () => { const testState = createStateWithExistingTasks( [], [], @@ -1893,7 +1893,7 @@ describe('taskSharedMetaReducer', () => { }); expectStateUpdate( - expectTagUpdate('TODAY', { taskIds: ['task2', 'task1', 'existing-task'] }), + expectTagUpdate('TODAY', { taskIds: ['task1', 'existing-task', 'task2'] }), action, testState, ); @@ -1907,7 +1907,7 @@ describe('taskSharedMetaReducer', () => { }); expectStateUpdate( - expectTagUpdate('TODAY', { taskIds: ['task2', 'parent-task'] }), + expectTagUpdate('TODAY', { taskIds: ['parent-task', 'task2'] }), action, testState, );