Skip to content

Commit

Permalink
Add initiated loading state for snappier loading
Browse files Browse the repository at this point in the history
Signed-off-by: John Molakvoæ (skjnldsv) <[email protected]>
  • Loading branch information
skjnldsv committed Oct 28, 2019
1 parent 3267721 commit 29dd23c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/services/Viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export default class Viewer {
}

/**
* Close the opened file
* Open the path into the viewer
*
* @memberof Viewer
* @param {string} path the path to open
Expand Down
36 changes: 24 additions & 12 deletions src/views/Viewer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

<template>
<Modal
v-if="currentFile.modal"
v-if="initiated || currentFile.modal"
id="viewer-content"
:class="{'icon-loading': !currentFile.loaded && !currentFile.failed}"
:view="currentFile.modal"
Expand All @@ -40,6 +40,7 @@
<!-- ACTIONS -->
<template #actions>
<ActionButton
v-if="OCA.Files && OCA.Files.Sidebar"
icon="icon-menu-sidebar-white-forced"
@click="showSidebar">
{{ t('viewer', 'Open sidebar') }}
Expand Down Expand Up @@ -151,6 +152,7 @@ export default {
fileList: [],

isLoaded: false,
initiated: false,

shownSidebar: false,
sidebarWidth: 0,
Expand Down Expand Up @@ -194,9 +196,13 @@ export default {
},

file: function(path) {
// we got a valid path! Load file...
if (path.trim() !== '') {
console.info('Opening viewer for file ', path)
this.openFile(path)
} else {
// path is empty, closing!
this.close()
}
}
},
Expand Down Expand Up @@ -239,6 +245,10 @@ export default {
return
}

// initial loading start
this.initiated = true

// extcrat needed info from path
const [dirPath, fileName] = extractFilePaths(path)

// prevent scrolling while opened
Expand Down Expand Up @@ -269,13 +279,12 @@ export default {

// filter out the unwanted mimes
const filteredFiles = fileList.filter(file => file.mime && mimes.indexOf(file.mime) !== -1)
console.info(filteredFiles);

// sort like the files list
// TODO: implement global sorting API
// https://github.com/nextcloud/server/blob/a83b79c5f8ab20ed9b4d751167417a65fa3c42b8/apps/files/lib/Controller/ApiController.php#L247
if (!this.standalone) {
this.fileList = filteredFiles.sort((a, b) => sortCompare(a, b, 'basename'))
}
this.fileList = filteredFiles.sort((a, b) => sortCompare(a, b, 'basename'))

// store current position
this.currentIndex = this.fileList.findIndex(file => file.basename === fileName)
Expand All @@ -292,6 +301,7 @@ export default {
mime = mime.split('/')[0]
}

// if we have a valid mime, show it!
if (this.components[mime]) {
this.currentFile = new File(fileInfo, mime, this.components[mime])
this.updatePreviousNext()
Expand Down Expand Up @@ -453,27 +463,29 @@ export default {
}
})
OCA.Files.fileActions.setDefault(mime, 'view')
}

// register groups
if (group) {
this.mimeGroups[mime] = group
// init if undefined
if (!this.mimeGroups[group]) {
this.mimeGroups[group] = []
}
this.mimeGroups[group].push(mime)
// register groups
if (group) {
this.mimeGroups[mime] = group
// init if undefined
if (!this.mimeGroups[group]) {
this.mimeGroups[group] = []
}
this.mimeGroups[group].push(mime)
}
},

/**
* Close the viewer
*/
close() {
// reset all properties
OCA.Viewer.close()
this.currentFile = {}
this.currentModal = null
this.fileList = []
this.initiated = false
this.hideAppsSidebar()

// restore default
Expand Down

0 comments on commit 29dd23c

Please sign in to comment.