From 561c72bc0fa1203c3cf365de9da1bc4a623098c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Molakvo=C3=A6?= Date: Thu, 27 Apr 2023 11:15:48 +0200 Subject: [PATCH] feat(files): sort favorites first MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: John Molakvoæ --- apps/files/lib/Service/UserConfig.php | 8 +++++++- apps/files/src/store/userconfig.ts | 1 + apps/files/src/views/FilesList.vue | 13 +++++++++++-- apps/files/src/views/Settings.vue | 4 ++++ 4 files changed, 23 insertions(+), 3 deletions(-) diff --git a/apps/files/lib/Service/UserConfig.php b/apps/files/lib/Service/UserConfig.php index e405b02c07a91..c39719ae8ed2c 100644 --- a/apps/files/lib/Service/UserConfig.php +++ b/apps/files/lib/Service/UserConfig.php @@ -41,6 +41,12 @@ class UserConfig { 'default' => false, 'allowed' => [true, false], ], + [ + // Whether to sort favorites first in the list or not + 'key' => 'sort_favorites_first', + 'default' => true, + 'allowed' => [true, false], + ], ]; protected IConfig $config; @@ -133,7 +139,7 @@ public function getConfigs(): array { $userConfigs = array_map(function(string $key) use ($userId) { $value = $this->config->getUserValue($userId, Application::APP_ID, $key, $this->getDefaultConfigValue($key)); // If the default is expected to be a boolean, we need to cast the value - if (is_bool($this->getDefaultConfigValue($key))) { + if (is_bool($this->getDefaultConfigValue($key)) && is_string($value)) { return $value === '1'; } return $value; diff --git a/apps/files/src/store/userconfig.ts b/apps/files/src/store/userconfig.ts index 42821951dbfa6..a5b049f197f52 100644 --- a/apps/files/src/store/userconfig.ts +++ b/apps/files/src/store/userconfig.ts @@ -31,6 +31,7 @@ import { emit, subscribe } from '@nextcloud/event-bus' const userConfig = loadState('files', 'config', { show_hidden: false, crop_image_previews: true, + sort_favorites_first: true, }) as UserConfig export const useUserConfigStore = function() { diff --git a/apps/files/src/views/FilesList.vue b/apps/files/src/views/FilesList.vue index f2a20c18f28e8..8b42cfe61336d 100644 --- a/apps/files/src/views/FilesList.vue +++ b/apps/files/src/views/FilesList.vue @@ -78,6 +78,7 @@ import Vue from 'vue' import { useFilesStore } from '../store/files.ts' import { usePathsStore } from '../store/paths.ts' import { useSelectionStore } from '../store/selection.ts' +import { useUserConfigStore } from '../store/userconfig.ts' import { useViewConfigStore } from '../store/viewConfig.ts' import BreadCrumbs from '../components/BreadCrumbs.vue' import FilesListVirtual from '../components/FilesListVirtual.vue' @@ -103,14 +104,16 @@ export default Vue.extend({ ], setup() { - const pathsStore = usePathsStore() const filesStore = useFilesStore() + const pathsStore = usePathsStore() const selectionStore = useSelectionStore() + const userConfigStore = useUserConfigStore() const viewConfigStore = useViewConfigStore() return { filesStore, pathsStore, selectionStore, + userConfigStore, viewConfigStore, } }, @@ -123,6 +126,10 @@ export default Vue.extend({ }, computed: { + userConfig() { + return this.userConfigStore.userConfig + }, + /** @return {Navigation} */ currentView() { return this.$navigation.active @@ -179,11 +186,13 @@ export default Vue.extend({ return orderBy( [...(this.currentFolder?._children || []).map(this.getNode).filter(file => file)], [ + // Sort favorites first if enabled + ...this.userConfig.sort_favorites_first ? [v => v.attributes?.favorite !== 1] : [], // Sort folders first if sorting by name ...this.sortingMode === 'basename' ? [v => v.type !== 'folder'] : [], // Use sorting mode v => v[this.sortingMode], - // Fallback to name + // Finally, fallback to name v => v.basename, ], this.isAscSorting ? ['asc', 'asc', 'asc'] : ['desc', 'desc', 'desc'], diff --git a/apps/files/src/views/Settings.vue b/apps/files/src/views/Settings.vue index efd9f8cad22fd..82580d7c5048b 100644 --- a/apps/files/src/views/Settings.vue +++ b/apps/files/src/views/Settings.vue @@ -26,6 +26,10 @@ @update:open="onClose"> + + {{ t('files', 'Sort favorites first') }} + {{ t('files', 'Show hidden files') }}