Skip to content

Commit

Permalink
only delete non-deleted-tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronshiel committed Oct 13, 2023
1 parent fa5c430 commit 9e0970a
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions client/src/hooks/graphql/use-with-upload-status.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export function useWithUploadStatus(
useWithUploadInitStatusActions();
const { newUploadsData } = useWithUploadStatusActions();
const dispatch = useAppDispatch();
const [deletedUploadTasks, setDeletedUploadTasks] = useState<string[]>([]);

const mentorId = getData((state) => state.data?._id);
const CancelToken = axios.CancelToken;
Expand Down Expand Up @@ -84,9 +85,30 @@ export function useWithUploadStatus(
return;
}
uploads.forEach((u) => {
if (areAllTasksDone(u) || isATaskCancelled(u)) {
deleteUploadTask(u.question, accessToken, mentorId).catch((error) => {
console.error(error);
const taskDeletedFromDb = deletedUploadTasks.includes(u.question);
if (!taskDeletedFromDb && (areAllTasksDone(u) || isATaskCancelled(u))) {
deleteUploadTask(u.question, accessToken, mentorId)
.catch((error) => {
console.error(error);
})
.then(() => {
setDeletedUploadTasks((prevState) => {
if (prevState.includes(u.question)) {
return prevState;
}
return [...prevState, u.question];
});
});
} else if (
taskDeletedFromDb &&
!areAllTasksDone(u) &&
!isATaskCancelled(u)
) {
setDeletedUploadTasks((prevState) => {
if (!prevState.includes(u.question)) {
return prevState;
}
return prevState.filter((q) => q !== u.question);
});
}
if (isATaskFailed(u)) {
Expand Down

0 comments on commit 9e0970a

Please sign in to comment.