nextcloud/apps/files/src/utils/filesViews.ts
Ferdinand Thiessen 275c4404d4
feat(files): allow to configure default view
This allows to configure which view should be the default ("start view")
in the files app, currently either "all files" or "personal files".
But it might be extended to the new home view in the future.

Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
2025-07-04 18:03:10 +02:00

30 lines
864 B
TypeScript

/**
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
import type { UserConfig } from '../types.ts'
import { loadState } from '@nextcloud/initial-state'
/**
* Check whether the personal files view can be shown
*/
export function hasPersonalFilesView(): boolean {
const storageStats = loadState('files', 'storageStats', { quota: -1 })
// Don't show this view if the user has no storage quota
return storageStats.quota !== 0
}
/**
* Get the default files view
*/
export function defaultView() {
const { default_view: defaultView } = loadState<Partial<UserConfig>>('files', 'config', { default_view: 'files' })
// the default view - only use the personal one if it is enabled
if (defaultView !== 'personal' || hasPersonalFilesView()) {
return defaultView
}
return 'files'
}