Skip to content

Commit

Permalink
fix: 드래그앤드롭 상태관리부분 수정(상태 수정 부분 제거 시 같은 공간에서 드래그앤드롭에 대한 서버 오류 전송)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kjiw0n committed Jul 18, 2024
1 parent e60c71d commit 1c2cf52
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/pages/Today.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function Today() {
// Task 목록 Get
const { data: stagingData, isError: isStagingError } = useGetTasks({ isTotal, sortOrder });
const { data: targetData, isError: isTargetError } = useGetTasks({ targetDate });
const { mutate } = useUpdateTaskStatus();
const { mutate, queryClient } = useUpdateTaskStatus();

console.log('targetData', targetData);

Expand Down Expand Up @@ -75,6 +75,19 @@ function Today() {
const [movedTask] = sourceTasks.splice(source.index, 1);
destinationTasks.splice(destination.index, 0, movedTask);

// 상태 업데이트
if (source.droppableId === 'target') {
queryClient.setQueryData(['tasks'], {
target: { ...targetData, data: { ...targetData.data, tasks: sourceTasks } },
staging: { ...stagingData, data: { ...stagingData.data, tasks: destinationTasks } },
});
} else {
queryClient.setQueryData(['tasks'], {
target: { ...targetData, data: { ...targetData.data, tasks: destinationTasks } },
staging: { ...stagingData, data: { ...stagingData.data, tasks: sourceTasks } },
});
}

// API 호출
if (destination.droppableId === 'target') {
mutate({
Expand Down

0 comments on commit 1c2cf52

Please sign in to comment.