Skip to content

Commit

Permalink
Refoctor: #33 할일 변경 함수 구조분해할당 삭제
Browse files Browse the repository at this point in the history
  • Loading branch information
Seok93 committed Jul 6, 2024
1 parent e741b3c commit 52f0fe6
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/pages/project/KanbanPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,18 @@ import { parsePrefixId } from '@utils/converter';
import { TASK_DUMMY } from '@mocks/mockData';
import type { Task, TaskWithStatus } from '@/types/TaskType';

// ToDo: 상태 DnD와 할일 DnD 로직 통합 가능한가 생각해보기
function createChangedStatus(statusTasks: TaskWithStatus[], dropResult: DropResult) {
const { source, destination } = dropResult;

if (!destination) throw Error('Error: DnD destination is null');

const newStatusTasks = deepClone(statusTasks);
const stausTask = newStatusTasks[source.index];

newStatusTasks.splice(source.index, 1);
newStatusTasks.splice(destination.index, 0, stausTask);
newStatusTasks.forEach((status, index) => (status.order = index + 1));

return newStatusTasks;
}

Expand All @@ -32,10 +33,10 @@ function createChangedTasks(statusTasks: TaskWithStatus[], dropResult: DropResul
const taskId = Number(parsePrefixId(draggableId));

const newStatusTasks = deepClone(statusTasks);
const { tasks: sourceTasks } = newStatusTasks.find((data) => data.statusId === sourceStatusId)! as TaskWithStatus;
const { tasks: destinationTasks } = isSameStatus
? { tasks: sourceTasks }
: (newStatusTasks.find((data) => data.statusId === destinationStatusId)! as TaskWithStatus);
const sourceTasks = newStatusTasks.find((data) => data.statusId === sourceStatusId)!.tasks;
const destinationTasks = isSameStatus
? sourceTasks
: newStatusTasks.find((data) => data.statusId === destinationStatusId)!.tasks;
const task = sourceTasks.find((data) => data.taskId === taskId)! as Task;

sourceTasks.splice(source.index, 1);
Expand Down

0 comments on commit 52f0fe6

Please sign in to comment.