Skip to content

Commit

Permalink
update history when opening and closing viewer
Browse files Browse the repository at this point in the history
* Add the `openfile` param to the url when opening a file
* update the document title from the Mime mixin
* push the new url to the browser history
* Also update the title and push the url when moving inside a collection
* push original url to browser history state when closing the viewer

fixes server#12470

Alternatives
------------

We could pop state back to where we started when closing the viewer.
That way history would not contain urls for visited files.
In particular when navigating through collections
I think having a full history may be useful

Warning
-------

Adds the following warning:
```
/home/next/code/nextcloud/server/apps/viewer/src/mixins/Mime.js
  111:20  warning  The property or function OC.encodePath was deprecated in Nextcloud 18.0.0
```
I tried to work around it
by using encodePath from https://www.npmjs.com/package/@nextcloud/paths
But no external imports are allowed in mixins.

Next Steps
----------

* Handle popstate events so we can actually go back in history

Signed-off-by: Azul <azul@riseup.net>
  • Loading branch information
azul committed Apr 30, 2020
1 parent 36dcc17 commit 45a9036
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
4 changes: 2 additions & 2 deletions js/viewer.js

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions src/mixins/Mime.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,14 @@ export default {
ext() {
return parsePath(this.basename).ext
},
queryString() {
const params = OC.Util.History.parseUrlQuery()
const dir = params.dir
delete params.dir
delete params.fileid
params.openfile = this.fileid
return 'dir=' + OC.encodePath(dir) + '&' + OC.buildQueryString(params)
},
},

watch: {
Expand All @@ -112,6 +120,8 @@ export default {
if (this.isLoaded) {
this.doneLoading()
}
OC.Util.History.pushState(this.queryString)
document.title = `${this.basename} - ${OC.theme.title}`
}
},
// update image size on sidebar toggle
Expand All @@ -132,6 +142,10 @@ export default {
window.addEventListener('resize', debounce(() => {
this.updateHeightWidth()
}, 100))
if (this.active) {
OC.Util.History.pushState(this.queryString)
document.title = `${this.basename} - ${OC.theme.title}`
}
},

methods: {
Expand Down
6 changes: 5 additions & 1 deletion src/views/Viewer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ export default {
const title = document.getElementsByTagName('head')[0].getElementsByTagName('title')[0]
if (title && !title.dataset.old) {
title.dataset.old = document.title
document.title = `${fileName} - ${OC.theme.title}`
title.dataset.oldQuery = location.search
}

try {
Expand Down Expand Up @@ -599,6 +599,10 @@ export default {
document.title = title.dataset.old
delete title.dataset.old
}
if (title && title.dataset.oldQuery) {
OC.Util.History.pushState(title.dataset.oldQuery)
delete title.dataset.oldQuery
}
},

/**
Expand Down

0 comments on commit 45a9036

Please sign in to comment.