Skip to content
Merged
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
Next Next commit
fix: sorting to align with files list
Signed-off-by: Luka Trovic <[email protected]>
  • Loading branch information
luka-nextcloud authored and skjnldsv committed Aug 22, 2025
commit 3526fec93e09abbd544f33fa19ae1b05b62fabe7
22 changes: 19 additions & 3 deletions src/views/Viewer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ import '@nextcloud/dialogs/style.css'
import Vue, { defineComponent } from 'vue'

import { emit, subscribe, unsubscribe } from '@nextcloud/event-bus'
import { File as NcFile, Node, davRemoteURL, davRootPath, davGetRootPath } from '@nextcloud/files'
import { File as NcFile, Node, davRemoteURL, davRootPath, davGetRootPath, sortNodes } from '@nextcloud/files'
import { loadState } from '@nextcloud/initial-state'
import { showError } from '@nextcloud/dialogs'
import axios from '@nextcloud/axios'
Expand All @@ -203,7 +203,7 @@ import getSortingConfig from '../services/FileSortingConfig.ts'
import isFullscreen from '@nextcloud/vue/dist/Mixins/isFullscreen.js'
import isMobile from '@nextcloud/vue/dist/Mixins/isMobile.js'

import { extractFilePaths, sortCompare, extractFilePathFromSource } from '../utils/fileUtils.ts'
import { extractFilePaths, extractFilePathFromSource } from '../utils/fileUtils.ts'
import cancelableRequest from '../utils/CancelableRequest.js'
import canDownload from '../utils/canDownload.js'
import Error from '../components/Error.vue'
Expand Down Expand Up @@ -762,7 +762,23 @@ export default defineComponent({
// sort like the files list
// TODO: implement global sorting API
// https://github.com/nextcloud/server/blob/a83b79c5f8ab20ed9b4d751167417a65fa3c42b8/apps/files/lib/Controller/ApiController.php#L247
this.fileList = filteredFiles.sort((a, b) => sortCompare(a, b, this.sortingConfig.key, this.sortingConfig.asc))
const url = this.currentFile.source ?? this.currentFile.davPath
const nodes = filteredFiles.map(
file => new NcFile({
source: davRemoteURL + davGetRootPath() + file.filename,
fileid: file.fileid,
displayname: file.displayname,
mime: file.mime,
mtime: new Date(file.lastmod),
owner: this.currentFile.ownerId,
root: url.includes('remote.php/dav') ? davGetRootPath() : undefined,
}),
)
const sortedNodes = sortNodes(nodes, {
sortingMode: this.sortingConfig.key,
sortingOrder: this.sortingConfig.asc ? 'asc' : 'desc',
})
this.fileList = sortedNodes.map(node => filteredFiles.find(file => file.filename === node.path))

// store current position
this.currentIndex = this.fileList.findIndex(file => file.filename === fileInfo.filename)
Expand Down