Skip to content

Commit

Permalink
Fix copy regression
Browse files Browse the repository at this point in the history
  • Loading branch information
cshfang committed Nov 27, 2024
1 parent 1437455 commit a6b07bb
Showing 1 changed file with 18 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState } from 'react';
import React, { useRef, useState } from 'react';
import { isFunction } from '@aws-amplify/ui';

import { LocationData } from '../../../actions';
Expand All @@ -18,21 +18,25 @@ export const useCopyView = (options?: UseCopyViewOptions): CopyViewState => {
},
dispatchStoreAction,
] = useStore();
const idLookup = useRef<Record<string, string>>({});

const [destination, setDestination] = useState(location);

const data = React.useMemo(
() =>
fileDataItems?.map((item) => ({
const data = React.useMemo(() => {
idLookup.current = {};
return fileDataItems?.map((item) => {
// generate new `id` on each `destination.key` change to refresh
// task data provided to `useActon`
const id = crypto.randomUUID();
idLookup.current[id] = item.id;
return {
...item,
// generate new `id` on each `destination.key` change to refresh
// task data provided to `useActon`
id: crypto.randomUUID(),
id,
key: `${destination.key}${item.fileKey}`,
sourceKey: item.key,
})),
[destination.key, fileDataItems]
);
};
});
}, [destination.key, fileDataItems]);

const folders = useFolders({ destination, setDestination });

Expand Down Expand Up @@ -68,7 +72,10 @@ export const useCopyView = (options?: UseCopyViewOptions): CopyViewState => {

const onTaskRemove = React.useCallback(
({ data }: Task) => {
dispatchStoreAction({ type: 'REMOVE_LOCATION_ITEM', id: data.id });
dispatchStoreAction({
type: 'REMOVE_LOCATION_ITEM',
id: idLookup.current[data.id],
});
},
[dispatchStoreAction]
);
Expand Down

0 comments on commit a6b07bb

Please sign in to comment.