diff options
author | Ferdinand Thiessen <opensource@fthiessen.de> | 2023-11-16 00:58:06 +0100 |
---|---|---|
committer | Ferdinand Thiessen <opensource@fthiessen.de> | 2023-11-16 14:25:40 +0100 |
commit | e250a561701ce010188a3c3a84b522dc51aed878 (patch) | |
tree | 6ce3408f0cd5a675e4c34636f7c23ef3d504ae50 | |
parent | 9c3350b3131312e60155c26a8a15b95981c6dd0a (diff) | |
download | nextcloud-server-e250a561701ce010188a3c3a84b522dc51aed878.tar.gz nextcloud-server-e250a561701ce010188a3c3a84b522dc51aed878.zip |
fix(files): Ensure favorites and folders are sorted first regardless or sorting order
Also fixes `mtime` being wrong sorted, as high mtime means recently edited -> lower
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
-rw-r--r-- | apps/files/src/views/FilesList.vue | 51 |
1 files changed, 35 insertions, 16 deletions
diff --git a/apps/files/src/views/FilesList.vue b/apps/files/src/views/FilesList.vue index 3bc4f27c2a2..0729e8a983a 100644 --- a/apps/files/src/views/FilesList.vue +++ b/apps/files/src/views/FilesList.vue @@ -218,6 +218,40 @@ export default Vue.extend({ }, /** + * Directory content sorting parameters + * Provided by an extra computed property for caching + */ + sortingParameters() { + const identifiers = [ + // 1: Sort favorites first if enabled + ...(this.userConfig.sort_favorites_first ? [v => v.attributes?.favorite !== 1] : []), + // 2: Sort folders first if sorting by name + ...(this.sortingMode === 'basename' ? [v => v.type !== 'folder'] : []), + // 3: Use sorting mode if NOT basename (to be able to use displayName too) + ...(this.sortingMode !== 'basename' ? [v => v[this.sortingMode]] : []), + // 4: Use displayName if available, fallback to name + v => v.attributes?.displayName || v.basename, + // 5: Finally, use basename if all previous sorting methods failed + v => v.basename, + ] + const orders = [ + // (for 1): always sort favorites before normal files + ...(this.userConfig.sort_favorites_first ? ['asc'] : []), + // (for 2): always sort folders before files + ...(this.sortingMode === 'basename' ? ['asc'] : []), + // (for 3): Reverse if sorting by mtime as mtime higher means edited more recent -> lower + ...(this.sortingMode === 'mtime' ? [this.isAscSorting ? 'desc' : 'asc'] : []), + // (also for 3 so make sure not to conflict with 2 and 3) + ...(this.sortingMode !== 'mtime' && this.sortingMode !== 'basename' ? [this.isAscSorting ? 'asc' : 'desc'] : []), + // for 4: use configured sorting direction + this.isAscSorting ? 'asc' : 'desc', + // for 5: use configured sorting direction + this.isAscSorting ? 'asc' : 'desc', + ] + return [identifiers, orders] as const + }, + + /** * The current directory contents. */ dirContentsSorted(): Node[] { @@ -234,24 +268,9 @@ export default Vue.extend({ return this.isAscSorting ? results : results.reverse() } - const identifiers = [ - // 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 if NOT basename (to be able to use displayName too) - ...this.sortingMode !== 'basename' ? [v => v[this.sortingMode]] : [], - // Use displayName if available, fallback to name - v => v.attributes?.displayName || v.basename, - // Finally, use basename if all previous sorting methods failed - v => v.basename, - ] - const orders = new Array(identifiers.length).fill(this.isAscSorting ? 'asc' : 'desc') - return orderBy( [...this.dirContents], - identifiers, - orders, + ...this.sortingParameters, ) }, |