-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(files): properly update paths and folder children on node move
Signed-off-by: skjnldsv <skjnldsv@protonmail.com>
- Loading branch information
Showing
3 changed files
with
114 additions
and
61 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ import Vue from 'vue' | |
|
||
import { fetchNode } from '../services/WebdavClient.ts' | ||
import { usePathsStore } from './paths.ts' | ||
import { dirname } from '@nextcloud/paths' | ||
|
||
export const useFilesStore = function(...args) { | ||
const store = defineStore('files', { | ||
|
@@ -24,14 +25,12 @@ export const useFilesStore = function(...args) { | |
getters: { | ||
/** | ||
Check warning on line 26 in apps/files/src/store/files.ts GitHub Actions / NPM lint
|
||
* Get a file or folder by its source | ||
* @param state | ||
*/ | ||
getNode: (state) => (source: FileSource): Node|undefined => state.files[source], | ||
|
||
/** | ||
* Get a list of files or folders by their IDs | ||
* Note: does not return undefined values | ||
* @param state | ||
*/ | ||
getNodes: (state) => (sources: FileSource[]): Node[] => sources | ||
.map(source => state.files[source]) | ||
|
@@ -41,13 +40,11 @@ export const useFilesStore = function(...args) { | |
* Get files or folders by their file ID | ||
* Multiple nodes can have the same file ID but different sources | ||
* (e.g. in a shared context) | ||
* @param state | ||
*/ | ||
getNodesById: (state) => (fileId: number): Node[] => Object.values(state.files).filter(node => node.fileid === fileId), | ||
|
||
/** | ||
* Get the root folder of a service | ||
* @param state | ||
*/ | ||
getRoot: (state) => (service: Service): Folder|undefined => state.roots[service], | ||
}, | ||
|
@@ -115,6 +112,17 @@ export const useFilesStore = function(...args) { | |
this.updateNodes([node]) | ||
}, | ||
|
||
onMovedNode({ node, oldSource }: { node: Node, oldSource: string }) { | ||
if (!node.fileid) { | ||
logger.error('Trying to update/set a node without fileid', { node }) | ||
return | ||
} | ||
|
||
// Update the path of the node | ||
Vue.delete(this.files, oldSource) | ||
this.updateNodes([node]) | ||
}, | ||
|
||
async onUpdatedNode(node: Node) { | ||
if (!node.fileid) { | ||
logger.error('Trying to update/set a node without fileid', { node }) | ||
|
@@ -147,6 +155,7 @@ export const useFilesStore = function(...args) { | |
subscribe('files:node:created', fileStore.onCreatedNode) | ||
subscribe('files:node:deleted', fileStore.onDeletedNode) | ||
subscribe('files:node:updated', fileStore.onUpdatedNode) | ||
subscribe('files:node:moved', fileStore.onMovedNode) | ||
|
||
fileStore._initialized = true | ||
} | ||
|
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