aboutsummaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorJohn Molakvoæ <skjnldsv@protonmail.com>2023-04-27 10:40:19 +0200
committerJohn Molakvoæ <skjnldsv@protonmail.com>2023-07-05 16:20:33 +0200
commitf029c8bd82e94479fef047f1147d025a523bcba7 (patch)
tree0e2f9b537fd1a7adacd345a21f1b7ddb705ac6d2 /apps
parent0984970cd8759ae2dcd7dfdfe41d5816bf3c2948 (diff)
downloadnextcloud-server-f029c8bd82e94479fef047f1147d025a523bcba7.tar.gz
nextcloud-server-f029c8bd82e94479fef047f1147d025a523bcba7.zip
fix(files): fix favorites legacy to vue handling and sorting
Signed-off-by: John Molakvoæ <skjnldsv@protonmail.com>
Diffstat (limited to 'apps')
-rw-r--r--apps/files/js/tagsplugin.js12
-rw-r--r--apps/files/src/views/favorites.ts95
2 files changed, 77 insertions, 30 deletions
diff --git a/apps/files/js/tagsplugin.js b/apps/files/js/tagsplugin.js
index 6759aa7002b..cda188803db 100644
--- a/apps/files/js/tagsplugin.js
+++ b/apps/files/js/tagsplugin.js
@@ -194,13 +194,25 @@
tags = tags.split('|');
tags = _.without(tags, '');
var isFavorite = tags.indexOf(OC.TAG_FAVORITE) >= 0;
+
+ // Fake Node object for vue compatibility
+ const node = {
+ type: 'folder',
+ path: (dir + '/' + fileName).replace(/\/\/+/g, '/'),
+ root: '/files/' + OC.getCurrentUser().uid
+ }
+
if (isFavorite) {
// remove tag from list
tags = _.without(tags, OC.TAG_FAVORITE);
removeFavoriteFromList(dir + '/' + fileName);
+ // vue compatibility
+ window._nc_event_bus.emit('files:favorites:removed', node)
} else {
tags.push(OC.TAG_FAVORITE);
addFavoriteToList(dir + '/' + fileName);
+ // vue compatibility
+ window._nc_event_bus.emit('files:favorites:added', node)
}
// pre-toggle the star
diff --git a/apps/files/src/views/favorites.ts b/apps/files/src/views/favorites.ts
index 731fbe14db7..8267bf266e8 100644
--- a/apps/files/src/views/favorites.ts
+++ b/apps/files/src/views/favorites.ts
@@ -21,7 +21,7 @@
*/
import type NavigationService from '../services/Navigation.ts'
import type { Navigation } from '../services/Navigation.ts'
-import { translate as t } from '@nextcloud/l10n'
+import { getLanguage, translate as t } from '@nextcloud/l10n'
import StarSvg from '@mdi/svg/svg/star.svg?raw'
import FolderSvg from '@mdi/svg/svg/folder.svg?raw'
@@ -33,7 +33,32 @@ import { subscribe } from '@nextcloud/event-bus'
import { Node, FileType } from '@nextcloud/files'
import logger from '../logger'
-const favoriteFolders = loadState('files', 'favoriteFolders', [])
+const generateFolderView = function(folder: string, index = 0): Navigation {
+ return {
+ id: generateIdFromPath(folder),
+ name: basename(folder),
+
+ icon: FolderSvg,
+ order: index,
+ params: {
+ dir: folder,
+ view: 'favorites',
+ },
+
+ parent: 'favorites',
+
+ columns: [],
+
+ getContents,
+ } as Navigation
+}
+
+const generateIdFromPath = function(path: string): string {
+ return `favorite-${hashCode(path)}`
+}
+
+const favoriteFolders = loadState('files', 'favoriteFolders', []) as string[]
+const favoriteFoldersViews = favoriteFolders.map((folder, index) => generateFolderView(folder, index))
export default () => {
const Navigation = window.OCP.Files.Navigation as NavigationService
@@ -50,9 +75,7 @@ export default () => {
getContents,
} as Navigation)
- favoriteFolders.forEach((folder) => {
- Navigation.register(generateFolderView(folder))
- })
+ favoriteFoldersViews.forEach(view => Navigation.register(view))
/**
* Update favourites navigation when a new folder is added
@@ -68,7 +91,7 @@ export default () => {
return
}
- Navigation.register(generateFolderView(node.path))
+ addPathToFavorites(node.path)
})
/**
@@ -85,30 +108,42 @@ export default () => {
return
}
- Navigation.remove(generateIdFromPath(node.path))
+ removePathFromFavorites(node.path)
})
-}
-
-const generateFolderView = function(folder: string): Navigation {
- return {
- id: generateIdFromPath(folder),
- name: basename(folder),
-
- icon: FolderSvg,
- order: -100, // always first
- params: {
- dir: folder,
- view: 'favorites',
- },
- parent: 'favorites',
-
- columns: [],
-
- getContents,
- } as Navigation
-}
-
-const generateIdFromPath = function(path: string): string {
- return `favorite-${hashCode(path)}`
+ /**
+ * Sort the favorites paths array and
+ * update the order property of the existing views
+ */
+ const updateAndSortViews = function() {
+ favoriteFolders.sort((a, b) => a.localeCompare(b, getLanguage(), { ignorePunctuation: true }))
+ favoriteFolders.forEach((folder, index) => {
+ const view = favoriteFoldersViews.find(view => view.id === generateIdFromPath(folder))
+ if (view) {
+ view.order = index
+ }
+ })
+ }
+
+ // Add a folder to the favorites paths array and update the views
+ const addPathToFavorites = function(path: string) {
+ const view = generateFolderView(path)
+ // Update arrays
+ favoriteFolders.push(path)
+ favoriteFoldersViews.push(view)
+ // Update and sort views
+ updateAndSortViews()
+ Navigation.register(view)
+ }
+
+ // Remove a folder from the favorites paths array and update the views
+ const removePathFromFavorites = function(path: string) {
+ const id = generateIdFromPath(path)
+ const index = favoriteFolders.findIndex(f => f === path)
+ // Update arrays
+ favoriteFolders.splice(index, 1)
+ favoriteFoldersViews.splice(index, 1)
+ Navigation.remove(id)
+ updateAndSortViews()
+ }
}