-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable right-click to delete option in
Explorer
cards (#1341)
* Export `fsPromises.unlink` from `node:fs` for `metafiles/deleteFile` thunk * Added `DeleteFileDialog` modal * Close `DeleteBranchDialog` on successful deletion * Allow right-click on `File` in `Explorer` to initiate `DeleteFileDialog` modal
- Loading branch information
Showing
10 changed files
with
141 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -94,6 +94,7 @@ export { | |
replaceExt, | ||
validateFileName, | ||
writeFileAsync, | ||
unlink, | ||
} from './io'; | ||
export { | ||
clipboard, | ||
|
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 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
78 changes: 78 additions & 0 deletions
78
packages/renderer/src/components/Modal/DeleteFileDialog.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,78 @@ | ||
import { | ||
Box, | ||
Button, | ||
Dialog, | ||
DialogActions, | ||
DialogContent, | ||
DialogContentText, | ||
DialogTitle, | ||
styled, | ||
} from '@mui/material'; | ||
import type {DeleteFileDialog as DeleteFileDialogModal} from '@syn-types/modal'; | ||
import {useAppDispatch, useAppSelector} from '../../store/hooks'; | ||
import {modalRemoved} from '../../store/slices/modals'; | ||
import {deleteFile} from '/@/store/thunks/metafiles'; | ||
import metafileSelectors from '/@/store/selectors/metafiles'; | ||
|
||
const DeleteFileDialog = ({modal}: {modal: DeleteFileDialogModal}) => { | ||
const dispatch = useAppDispatch(); | ||
const metafile = useAppSelector(state => metafileSelectors.selectById(state, modal.metafile)); | ||
|
||
const handleClose = () => dispatch(modalRemoved(modal.id)); | ||
const handleClick = async () => { | ||
if (metafile) { | ||
const result = await dispatch(deleteFile(metafile.id)); | ||
console.log( | ||
result ? `Deleted ${metafile.name} file...` : `Unable to delete ${metafile.name} file...`, | ||
); | ||
if (result) handleClose(); | ||
} | ||
}; | ||
|
||
return ( | ||
<StyledDialog | ||
open | ||
onClose={handleClose} | ||
aria-labelledby="delete-file-dialog-title" | ||
aria-describedby="delete-file-description" | ||
> | ||
<DialogTitle id="delete-file-dialog-title">Delete File</DialogTitle> | ||
<DialogContent sx={{px: 2, pb: 1.5}}> | ||
<DialogContentText id="delete-file-description"> | ||
Are you sure you want to permanently delete the file{' '} | ||
<Box | ||
component="span" | ||
fontWeight="fontWeightBold" | ||
> | ||
{metafile?.name} | ||
</Box>{' '} | ||
? | ||
</DialogContentText> | ||
</DialogContent> | ||
<DialogActions> | ||
<Button | ||
id="cancel-button" | ||
variant="contained" | ||
onClick={handleClose} | ||
> | ||
Cancel | ||
</Button> | ||
<Button | ||
id="delete-file-button" | ||
variant="contained" | ||
onClick={handleClick} | ||
> | ||
Delete | ||
</Button> | ||
</DialogActions> | ||
</StyledDialog> | ||
); | ||
}; | ||
|
||
const StyledDialog = styled(Dialog)(() => ({ | ||
'& .MuiDialog-paper': { | ||
width: 400, | ||
}, | ||
})); | ||
|
||
export default DeleteFileDialog; |
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 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 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