aboutsummaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorFerdinand Thiessen <opensource@fthiessen.de>2024-04-17 17:03:44 +0200
committerFerdinand Thiessen <opensource@fthiessen.de>2024-06-04 12:40:48 +0200
commit91ac7dfb7cbe0b65af3f3aa528d61f2fa6beb5a0 (patch)
treea0d882f5eef08c6ffe35d1c84968abea737f141b /apps
parentc1fdd9031ce8cf8e737e6091da723f3446c1b713 (diff)
downloadnextcloud-server-91ac7dfb7cbe0b65af3f3aa528d61f2fa6beb5a0.tar.gz
nextcloud-server-91ac7dfb7cbe0b65af3f3aa528d61f2fa6beb5a0.zip
fix(files): Update current fileid in route if that node was deleted
We do not change the view to the trash bin but stay in the current view, so we need to update the current fileid on the route if that was deleted. Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
Diffstat (limited to 'apps')
-rw-r--r--apps/files/src/actions/deleteAction.ts5
-rw-r--r--apps/files/src/store/paths.ts2
-rw-r--r--apps/files/src/views/FilesList.vue36
3 files changed, 40 insertions, 3 deletions
diff --git a/apps/files/src/actions/deleteAction.ts b/apps/files/src/actions/deleteAction.ts
index 6b4cb927b1c..23106a5d15f 100644
--- a/apps/files/src/actions/deleteAction.ts
+++ b/apps/files/src/actions/deleteAction.ts
@@ -126,14 +126,15 @@ export const action = new FileAction({
.every(permission => (permission & Permission.DELETE) !== 0)
},
- async exec(node: Node) {
+ async exec(node: Node, view: View, dir: string) {
try {
await axios.delete(node.encodedSource)
// 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.
+ // and changing the view will trigger a reload anyway.
emit('files:node:deleted', node)
+
return true
} catch (error) {
logger.error('Error while deleting a file', { error, source: node.source, node })
diff --git a/apps/files/src/store/paths.ts b/apps/files/src/store/paths.ts
index 5d5d459f309..23fd69a91e6 100644
--- a/apps/files/src/store/paths.ts
+++ b/apps/files/src/store/paths.ts
@@ -12,7 +12,7 @@ import logger from '../logger'
import { useFilesStore } from './files'
export const usePathsStore = function(...args) {
- const files = useFilesStore()
+ const files = useFilesStore(...args)
const store = defineStore('paths', {
state: () => ({
diff --git a/apps/files/src/views/FilesList.vue b/apps/files/src/views/FilesList.vue
index 17903c5473f..e075faa9015 100644
--- a/apps/files/src/views/FilesList.vue
+++ b/apps/files/src/views/FilesList.vue
@@ -244,6 +244,14 @@ export default defineComponent({
},
/**
+ * The current file id
+ */
+ fileId(): number | null {
+ const number = Number.parseInt(this.$route?.params.fileid ?? '')
+ return Number.isNaN(number) ? null : number
+ },
+
+ /**
* The current folder.
*/
currentFolder(): Folder | undefined {
@@ -460,6 +468,8 @@ export default defineComponent({
mounted() {
this.fetchContent()
+
+ subscribe('files:node:deleted', this.onNodeDeleted)
subscribe('files:node:updated', this.onUpdatedNode)
subscribe('nextcloud:unified-search.search', this.onSearch)
subscribe('nextcloud:unified-search.reset', this.onSearch)
@@ -469,6 +479,7 @@ export default defineComponent({
},
unmounted() {
+ unsubscribe('files:node:deleted', this.onNodeDeleted)
unsubscribe('files:node:updated', this.onUpdatedNode)
unsubscribe('nextcloud:unified-search.search', this.onSearch)
unsubscribe('nextcloud:unified-search.reset', this.onSearch)
@@ -546,6 +557,31 @@ export default defineComponent({
},
/**
+ * Handle the node deleted event to reset open file
+ * @param node The deleted node
+ */
+ onNodeDeleted(node: Node) {
+ if (node.fileid && node.fileid === this.fileId) {
+ if (node.fileid === this.currentFolder?.fileid) {
+ // Handle the edge case that the current directory is deleted
+ // in this case we neeed to keept the current view but move to the parent directory
+ window.OCP.Files.Router.goToRoute(
+ null,
+ { view: this.$route.params.view },
+ { dir: this.currentFolder?.dirname ?? '/' },
+ )
+ } else {
+ // If the currently active file is deleted we need to remove the fileid and possible the `openfile` query
+ window.OCP.Files.Router.goToRoute(
+ null,
+ { ...this.$route.params, fileid: undefined },
+ { ...this.$route.query, openfile: undefined },
+ )
+ }
+ }
+ },
+
+ /**
* The upload manager have finished handling the queue
* @param {Upload} upload the uploaded data
*/