Skip to content

Commit

Permalink
fix: use filename to find current index
Browse files Browse the repository at this point in the history
The viewer component is usually used with a folder and the basename unique.
However in photos, the fileList contains objects from multiple folders and the basename is not always unique.

How to reproduce:

- Create folder A and B
- Upload an image to folder A and name it "Test"
- Upload another image to folder B and also name it "Test"
- Open photos
- Click on the image from folder B
- The image from folder A is shown

To find the correct "currentIndex" we need filename (including the path).

Signed-off-by: Daniel Kesselberg <[email protected]>
Signed-off-by: nextcloud-command <[email protected]>
  • Loading branch information
kesselb authored and nextcloud-command committed Dec 30, 2023
1 parent 27cb725 commit 403853d
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 16 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions js/viewer-filerobot.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/viewer-filerobot.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions js/viewer-main.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/viewer-main.js.map

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/services/Viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ import Audios from '../models/audios.js'
* File info type definition
*
* @typedef {object} Fileinfo
* @property {string} filename the file name
* @property {string} basename the full path of the file
* @property {string} filename File path of the remote item
* @property {string} basename Base filename of the remote item, no path
* @property {?string} source absolute path of a non-dav file, e.g. a static resource or provided by an app route
* @property {string} mime file MIME type in the format type/sub-type
* @property {string} [previewUrl] URL of the file preview
Expand Down
10 changes: 5 additions & 5 deletions src/views/Viewer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ export default {

files(fileList) {
// the files list changed, let's update the current opened index
const currentIndex = fileList.findIndex(file => file.basename === this.currentFile.basename)
const currentIndex = fileList.findIndex(file => file.filename === this.currentFile.filename)
if (currentIndex > -1) {
this.currentIndex = currentIndex
logger.debug('The files list changed, new current file index is ' + currentIndex)
Expand Down Expand Up @@ -684,7 +684,7 @@ export default {
this.fileList = this.files

// store current position
this.currentIndex = this.fileList.findIndex(file => file.basename === fileInfo.basename)
this.currentIndex = this.fileList.findIndex(file => file.filename === fileInfo.filename)
} else if (group && this.el === null) {
const mimes = this.mimeGroups[group]
? this.mimeGroups[group]
Expand All @@ -705,7 +705,7 @@ export default {
this.fileList = filteredFiles.sort((a, b) => sortCompare(a, b, this.sortingConfig.key, this.sortingConfig.asc))

// store current position
this.currentIndex = this.fileList.findIndex(file => file.basename === fileInfo.basename)
this.currentIndex = this.fileList.findIndex(file => file.filename === fileInfo.filename)
} else {
this.currentIndex = 0
this.fileList = [fileInfo]
Expand Down Expand Up @@ -1127,8 +1127,8 @@ export default {
await axios.delete(url)
emit('files:node:deleted', { fileid })

// fileid is not unique, basename is
const currentIndex = this.fileList.findIndex(file => file.basename === this.currentFile.basename)
// fileid is not unique, basename is not unqiue, filename is
const currentIndex = this.fileList.findIndex(file => file.filename === this.currentFile.filename)
if (this.hasPrevious || this.hasNext) {
// Checking the previous or next file
this.hasPrevious ? this.previous() : this.next()
Expand Down

0 comments on commit 403853d

Please sign in to comment.