Skip to content

Commit

Permalink
Refresh move dialog when create a folder
Browse files Browse the repository at this point in the history
  • Loading branch information
Ramon Candel authored and Ramon Candel committed Nov 15, 2023
1 parent 636badf commit a9a0a58
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 35 deletions.
9 changes: 8 additions & 1 deletion src/app/drive/components/DriveExplorer/DriveExplorer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,14 @@ const DriveExplorer = (props: DriveExplorerProps): JSX.Element => {
}}
/>
<NameCollisionContainer />
<MoveItemsDialog items={[...items]} onItemsMoved={onItemsMoved} isTrash={isTrash} />
<MoveItemsDialog
items={[...items]}
onItemsMoved={() => {
dispatch(fetchSortedFolderContentThunk(currentFolderId));
onItemsMoved?.();
}}
isTrash={isTrash}
/>
<ClearTrashDialog onItemsDeleted={onItemsDeleted} />
<EditFolderNameDialog />
<UploadItemsFailsDialog />
Expand Down
73 changes: 39 additions & 34 deletions src/app/drive/components/MoveItemsDialog/MoveItemsDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,41 +85,43 @@ const MoveItemsDialog = (props: MoveItemsDialogProps): JSX.Element => {
dispatch(fetchDialogContentThunk(folderId))
.unwrap()
.then(() => {
databaseService.get(DatabaseCollection.MoveDialogLevels, folderId).then((items) => {
setCurrentFolderId(folderId);
setCurrentFolderName(name);
setDestinationId(folderId);
getDatabaseItems(folderId, name);
});
};

const files: DriveItemData[] = [];
const folders = items?.filter((i) => {
if (!i.isFolder) files.push(i);
return i.isFolder;
});
const getDatabaseItems = (folderId: number, name: string) => {
databaseService.get(DatabaseCollection.MoveDialogLevels, folderId).then((items) => {
setCurrentFolderId(folderId);
setCurrentFolderName(name);
setDestinationId(folderId);

let auxCurrentPaths: FolderPathDialog[] = [...currentNamePaths];
const currentIndex = auxCurrentPaths.findIndex((i) => {
return i.id === folderId;
});
if (currentIndex > -1) {
auxCurrentPaths = auxCurrentPaths.slice(0, currentIndex + 1);
dispatch(storageActions.popNamePathDialogUpTo({ id: folderId, name: name }));
} else {
auxCurrentPaths.push({ id: folderId, name: name });
dispatch(storageActions.pushNamePathDialog({ id: folderId, name: name }));
}
const folders = items?.filter((i) => {
return i.isFolder;
});

setCurrentNamePaths(auxCurrentPaths);
if (folders) {
const unselectedFolders = folders.filter((item) => item.id != itemsToMove[0].id);
setShownFolders(unselectedFolders);
} else {
setShownFolders([]);
setDestinationId(folderId);
setCurrentFolderId(folderId);
setCurrentFolderName(name);
}
});
let auxCurrentPaths: FolderPathDialog[] = [...currentNamePaths];
const currentIndex = auxCurrentPaths.findIndex((i) => {
return i.id === folderId;
});
if (currentIndex > -1) {
auxCurrentPaths = auxCurrentPaths.slice(0, currentIndex + 1);
dispatch(storageActions.popNamePathDialogUpTo({ id: folderId, name: name }));
} else {
auxCurrentPaths.push({ id: folderId, name: name });
dispatch(storageActions.pushNamePathDialog({ id: folderId, name: name }));
}

setCurrentNamePaths(auxCurrentPaths);
if (folders) {
const unselectedFolders = folders.filter((item) => item.id != itemsToMove[0].id);
setShownFolders(unselectedFolders);
} else {
setShownFolders([]);
setDestinationId(folderId);
setCurrentFolderId(folderId);
setCurrentFolderName(name);
}
});
};

const onFolderClicked = (folderId: number, name?: string): void => {
Expand Down Expand Up @@ -161,15 +163,15 @@ const MoveItemsDialog = (props: MoveItemsDialogProps): JSX.Element => {
await restoreItemsFromTrash(itemsToMove, destinationFolderId, translate as TFunction, props.isTrash);
}

props.onItemsMoved && props.onItemsMoved();
props.onItemsMoved?.();

setIsLoading(false);
onClose();
setDriveBreadcrumb();
} catch (err: unknown) {
const castedError = errorService.castError(err);
errorService.reportError(castedError);
setIsLoading(false);
console.log(castedError.message);
}
};

Expand All @@ -186,7 +188,10 @@ const MoveItemsDialog = (props: MoveItemsDialogProps): JSX.Element => {
</div>

{/* Create folder dialog */}
<CreateFolderDialog currentFolderId={currentFolderId} />
<CreateFolderDialog
currentFolderId={currentFolderId}
onFolderCreated={() => setTimeout(() => onShowFolderContentClicked(currentFolderId, currentFolderName), 500)}
/>

{/* Folder list */}
<div className="flex flex-col">
Expand Down

0 comments on commit a9a0a58

Please sign in to comment.