Skip to content

Commit c686f47

Browse files
fix: sorting to align with files list
Signed-off-by: Luka Trovic <luka@nextcloud.com>
1 parent fef91cf commit c686f47

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

src/views/Viewer.vue

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ import '@nextcloud/dialogs/style.css'
194194
import Vue, { defineComponent } from 'vue'
195195
196196
import { emit, subscribe, unsubscribe } from '@nextcloud/event-bus'
197-
import { File as NcFile, Node, davRemoteURL, davRootPath, davGetRootPath } from '@nextcloud/files'
197+
import { File as NcFile, Node, davRemoteURL, davRootPath, davGetRootPath, sortNodes } from '@nextcloud/files'
198198
import { loadState } from '@nextcloud/initial-state'
199199
import { showError } from '@nextcloud/dialogs'
200200
import axios from '@nextcloud/axios'
@@ -203,7 +203,7 @@ import getSortingConfig from '../services/FileSortingConfig.ts'
203203
import isFullscreen from '@nextcloud/vue/dist/Mixins/isFullscreen.js'
204204
import isMobile from '@nextcloud/vue/dist/Mixins/isMobile.js'
205205
206-
import { extractFilePaths, sortCompare, extractFilePathFromSource } from '../utils/fileUtils.ts'
206+
import { extractFilePaths, extractFilePathFromSource } from '../utils/fileUtils.ts'
207207
import cancelableRequest from '../utils/CancelableRequest.js'
208208
import canDownload from '../utils/canDownload.js'
209209
import Error from '../components/Error.vue'
@@ -762,7 +762,23 @@ export default defineComponent({
762762
// sort like the files list
763763
// TODO: implement global sorting API
764764
// https://github.com/nextcloud/server/blob/a83b79c5f8ab20ed9b4d751167417a65fa3c42b8/apps/files/lib/Controller/ApiController.php#L247
765-
this.fileList = filteredFiles.sort((a, b) => sortCompare(a, b, this.sortingConfig.key, this.sortingConfig.asc))
765+
const url = this.currentFile.source ?? this.currentFile.davPath
766+
const nodes = filteredFiles.map(
767+
file => new NcFile({
768+
source: davRemoteURL + davGetRootPath() + file.filename,
769+
fileid: file.fileid,
770+
displayname: file.displayname,
771+
mime: file.mime,
772+
mtime: new Date(file.lastmod),
773+
owner: this.currentFile.ownerId,
774+
root: url.includes('remote.php/dav') ? davGetRootPath() : undefined,
775+
}),
776+
)
777+
const sortedNodes = sortNodes(nodes, {
778+
sortingMode: this.sortingConfig.key,
779+
sortingOrder: this.sortingConfig.asc ? 'asc' : 'desc',
780+
})
781+
this.fileList = sortedNodes.map(node => filteredFiles.find(file => file.filename === node.path))
766782
767783
// store current position
768784
this.currentIndex = this.fileList.findIndex(file => file.filename === fileInfo.filename)

0 commit comments

Comments
 (0)