Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
feat(files): sort favorites first
Signed-off-by: John Molakvoæ <[email protected]>
  • Loading branch information
skjnldsv committed May 4, 2023
commit 844f9be0b99ea1d1adb4ce521b2279b10484bea5
8 changes: 7 additions & 1 deletion apps/files/lib/Service/UserConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions apps/files/src/store/userconfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
13 changes: 11 additions & 2 deletions apps/files/src/views/FilesList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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,
}
},
Expand All @@ -123,6 +126,10 @@ export default Vue.extend({
},

computed: {
userConfig() {
return this.userConfigStore.userConfig
},

/** @return {Navigation} */
currentView() {
return this.$navigation.active
Expand Down Expand Up @@ -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'],
Expand Down
4 changes: 4 additions & 0 deletions apps/files/src/views/Settings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
@update:open="onClose">
<!-- Settings API-->
<NcAppSettingsSection id="settings" :title="t('files', 'Files settings')">
<NcCheckboxRadioSwitch :checked="userConfig.sort_favorites_first"
@update:checked="setConfig('sort_favorites_first', $event)">
{{ t('files', 'Sort favorites first') }}
</NcCheckboxRadioSwitch>
<NcCheckboxRadioSwitch :checked="userConfig.show_hidden"
@update:checked="setConfig('show_hidden', $event)">
{{ t('files', 'Show hidden files') }}
Expand Down