Skip to content

Commit 9c20251

Browse files
committed
feat: 태스크 우선순위 변경 API 연결
1 parent 1ddcf27 commit 9c20251

File tree

2 files changed

+108
-4
lines changed

2 files changed

+108
-4
lines changed

frontend/src/hooks/pages/backlog/useBacklogSocket.ts

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ const useBacklogSocket = (socket: Socket) => {
7878
if (content.epicId) {
7979
setBacklog((prevBacklog) => {
8080
let targetStory: StoryDTO | null = null;
81-
backlog.epicList.some((epic) => {
81+
prevBacklog.epicList.some((epic) => {
8282
const foundStory = epic.storyList.find(
8383
(story) => story.id === content.id
8484
);
@@ -168,6 +168,56 @@ const useBacklogSocket = (socket: Socket) => {
168168
});
169169
break;
170170
case BacklogSocketTaskAction.UPDATE:
171+
if (content.storyId) {
172+
setBacklog((prevBacklog) => {
173+
let targetTask: TaskDTO | null = null;
174+
prevBacklog.epicList.some((epic) => {
175+
epic.storyList.some((story) => {
176+
const foundTask = story.taskList.find(
177+
(task) => task.id === content.id
178+
);
179+
180+
if (foundTask) {
181+
targetTask = { ...foundTask };
182+
return true;
183+
}
184+
185+
return false;
186+
});
187+
188+
if (targetTask) {
189+
return true;
190+
}
191+
192+
return false;
193+
});
194+
195+
if (!targetTask) {
196+
return prevBacklog;
197+
}
198+
199+
const newEpicList = prevBacklog.epicList.map((epic) => {
200+
const newStoryList = epic.storyList.map((story) => {
201+
const newTaskList = story.taskList.filter(
202+
(task) => task.id !== content.id
203+
);
204+
205+
if (story.id === content.storyId) {
206+
newTaskList.push({
207+
...targetTask,
208+
...content,
209+
} as TaskDTO);
210+
}
211+
return { ...story, taskList: newTaskList };
212+
});
213+
214+
return { ...epic, storyList: newStoryList };
215+
});
216+
return { epicList: newEpicList };
217+
});
218+
break;
219+
}
220+
171221
setBacklog((prevBacklog) => {
172222
const newEpicList = prevBacklog.epicList.map((epic) => {
173223
const newStoryList = epic.storyList.map((story) => {

frontend/src/pages/backlog/UnfinishedStoryPage.tsx

Lines changed: 57 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,14 @@ import useStoryEmitEvent from "../../hooks/pages/backlog/useStoryEmitEvent";
1010
import changeEpicListToStoryList from "../../utils/changeEpicListToStoryList";
1111
import getDragElementIndex from "../../utils/getDragElementIndex";
1212
import { BacklogSocketData } from "../../types/common/backlog";
13-
import { BacklogDTO } from "../../types/DTO/backlogDTO";
13+
import { BacklogDTO, TaskDTO } from "../../types/DTO/backlogDTO";
1414
import StoryDragContainer from "../../components/backlog/StoryDragContainer";
1515
import TaskBlock from "../../components/backlog/TaskBlock";
1616
import TaskDragContainer from "../../components/backlog/TaskDragContainer";
1717
import TaskContainer from "../../components/backlog/TaskContainer";
1818
import TaskHeader from "../../components/backlog/TaskHeader";
1919
import TaskCreateBlock from "../../components/backlog/TaskCreateBlock";
20+
import useTaskEmitEvent from "../../hooks/pages/backlog/useTaskEmitEvent";
2021

2122
const UnfinishedStoryPage = () => {
2223
const { socket, backlog }: { socket: Socket; backlog: BacklogDTO } =
@@ -37,6 +38,20 @@ const UnfinishedStoryPage = () => {
3738
const storyList = useMemo(
3839
() =>
3940
changeEpicListToStoryList(backlog.epicList)
41+
.filter(({ status }) => status !== "완료")
42+
.map((story) => {
43+
const newTaskList = story.taskList.slice();
44+
newTaskList.sort((taskA, taskB) => {
45+
if (taskA.rankValue < taskB.rankValue) {
46+
return -1;
47+
}
48+
if (taskA.rankValue > taskB.rankValue) {
49+
return 1;
50+
}
51+
return 0;
52+
});
53+
return { ...story, taskList: newTaskList };
54+
})
4055
.sort((storyA, storyB) => {
4156
if (storyA.rankValue < storyB.rankValue) {
4257
return -1;
@@ -45,8 +60,7 @@ const UnfinishedStoryPage = () => {
4560
return 1;
4661
}
4762
return 0;
48-
})
49-
.filter(({ status }) => status !== "완료"),
63+
}),
5064
[backlog.epicList]
5165
);
5266
const epicCategoryList = useMemo(
@@ -60,6 +74,7 @@ const UnfinishedStoryPage = () => {
6074
[backlog.epicList]
6175
);
6276
const { emitStoryUpdateEvent } = useStoryEmitEvent(socket);
77+
const { emitTaskUpdateEvent } = useTaskEmitEvent(socket);
6378

6479
const setStoryComponentRef = (index: number) => (element: HTMLDivElement) => {
6580
storyComponentRefList.current[index] = element;
@@ -181,6 +196,45 @@ const UnfinishedStoryPage = () => {
181196
};
182197

183198
const handleTaskDragEnd = () => {
199+
const { storyId, taskIndex } = taskElementIndex;
200+
const taskList = storyList.find(({ id }) => id === storyId)
201+
?.taskList as TaskDTO[];
202+
const targetIndex = taskList?.findIndex(({ id }) => id === draggingTaskId);
203+
204+
let rankValue;
205+
206+
if (taskIndex === targetIndex) {
207+
setDraggingTaskId(undefined);
208+
setTaskElementIndex({ storyId: undefined, taskIndex: undefined });
209+
return;
210+
}
211+
212+
if (taskIndex === 0 && !taskList.length) {
213+
console.log("아무 것도 없을 때");
214+
215+
rankValue = LexoRank.middle().toString();
216+
} else if (taskIndex === 0) {
217+
const firstTaskRank = taskList[0].rankValue;
218+
rankValue = LexoRank.parse(firstTaskRank).genPrev().toString();
219+
} else if (taskIndex === taskList.length) {
220+
const lastTaskRank = taskList[taskList.length - 1].rankValue;
221+
rankValue = LexoRank.parse(lastTaskRank).genNext().toString();
222+
} else {
223+
const prevTaskRank = LexoRank.parse(
224+
taskList[(taskIndex as number) - 1].rankValue
225+
);
226+
const nextTaskRank = LexoRank.parse(
227+
taskList[taskIndex as number].rankValue
228+
);
229+
rankValue = prevTaskRank.between(nextTaskRank).toString();
230+
}
231+
232+
emitTaskUpdateEvent({
233+
id: draggingTaskId as number,
234+
storyId,
235+
rankValue,
236+
});
237+
184238
setDraggingTaskId(undefined);
185239
setTaskElementIndex({ storyId: undefined, taskIndex: undefined });
186240
};

0 commit comments

Comments
 (0)