aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files
diff options
context:
space:
mode:
authorFerdinand Thiessen <opensource@fthiessen.de>2025-01-16 23:25:59 +0100
committerFerdinand Thiessen <opensource@fthiessen.de>2025-01-21 17:55:53 +0100
commit344c8a409c733068e7d22b5b182f30f5defda624 (patch)
tree98c0f4e21a4d69b0b831e4d59968d0bfb2b5b565 /apps/files
parent0a3cf3caf3e53bd24c62f3ba347fda337c59c1a1 (diff)
downloadnextcloud-server-344c8a409c733068e7d22b5b182f30f5defda624.tar.gz
nextcloud-server-344c8a409c733068e7d22b5b182f30f5defda624.zip
fix(files): Ensure favorites set in sidebar work
When marking a file as favorite from within the sidebar make sure it really works, this fixes two issues: 1. The source needs to be the plain source not URL encoded, as otherwise the source of the node would be encoded twice (and show with encoding in the navigation) 2. The store should also listen for the update events as the sidebar has no access to the real node to update it, instead the store should - as long as we only have the legacy sidebar - update the node when added or removed as favorite. Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
Diffstat (limited to 'apps/files')
-rw-r--r--apps/files/src/store/files.ts18
-rw-r--r--apps/files/src/views/Sidebar.vue20
-rw-r--r--apps/files/src/views/favorites.ts4
3 files changed, 32 insertions, 10 deletions
diff --git a/apps/files/src/store/files.ts b/apps/files/src/store/files.ts
index f18bee42550..08b5d0757d3 100644
--- a/apps/files/src/store/files.ts
+++ b/apps/files/src/store/files.ts
@@ -149,6 +149,21 @@ export const useFilesStore = function(...args) {
// Otherwise, it means we receive an event for a node that is not in the store
fetchNode(node).then(n => this.updateNodes([n]))
},
+
+ // Handlers for legacy sidebar (no real nodes support)
+ onAddFavorite(node: Node) {
+ const ourNode = this.getNode(node.source)
+ if (ourNode) {
+ Vue.set(ourNode.attributes, 'favorite', 1)
+ }
+ },
+
+ onRemoveFavorite(node: Node) {
+ const ourNode = this.getNode(node.source)
+ if (ourNode) {
+ Vue.set(ourNode.attributes, 'favorite', 0)
+ }
+ },
},
})
@@ -159,6 +174,9 @@ export const useFilesStore = function(...args) {
subscribe('files:node:deleted', fileStore.onDeletedNode)
subscribe('files:node:updated', fileStore.onUpdatedNode)
subscribe('files:node:moved', fileStore.onMovedNode)
+ // legacy sidebar
+ subscribe('files:favorites:added', fileStore.onAddFavorite)
+ subscribe('files:favorites:removed', fileStore.onRemoveFavorite)
fileStore._initialized = true
}
diff --git a/apps/files/src/views/Sidebar.vue b/apps/files/src/views/Sidebar.vue
index 196d64990a6..5418d36297b 100644
--- a/apps/files/src/views/Sidebar.vue
+++ b/apps/files/src/views/Sidebar.vue
@@ -404,10 +404,10 @@ export default {
},
/**
- * Toggle favourite state
+ * Toggle favorite state
* TODO: better implementation
*
- * @param {boolean} state favourited or not
+ * @param {boolean} state is favorite or not
*/
async toggleStarred(state) {
try {
@@ -430,17 +430,21 @@ export default {
*/
const isDir = this.fileInfo.type === 'dir'
const Node = isDir ? Folder : File
- emit(state ? 'files:favorites:added' : 'files:favorites:removed', new Node({
+ const node = new Node({
fileid: this.fileInfo.id,
- source: this.davPath,
- root: `/files/${getCurrentUser().uid}`,
+ source: `${davRemoteURL}${davRootPath}${this.file}`,
+ root: davRootPath,
mime: isDir ? undefined : this.fileInfo.mimetype,
- }))
+ attributes: {
+ favorite: 1,
+ },
+ })
+ emit(state ? 'files:favorites:added' : 'files:favorites:removed', node)
this.fileInfo.isFavourited = state
} catch (error) {
- showError(t('files', 'Unable to change the favourite state of the file'))
- logger.error('Unable to change favourite state', { error })
+ showError(t('files', 'Unable to change the favorite state of the file'))
+ logger.error('Unable to change favorite state', { error })
}
},
diff --git a/apps/files/src/views/favorites.ts b/apps/files/src/views/favorites.ts
index 8d561b4f5b8..cadc7704e14 100644
--- a/apps/files/src/views/favorites.ts
+++ b/apps/files/src/views/favorites.ts
@@ -65,7 +65,7 @@ export const registerFavoritesView = async () => {
favoriteFoldersViews.forEach(view => Navigation.register(view))
/**
- * Update favourites navigation when a new folder is added
+ * Update favorites navigation when a new folder is added
*/
subscribe('files:favorites:added', (node: Node) => {
if (node.type !== FileType.Folder) {
@@ -99,7 +99,7 @@ export const registerFavoritesView = async () => {
})
/**
- * Update favourites navigation when a folder is renamed
+ * Update favorites navigation when a folder is renamed
*/
subscribe('files:node:renamed', (node: Node) => {
if (node.type !== FileType.Folder) {