aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristopher Ng <chrng8@gmail.com>2024-08-21 10:31:21 -0700
committerChristopher Ng <chrng8@gmail.com>2024-08-27 14:33:39 -0700
commit9cc1a020a2d38b28102f14d651529e31b994f617 (patch)
tree63e18b69c7e790b0c8e3a9dd484761996b05b8eb
parent71e653c0bc0f365d4dbd863e797308334b307532 (diff)
downloadnextcloud-server-9cc1a020a2d38b28102f14d651529e31b994f617.tar.gz
nextcloud-server-9cc1a020a2d38b28102f14d651529e31b994f617.zip
feat(files): Allow more than 50 favorite views
Signed-off-by: Christopher Ng <chrng8@gmail.com>
-rw-r--r--apps/files/src/init.ts2
-rw-r--r--apps/files/src/views/favorites.spec.ts2
-rw-r--r--apps/files/src/views/favorites.ts35
3 files changed, 15 insertions, 24 deletions
diff --git a/apps/files/src/init.ts b/apps/files/src/init.ts
index 846f1049d5a..db4aec7fa06 100644
--- a/apps/files/src/init.ts
+++ b/apps/files/src/init.ts
@@ -23,7 +23,7 @@ import { entry as newFolderEntry } from './newMenu/newFolder.ts'
import { entry as newTemplatesFolder } from './newMenu/newTemplatesFolder.ts'
import { registerTemplateEntries } from './newMenu/newFromTemplate.ts'
-import registerFavoritesView from './views/favorites'
+import { registerFavoritesView } from './views/favorites.ts'
import registerRecentView from './views/recent'
import registerPersonalFilesView from './views/personal-files'
import registerFilesView from './views/files'
diff --git a/apps/files/src/views/favorites.spec.ts b/apps/files/src/views/favorites.spec.ts
index b2aa292f936..cb6f2fcde5e 100644
--- a/apps/files/src/views/favorites.spec.ts
+++ b/apps/files/src/views/favorites.spec.ts
@@ -12,7 +12,7 @@ import * as initialState from '@nextcloud/initial-state'
import { action } from '../actions/favoriteAction'
import * as favoritesService from '../services/Favorites'
-import registerFavoritesView from './favorites'
+import { registerFavoritesView } from './favorites'
vi.mock('@nextcloud/axios')
diff --git a/apps/files/src/views/favorites.ts b/apps/files/src/views/favorites.ts
index 3af8c49498f..c6846724bba 100644
--- a/apps/files/src/views/favorites.ts
+++ b/apps/files/src/views/favorites.ts
@@ -5,10 +5,9 @@
import type { Folder, Node } from '@nextcloud/files'
import { subscribe } from '@nextcloud/event-bus'
-import { FileType, View, getNavigation } from '@nextcloud/files'
-import { loadState } from '@nextcloud/initial-state'
+import { FileType, View, getFavoriteNodes, getNavigation } from '@nextcloud/files'
import { getLanguage, translate as t } from '@nextcloud/l10n'
-import { basename } from 'path'
+import { client } from '../services/WebdavClient.ts'
import FolderSvg from '@mdi/svg/svg/folder.svg?raw'
import StarSvg from '@mdi/svg/svg/star.svg?raw'
@@ -16,22 +15,17 @@ import { getContents } from '../services/Favorites'
import { hashCode } from '../utils/hashUtils'
import logger from '../logger'
-// The return type of the initial state
-interface IFavoriteFolder {
- fileid: number
- path: string
-}
-
-export const generateFavoriteFolderView = function(folder: IFavoriteFolder, index = 0): View {
+const generateFavoriteFolderView = function(folder: Folder, index = 0): View {
return new View({
id: generateIdFromPath(folder.path),
- name: basename(folder.path),
+ name: folder.displayname,
icon: FolderSvg,
order: index,
+
params: {
dir: folder.path,
- fileid: folder.fileid.toString(),
+ fileid: String(folder.fileid),
view: 'favorites',
},
@@ -43,16 +37,11 @@ export const generateFavoriteFolderView = function(folder: IFavoriteFolder, inde
})
}
-export const generateIdFromPath = function(path: string): string {
+const generateIdFromPath = function(path: string): string {
return `favorite-${hashCode(path)}`
}
-export default () => {
- // Load state in function for mock testing purposes
- const favoriteFolders = loadState<IFavoriteFolder[]>('files', 'favoriteFolders', [])
- const favoriteFoldersViews = favoriteFolders.map((folder, index) => generateFavoriteFolderView(folder, index)) as View[]
- logger.debug('Generating favorites view', { favoriteFolders })
-
+export const registerFavoritesView = async () => {
const Navigation = getNavigation()
Navigation.register(new View({
id: 'favorites',
@@ -70,6 +59,9 @@ export default () => {
getContents,
}))
+ const favoriteFolders = (await getFavoriteNodes(client)).filter(node => node.type === FileType.Folder) as Folder[]
+ const favoriteFoldersViews = favoriteFolders.map((folder, index) => generateFavoriteFolderView(folder, index)) as View[]
+ logger.debug('Generating favorites view', { favoriteFolders })
favoriteFoldersViews.forEach(view => Navigation.register(view))
/**
@@ -137,8 +129,7 @@ export default () => {
// Add a folder to the favorites paths array and update the views
const addToFavorites = function(node: Folder) {
- const newFavoriteFolder: IFavoriteFolder = { path: node.path, fileid: node.fileid! }
- const view = generateFavoriteFolderView(newFavoriteFolder)
+ const view = generateFavoriteFolderView(node)
// Skip if already exists
if (favoriteFolders.find((folder) => folder.path === node.path)) {
@@ -146,7 +137,7 @@ export default () => {
}
// Update arrays
- favoriteFolders.push(newFavoriteFolder)
+ favoriteFolders.push(node)
favoriteFoldersViews.push(view)
// Update and sort views