From f28944e23f96dd756cba3739e99c2fba57e81f1f Mon Sep 17 00:00:00 2001 From: John Molakvoæ Date: Sat, 25 Mar 2023 11:51:11 +0100 Subject: feat(files): propagate restore and delete events MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: John Molakvoæ --- apps/files/src/actions/deleteAction.ts | 15 ++- apps/files/src/components/FileEntry.vue | 10 ++ apps/files/src/components/FilesListVirtual.vue | 14 +-- apps/files/src/store/files.ts | 115 +++++++++++++++-------- apps/files/src/store/paths.ts | 56 +++++++---- apps/files/src/store/sorting.ts | 13 +-- apps/files/src/types.ts | 12 +++ apps/files/src/views/FilesList.vue | 4 +- apps/files_trashbin/src/actions/restoreAction.ts | 14 ++- 9 files changed, 166 insertions(+), 87 deletions(-) diff --git a/apps/files/src/actions/deleteAction.ts b/apps/files/src/actions/deleteAction.ts index cd12c15ba10..acf855c8d15 100644 --- a/apps/files/src/actions/deleteAction.ts +++ b/apps/files/src/actions/deleteAction.ts @@ -19,28 +19,33 @@ * along with this program. If not, see . * */ -import { registerFileAction, Permission, FileAction } from '@nextcloud/files' +import { registerFileAction, Permission, FileAction, Node } from '@nextcloud/files' import { translate as t } from '@nextcloud/l10n' import axios from '@nextcloud/axios' import TrashCan from '@mdi/svg/svg/trash-can.svg?raw' -import logger from '../logger' +import { emit } from '@nextcloud/event-bus' registerFileAction(new FileAction({ id: 'delete', - displayName(nodes, view) { + displayName(nodes: Node[], view) { return view.id === 'trashbin' ? t('files_trashbin', 'Delete permanently') : t('files', 'Delete') }, iconSvgInline: () => TrashCan, - enabled(nodes) { + enabled(nodes: Node[]) { return nodes.length > 0 && nodes .map(node => node.permissions) .every(permission => (permission & Permission.DELETE) !== 0) }, - async exec(node) { + async exec(node: Node) { // No try...catch here, let the files app handle the error await axios.delete(node.source) + + // Let's delete even if it's moved to the trashbin + // since it has been removed from the current view + // and changing the view will trigger a reload anyway. + emit('files:file:deleted', node) return true }, order: 100, diff --git a/apps/files/src/components/FileEntry.vue b/apps/files/src/components/FileEntry.vue index 343d24f05e1..4d7582216f4 100644 --- a/apps/files/src/components/FileEntry.vue +++ b/apps/files/src/components/FileEntry.vue @@ -431,6 +431,16 @@ export default Vue.extend({