Skip to content

Commit 737c36d

Browse files
committed
refactor: when you cancel editing a new task in the new homework, we return to the remaining task, if there is one, otherwise to the homework. For an existing task, we keep the previous transition to the initial state
1 parent 72f45ab commit 737c36d

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

hwproj.front/src/store/storeHooks/taskEditorHooks.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,9 +240,15 @@ export const useTaskEditing = () => {
240240
}, [commitTaskRemoval, dispatch]);
241241

242242
const discardTaskDraft = useCallback((task: HomeworkTaskViewModel, homework: HomeworkViewModel, isNewTask: boolean) => {
243+
const draftHomework = draftHomeworks.find(dh => dh.id === task.homeworkId)
244+
const remainingTasks = (draftHomework?.tasks || []).filter(t => t.id !== task.id);
243245
discardTaskDraftByIds(task.id!, task.homeworkId!);
244246
if (isNewTask) {
245-
dispatch(setSelectedItem({ isHomework: true, id: homework.id }));
247+
if (homework.id! < 0 && remainingTasks.length > 0) {
248+
dispatch(setSelectedItem({ isHomework: false, id: remainingTasks[0].id }));
249+
} else {
250+
dispatch(setSelectedItem({ isHomework: true, id: homework.id }));
251+
}
246252
} else {
247253
dispatch(setSelectedItem({ isHomework: false, id: task.id }));
248254
}

0 commit comments

Comments
 (0)