-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create only one element to delete files and folders
- Loading branch information
Showing
6 changed files
with
63 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
55 changes: 55 additions & 0 deletions
55
client/components/Application/Dialogs/DeleteFilesFolders.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import ConfirmDialog from '../../Parts/Dialogs/Confirm' | ||
import { selectors, useStore } from '../store' | ||
|
||
export default function DeleteFilesFoldersDialog() { | ||
const path = useStore((state) => state.path) | ||
const selectedMultiplePaths = useStore((state) => state.selectedMultiplePaths) | ||
const files = useStore((state) => state.files) | ||
const isFolder = useStore(selectors.isFolder) | ||
|
||
// const selectedElements = files.filter((file) => { | ||
// if( selectedMultiplePaths?.includes(file.path) && file.type === 'folder' ) return file | ||
// else return | ||
// }) | ||
|
||
const selectedFolders = files | ||
.filter((file) => { | ||
return selectedMultiplePaths?.includes(file.path) && file.type === 'folder' | ||
}) | ||
.map((file) => file.path) | ||
|
||
const selectedFiles = files | ||
.filter((file) => { | ||
return selectedMultiplePaths?.includes(file.path) && file.type !== 'folder' | ||
}) | ||
.map((file) => file.path) | ||
|
||
const deleteFiles = useStore((state) => state.deleteFiles) | ||
const deleteFolders = useStore((state) => state.deleteFolders) | ||
const updateState = useStore((state) => state.updateState) | ||
if (!path) return null | ||
|
||
return ( | ||
<ConfirmDialog | ||
open={true} | ||
title="Delete File" | ||
description={ | ||
selectedMultiplePaths | ||
? 'Are you sure you want to delete these elements?' | ||
: `Are you sure you want to delete this ${isFolder ? 'folder' : 'file'}?` | ||
} | ||
label="Yes" | ||
cancelLabel="No" | ||
onCancel={() => updateState({ dialog: undefined })} | ||
onConfirm={async () => { | ||
if (selectedMultiplePaths) { | ||
if (selectedFolders.length > 0) await deleteFolders(selectedFolders) | ||
if (selectedFiles.length > 0) await deleteFiles(selectedFiles) | ||
} | ||
// is only one selected file | ||
else isFolder ? await deleteFolders([path]) : await deleteFiles([path]) | ||
updateState({ dialog: undefined }) | ||
}} | ||
/> | ||
) | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters