Skip to content

Commit 844f9be

Browse files
committed
feat(files): sort favorites first
Signed-off-by: John Molakvoæ <skjnldsv@protonmail.com>
1 parent 11b19d7 commit 844f9be

4 files changed

Lines changed: 23 additions & 3 deletions

File tree

apps/files/lib/Service/UserConfig.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ class UserConfig {
4141
'default' => false,
4242
'allowed' => [true, false],
4343
],
44+
[
45+
// Whether to sort favorites first in the list or not
46+
'key' => 'sort_favorites_first',
47+
'default' => true,
48+
'allowed' => [true, false],
49+
],
4450
];
4551

4652
protected IConfig $config;
@@ -133,7 +139,7 @@ public function getConfigs(): array {
133139
$userConfigs = array_map(function(string $key) use ($userId) {
134140
$value = $this->config->getUserValue($userId, Application::APP_ID, $key, $this->getDefaultConfigValue($key));
135141
// If the default is expected to be a boolean, we need to cast the value
136-
if (is_bool($this->getDefaultConfigValue($key))) {
142+
if (is_bool($this->getDefaultConfigValue($key)) && is_string($value)) {
137143
return $value === '1';
138144
}
139145
return $value;

apps/files/src/store/userconfig.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import { emit, subscribe } from '@nextcloud/event-bus'
3131
const userConfig = loadState('files', 'config', {
3232
show_hidden: false,
3333
crop_image_previews: true,
34+
sort_favorites_first: true,
3435
}) as UserConfig
3536

3637
export const useUserConfigStore = function() {

apps/files/src/views/FilesList.vue

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ import Vue from 'vue'
7878
import { useFilesStore } from '../store/files.ts'
7979
import { usePathsStore } from '../store/paths.ts'
8080
import { useSelectionStore } from '../store/selection.ts'
81+
import { useUserConfigStore } from '../store/userconfig.ts'
8182
import { useViewConfigStore } from '../store/viewConfig.ts'
8283
import BreadCrumbs from '../components/BreadCrumbs.vue'
8384
import FilesListVirtual from '../components/FilesListVirtual.vue'
@@ -103,14 +104,16 @@ export default Vue.extend({
103104
],
104105
105106
setup() {
106-
const pathsStore = usePathsStore()
107107
const filesStore = useFilesStore()
108+
const pathsStore = usePathsStore()
108109
const selectionStore = useSelectionStore()
110+
const userConfigStore = useUserConfigStore()
109111
const viewConfigStore = useViewConfigStore()
110112
return {
111113
filesStore,
112114
pathsStore,
113115
selectionStore,
116+
userConfigStore,
114117
viewConfigStore,
115118
}
116119
},
@@ -123,6 +126,10 @@ export default Vue.extend({
123126
},
124127
125128
computed: {
129+
userConfig() {
130+
return this.userConfigStore.userConfig
131+
},
132+
126133
/** @return {Navigation} */
127134
currentView() {
128135
return this.$navigation.active
@@ -179,11 +186,13 @@ export default Vue.extend({
179186
return orderBy(
180187
[...(this.currentFolder?._children || []).map(this.getNode).filter(file => file)],
181188
[
189+
// Sort favorites first if enabled
190+
...this.userConfig.sort_favorites_first ? [v => v.attributes?.favorite !== 1] : [],
182191
// Sort folders first if sorting by name
183192
...this.sortingMode === 'basename' ? [v => v.type !== 'folder'] : [],
184193
// Use sorting mode
185194
v => v[this.sortingMode],
186-
// Fallback to name
195+
// Finally, fallback to name
187196
v => v.basename,
188197
],
189198
this.isAscSorting ? ['asc', 'asc', 'asc'] : ['desc', 'desc', 'desc'],

apps/files/src/views/Settings.vue

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@
2626
@update:open="onClose">
2727
<!-- Settings API-->
2828
<NcAppSettingsSection id="settings" :title="t('files', 'Files settings')">
29+
<NcCheckboxRadioSwitch :checked="userConfig.sort_favorites_first"
30+
@update:checked="setConfig('sort_favorites_first', $event)">
31+
{{ t('files', 'Sort favorites first') }}
32+
</NcCheckboxRadioSwitch>
2933
<NcCheckboxRadioSwitch :checked="userConfig.show_hidden"
3034
@update:checked="setConfig('show_hidden', $event)">
3135
{{ t('files', 'Show hidden files') }}

0 commit comments

Comments
 (0)