Skip to content

Commit

Permalink
Added more asynchronous calls to refine process
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeff McMillen authored and Jeff McMillen committed Nov 26, 2024
1 parent ec9c3b3 commit cb014ff
Showing 1 changed file with 19 additions and 32 deletions.
51 changes: 19 additions & 32 deletions client/src/hooks/datafiles/mutations/useMove.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function useMove() {
});
};

const { mutate, isIdle, isSuccess, failureCount } = useMutation({
const { mutateAsync } = useMutation({
mutationFn: moveFileUtil,
});

Expand All @@ -62,7 +62,7 @@ function useMove() {
const filteredSelected = selected.filter(
(f: any) => status[f.id] !== 'SUCCESS'
);
filteredSelected.forEach((file: any) => {
const moveCalls: Promise<any>[] = filteredSelected.forEach((file: any) => {
dispatch({
type: 'DATA_FILES_SET_OPERATION_STATUS_BY_KEY',
payload: {
Expand All @@ -71,10 +71,7 @@ function useMove() {
operation: 'move',
},
});
});

filteredSelected.forEach((file: any) => {
mutate(
return mutateAsync(
{
api: api,
scheme: scheme,
Expand All @@ -93,6 +90,21 @@ function useMove() {
operation: 'move',
},
});
dispatch({
type: 'DATA_FILES_TOGGLE_MODAL',
payload: { operation: 'move', props: {} },
});
dispatch({
type: 'ADD_TOAST',
payload: {
message: `${
filteredSelected.length > 1
? `${filteredSelected.length} files`
: 'File'
} moved to ${truncateMiddle(destPath, 20) || '/'}`,
},
});
callback();
},
onError: () => {
dispatch({
Expand All @@ -103,36 +115,11 @@ function useMove() {
operation: 'move',
},
});
console.log('File error');
},
}
);
});
if (!isIdle && isSuccess && failureCount === 0) {
callback();
dispatch({
type: 'ADD_TOAST',
payload: {
message: `${
filteredSelected.length > 1
? `${filteredSelected.length} files`
: 'File'
} moved to ${truncateMiddle(destPath, 20) || '/'}`,
},
});
dispatch({
type: 'DATA_FILES_SET_OPERATION_STATUS',
payload: { operation: 'move', status: {} },
});
} else {
dispatch({
type: 'DATA_FILES_SET_OPERATION_STATUS',
payload: { operation: 'move', status: 'FAILURE' },
});
}
dispatch({
type: 'DATA_FILES_TOGGLE_MODAL',
payload: { operation: 'move', props: {} },
});
};

return { move, status, setStatus };
Expand Down

0 comments on commit cb014ff

Please sign in to comment.