Compare commits

...

2 Commits

Author SHA1 Message Date
Christopher Ng
5f0a45ee1c chore(files): Adapt to moved payload
Signed-off-by: Christopher Ng <chrng8@gmail.com>
2024-09-13 17:31:25 -07:00
Christopher Ng
fb87dc331b chore(files): Provide old node on moved
Signed-off-by: Christopher Ng <chrng8@gmail.com>
2024-09-13 17:31:25 -07:00
3 changed files with 12 additions and 16 deletions

View File

@@ -46,7 +46,6 @@ import { showError, showSuccess } from '@nextcloud/dialogs'
import { emit } from '@nextcloud/event-bus'
import { FileType, NodeStatus } from '@nextcloud/files'
import { translate as t } from '@nextcloud/l10n'
import { dirname } from '@nextcloud/paths'
import { defineComponent, inject } from 'vue'
import NcTextField from '@nextcloud/vue/dist/Components/NcTextField.js'
@@ -244,6 +243,7 @@ export default defineComponent({
return
}
const oldNode = this.source.clone()
const oldName = this.source.basename
const oldEncodedSource = this.source.encodedSource
if (oldName === newName) {
@@ -272,8 +272,8 @@ export default defineComponent({
emit('files:node:updated', this.source)
emit('files:node:renamed', this.source)
emit('files:node:moved', {
node: this.source,
oldSource: `${dirname(this.source.source)}/${oldName}`,
newNode: this.source,
oldNode,
})
showSuccess(t('files', 'Renamed "{oldName}" to "{newName}"', { oldName, newName }))

View File

@@ -16,7 +16,7 @@ declare module '@nextcloud/event-bus' {
'files:node:deleted': Node
'files:node:updated': Node
'files:node:renamed': Node
'files:node:moved': { node: Node, oldSource: string }
'files:node:moved': { newNode: Node, oldNode: Node }
'files:filter:added': IFileListFilter
'files:filter:removed': string

View File

@@ -3,6 +3,7 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
import type { NextcloudEvents } from '@nextcloud/event-bus'
import type { TreeNode } from '../services/FolderTree.ts'
import PQueue from 'p-queue'
@@ -20,7 +21,6 @@ import {
getContents,
getFolderTreeNodes,
getSourceParent,
sourceRoot,
} from '../services/FolderTree.ts'
const isFolderTreeEnabled = loadState('files', 'config', { folder_tree: true }).folder_tree
@@ -94,10 +94,6 @@ const removeFolderView = (folder: Folder) => {
Navigation.remove(viewId)
}
const removeFolderViewSource = (source: string) => {
Navigation.remove(source)
}
const onCreateNode = (node: Node) => {
if (!(node instanceof Folder)) {
return
@@ -112,15 +108,15 @@ const onDeleteNode = (node: Node) => {
removeFolderView(node)
}
const onMoveNode = ({ node, oldSource }) => {
if (!(node instanceof Folder)) {
const onMoveNode = ({ newNode, oldNode }: NextcloudEvents['files:node:moved']) => {
if (!(newNode instanceof Folder) || !(oldNode instanceof Folder)) {
return
}
removeFolderViewSource(oldSource)
registerNodeView(node)
removeFolderView(oldNode)
registerNodeView(newNode)
const newPath = node.source.replace(sourceRoot, '')
const oldPath = oldSource.replace(sourceRoot, '')
const newPath = newNode.path
const oldPath = oldNode.path
const childViews = Navigation.views.filter(view => {
if (!view.params?.dir) {
return false
@@ -132,7 +128,7 @@ const onMoveNode = ({ node, oldSource }) => {
})
for (const view of childViews) {
// @ts-expect-error FIXME Allow setting parent
view.parent = getSourceParent(node.source)
view.parent = getSourceParent(newNode.source)
// @ts-expect-error dir param is defined
view.params.dir = view.params.dir.replace(oldPath, newPath)
}