Skip to content

Commit cce1e1d

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

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
@@ -180,15 +180,15 @@ import Vue, { defineComponent } from 'vue'
180180
181181
import { emit, subscribe, unsubscribe } from '@nextcloud/event-bus'
182182
import { loadState } from '@nextcloud/initial-state'
183-
import { File as NcFile, Node, davRemoteURL, davRootPath, davGetRootPath } from '@nextcloud/files'
183+
import { File as NcFile, Node, davRemoteURL, davRootPath, davGetRootPath, sortNodes } from '@nextcloud/files'
184184
import { showError } from '@nextcloud/dialogs'
185185
import axios from '@nextcloud/axios'
186186
187187
import isFullscreen from '@nextcloud/vue/dist/Mixins/isFullscreen.js'
188188
import isMobile from '@nextcloud/vue/dist/Mixins/isMobile.js'
189189
190190
import { canDownload } from '../utils/canDownload.ts'
191-
import { extractFilePaths, sortCompare, extractFilePathFromSource } from '../utils/fileUtils.ts'
191+
import { extractFilePaths, extractFilePathFromSource } from '../utils/fileUtils.ts'
192192
import getSortingConfig from '../services/FileSortingConfig.ts'
193193
import cancelableRequest from '../utils/CancelableRequest.js'
194194
import Error from '../components/Error.vue'
@@ -770,7 +770,23 @@ export default defineComponent({
770770
// sort like the files list
771771
// TODO: implement global sorting API
772772
// https://github.com/nextcloud/server/blob/a83b79c5f8ab20ed9b4d751167417a65fa3c42b8/apps/files/lib/Controller/ApiController.php#L247
773-
this.fileList = filteredFiles.sort((a, b) => sortCompare(a, b, this.sortingConfig.key, this.sortingConfig.asc))
773+
const url = this.currentFile.source ?? this.currentFile.davPath
774+
const nodes = filteredFiles.map(
775+
file => new NcFile({
776+
source: davRemoteURL + davGetRootPath() + file.filename,
777+
fileid: file.fileid,
778+
displayname: file.displayname,
779+
mime: file.mime,
780+
mtime: new Date(file.lastmod),
781+
owner: this.currentFile.ownerId,
782+
root: url.includes('remote.php/dav') ? davGetRootPath() : undefined,
783+
}),
784+
)
785+
const sortedNodes = sortNodes(nodes, {
786+
sortingMode: this.sortingConfig.key,
787+
sortingOrder: this.sortingConfig.asc ? 'asc' : 'desc',
788+
})
789+
this.fileList = sortedNodes.map(node => filteredFiles.find(file => file.filename === node.path))
774790
775791
// store current position
776792
this.currentIndex = this.fileList.findIndex(file => file.filename === fileInfo.filename)

0 commit comments

Comments
 (0)