Skip to content

Commit

Permalink
copyCalls as an array of Promises on return
Browse files Browse the repository at this point in the history
  • Loading branch information
jalowe13 committed Nov 21, 2024
1 parent 5fc9b50 commit 71709a7
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions client/src/hooks/datafiles/mutations/useCopy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ function useCopy() {
});

const { mutateAsync } = useMutation({ mutationFn: copyFileUtil });
const copy = async ({
const copy = ({
srcApi,
destApi,
destSystem,
Expand All @@ -99,13 +99,13 @@ function useCopy() {
const filteredSelected = selected
.filter((f: any) => status[f.id] !== 'SUCCESS')
.map((f: any) => ({ ...f, api: srcApi }));
const copyCalls = filteredSelected.map((file: any) => {
const copyCalls: Promise<any>[] = filteredSelected.map((file: any) => {
// Copy File
dispatch({
type: 'DATA_FILES_SET_OPERATION_STATUS_BY_KEY',
payload: { status: 'RUNNING', key: file.id, operation: 'copy' },
});
mutateAsync(
return mutateAsync(
{
api: file.api,
scheme: scheme,
Expand Down Expand Up @@ -135,20 +135,21 @@ function useCopy() {
);
});
// Result
await Promise.all(copyCalls);
dispatch({
type: 'DATA_FILES_TOGGLE_MODAL',
payload: { operation: 'copy', props: {} },
});
dispatch({
type: 'ADD_TOAST',
payload: {
message: `${
copyCalls.length > 1 ? `${copyCalls.length} files` : 'File'
} copied to ${truncateMiddle(`${destPath}`, 20) || '/'}`,
},
Promise.all(copyCalls).then(() => {
dispatch({
type: 'DATA_FILES_TOGGLE_MODAL',
payload: { operation: 'copy', props: {} },
});
dispatch({
type: 'ADD_TOAST',
payload: {
message: `${
copyCalls.length > 1 ? `${copyCalls.length} files` : 'File'
} copied to ${truncateMiddle(`${destPath}`, 20) || '/'}`,
},
});
callback();
});
callback();
};
return { copy, status, setStatus };
}
Expand Down

0 comments on commit 71709a7

Please sign in to comment.