Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
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 <[email protected]>
  • Loading branch information
susnux committed Jun 4, 2024
commit 91ac7dfb7cbe0b65af3f3aa528d61f2fa6beb5a0
5 changes: 3 additions & 2 deletions apps/files/src/actions/deleteAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
Expand Down
2 changes: 1 addition & 1 deletion apps/files/src/store/paths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: () => ({
Expand Down
36 changes: 36 additions & 0 deletions apps/files/src/views/FilesList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,14 @@ export default defineComponent({
return (this.$route?.query?.dir?.toString() || '/').replace(/^(.+)\/$/, '$1')
},

/**
* The current file id
*/
fileId(): number | null {
const number = Number.parseInt(this.$route?.params.fileid ?? '')
return Number.isNaN(number) ? null : number
},

/**
* The current folder.
*/
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -545,6 +556,31 @@ export default defineComponent({
return this.filesStore.getNode(fileId)
},

/**
* 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
Expand Down