-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
211 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
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
99 changes: 99 additions & 0 deletions
99
src/modules/nextcloud/components/NextcloudDeleteConfirm.jsx
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,99 @@ | ||
import React, { useState } from 'react' | ||
|
||
import { useClient } from 'cozy-client' | ||
import { splitFilename } from 'cozy-client/dist/models/file' | ||
import Buttons from 'cozy-ui/transpiled/react/Buttons' | ||
import { ConfirmDialog } from 'cozy-ui/transpiled/react/CozyDialogs' | ||
import Icon from 'cozy-ui/transpiled/react/Icon' | ||
import ForbiddenIcon from 'cozy-ui/transpiled/react/Icons/Forbidden' | ||
import RestoreIcon from 'cozy-ui/transpiled/react/Icons/Restore' | ||
import List from 'cozy-ui/transpiled/react/List' | ||
import ListItem from 'cozy-ui/transpiled/react/ListItem' | ||
import ListItemIcon from 'cozy-ui/transpiled/react/ListItemIcon' | ||
import ListItemText from 'cozy-ui/transpiled/react/ListItemText' | ||
import { useAlert } from 'cozy-ui/transpiled/react/providers/Alert' | ||
import { useI18n } from 'cozy-ui/transpiled/react/providers/I18n' | ||
|
||
import { getEntriesTypeTranslated } from 'lib/entries' | ||
import { computeNextcloudFolderQueryId } from 'modules/nextcloud/queries' | ||
|
||
const NextcloudDeleteConfirm = ({ files, onClose }) => { | ||
const { t } = useI18n() | ||
const client = useClient() | ||
const { showAlert } = useAlert() | ||
|
||
const [isBusy, setBusy] = useState(false) | ||
|
||
const onDelete = async () => { | ||
try { | ||
setBusy(true) | ||
await client | ||
.collection('io.cozy.remote.nextcloud.files') | ||
.destroyAll(files) | ||
client.resetQuery( | ||
computeNextcloudFolderQueryId({ | ||
sourceAccount: files[0].cozyMetadata.sourceAccount, | ||
path: files[0].parentPath | ||
}) | ||
) | ||
} catch (e) { | ||
showAlert({ | ||
message: t('NextcloudDeleteConfirm.error'), | ||
severity: 'error' | ||
}) | ||
} finally { | ||
onClose() | ||
setBusy(false) | ||
} | ||
} | ||
|
||
const entriesType = getEntriesTypeTranslated(t, files) | ||
return ( | ||
<ConfirmDialog | ||
open={true} | ||
onClose={onClose} | ||
title={t('NextcloudDeleteConfirm.title', { | ||
filename: splitFilename(files[0]).filename, | ||
smart_count: files.length, | ||
type: entriesType | ||
})} | ||
content={ | ||
<List> | ||
<ListItem gutters="disabled" size="small" ellipsis={false}> | ||
<ListItemIcon> | ||
<Icon icon={ForbiddenIcon} /> | ||
</ListItemIcon> | ||
<ListItemText | ||
primary={t(`NextcloudDeleteConfirm.trash`, { | ||
smart_count: files.length | ||
})} | ||
/> | ||
</ListItem> | ||
<ListItem gutters="disabled" size="small" ellipsis={false}> | ||
<ListItemIcon> | ||
<Icon icon={RestoreIcon} /> | ||
</ListItemIcon> | ||
<ListItemText primary={t(`NextcloudDeleteConfirm.restore`)} /> | ||
</ListItem> | ||
</List> | ||
} | ||
actions={ | ||
<> | ||
<Buttons | ||
variant="secondary" | ||
onClick={onClose} | ||
label={t('NextcloudDeleteConfirm.cancel')} | ||
/> | ||
<Buttons | ||
busy={isBusy} | ||
color="error" | ||
label={t('NextcloudDeleteConfirm.delete')} | ||
onClick={onDelete} | ||
/> | ||
</> | ||
} | ||
/> | ||
) | ||
} | ||
|
||
export { NextcloudDeleteConfirm } |
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
42 changes: 42 additions & 0 deletions
42
src/modules/nextcloud/components/actions/deleteNextcloudFile.jsx
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,42 @@ | ||
import React, { forwardRef } from 'react' | ||
|
||
import ActionsMenuItem from 'cozy-ui/transpiled/react/ActionsMenu/ActionsMenuItem' | ||
import Icon from 'cozy-ui/transpiled/react/Icon' | ||
import TrashIcon from 'cozy-ui/transpiled/react/Icons/Trash' | ||
import ListItemIcon from 'cozy-ui/transpiled/react/ListItemIcon' | ||
import ListItemText from 'cozy-ui/transpiled/react/ListItemText' | ||
|
||
import { navigateToModalWithMultipleFile } from 'modules/actions/helpers' | ||
|
||
export const deleteNextcloudFile = ({ t, pathname, navigate, search }) => { | ||
const label = t('SelectionBar.trash') | ||
const icon = TrashIcon | ||
|
||
return { | ||
name: 'deleteNextcloudFile', | ||
label, | ||
icon, | ||
action: files => { | ||
navigateToModalWithMultipleFile({ | ||
files, | ||
pathname, | ||
navigate, | ||
path: 'delete', | ||
search | ||
}) | ||
}, | ||
Component: forwardRef(function DeleteNextcloudFile(props, ref) { | ||
return ( | ||
<ActionsMenuItem {...props} ref={ref}> | ||
<ListItemIcon> | ||
<Icon icon={icon} color="var(--errorColor)" /> | ||
</ListItemIcon> | ||
<ListItemText | ||
primary={label} | ||
primaryTypographyProps={{ color: 'error' }} | ||
/> | ||
</ActionsMenuItem> | ||
) | ||
}) | ||
} | ||
} |
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,50 @@ | ||
import React from 'react' | ||
import { | ||
Navigate, | ||
useLocation, | ||
useParams, | ||
useNavigate, | ||
useSearchParams | ||
} from 'react-router-dom' | ||
|
||
import { hasQueryBeenLoaded } from 'cozy-client' | ||
|
||
import { LoaderModal } from 'components/LoaderModal' | ||
import { getParentPath } from 'lib/path' | ||
import { NextcloudDeleteConfirm } from 'modules/nextcloud/components/NextcloudDeleteConfirm' | ||
import { useNextcloudFolder } from 'modules/nextcloud/hooks/useNextcloudFolder' | ||
import { useNextcloudPath } from 'modules/nextcloud/hooks/useNextcloudPath' | ||
|
||
const NextcloudDeleteView = () => { | ||
const navigate = useNavigate() | ||
const [searchParams] = useSearchParams() | ||
const { sourceAccount } = useParams() | ||
const path = useNextcloudPath() | ||
const { state, pathname } = useLocation() | ||
|
||
const { nextcloudResult } = useNextcloudFolder({ | ||
sourceAccount, | ||
path | ||
}) | ||
|
||
const newPath = getParentPath(pathname) + `?${searchParams.toString()}` | ||
|
||
const handleClose = () => { | ||
navigate(newPath, { replace: true }) | ||
} | ||
|
||
if (!state?.fileIds) { | ||
return <Navigate to={newPath} replace /> | ||
} | ||
|
||
if (hasQueryBeenLoaded(nextcloudResult) && nextcloudResult.data) { | ||
const entries = nextcloudResult.data.filter(({ _id }) => | ||
state.fileIds.includes(_id) | ||
) | ||
return <NextcloudDeleteConfirm files={entries} onClose={handleClose} /> | ||
} | ||
|
||
return <LoaderModal /> | ||
} | ||
|
||
export { NextcloudDeleteView } |