-
Notifications
You must be signed in to change notification settings - Fork 55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add onPrev, onNext, and onClose callbacks #497
Conversation
44cd8d5
to
4acdf8f
Compare
src/views/Viewer.vue
Outdated
@@ -222,7 +223,7 @@ export default { | |||
if (path.trim() !== '') { | |||
console.info('Opening viewer for file ', path) | |||
this.openFile(path) | |||
} else { | |||
} else if (this.initiated) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh... one more thing. I had to add this condition because the close function was getting twice. I suspect it happened like this:
- clicking the ❌ triggers the close function
- the close function indirectly sets file to
''
which triggers this observer function.
Since close
also sets this.initiated
to false this condition works to prevent calling close again. However it seems like a workaround for a more fundamental problem.
Should i try and solve the underlying problem as part of this pr?
What would be the best way to approach it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, if you can narrow why is it called twice, that would be better I think :)
Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I figured out what happens:
- clicking the ❌ triggers the close function
- close function calls
OCA.Viewer.close()
and triggers the callback OCA.Viewer.close()
setsfile
to''
- the
file
watcher triggers the close function again - close function calls
OCA.Viewer.close()
and triggers the callback again OCA.Viewer.close()
setsfile
to''
- this time it has no effect because it already was empty.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In order to fix this i separate cleanup
from the close
function
-
close()
delegates toOCA.Viewer.close()
.
It is just a shortcut to be used in the template. -
cleanup()
does the actual work.
OCA.Viewer.close()
will setfile
to''
.
file
is being watched and the watch function triggers the cleanup.
2464d5c
to
dc72592
Compare
@skjnldsv If you could take another look... that would be great 😃 (added another commit fixing the double call of |
Sorry, I'm overwhelmed since a few months! :( |
That's what i was assuming. I know how it feels. Take your time. 🍵 🥰 |
src/services/Viewer.js
Outdated
* @param {string} path the path to open | ||
* @param {Object[]} [list] the list of files as objects (fileinfo) format |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you also update the jsdoc, it is outdated and doesn't reflect the Object params requirements (I forgot to update it before, but since we're at it 🙈)
Please also rebase! :) |
Let's rebase, squash and get this in? :) |
@skjnldsv I'm in a call right now. This is the next thing I'll work on. |
c66416e
to
fd03cec
Compare
@skjnldsv I rebased and updated the jsdoc. |
Yes please :) |
/compile amend / |
Apps using the viewer might want to react to changes in the viewer. In particular this will update the url in the files app when navigating between files. This way the url can be copied and used to navigate to one particular image in a collection. It also can be used to add browser history entries. For this to work it is important to first call the callback and then update the title. This way the callback can create a new history entry and the title of that entry will then be updated. onPrev and onNext callbacks receive the old and the current fileInfo as arguments. onClose callback does not receive any arguments as of now. Update the url by pushing a new entry to browser history. Update before the initial load, when navigating to include the fileid of the newly displayed file. Push the original url again once the viewer is closed. `close()` delegates to `OCA.Viewer.close()`. It is just a shortcut to be used in the template. `cleanup()` does the actual work. `OCA.Viewer.close()` will set `file` to `''`. `file` is being watched and the watch function triggers the cleanup. This way each step is only getting called once. Here's what was happening before: * clicking the ❌ triggers the close function * close function calls `OCA.Viewer.close()` and triggers the callback * `OCA.Viewer.close()` sets `file` to `''` * the `file` watcher triggers the close function again * close function calls `OCA.Viewer.close()` and triggers the callback again * `OCA.Viewer.close()` sets `file` to `''` * this time it has no effect because it already was empty. doc: update jsdoc for Viewer.open Signed-off-by: Azul <azul@riseup.net> Signed-off-by: npmbuildbot[bot] <npmbuildbot[bot]@users.noreply.github.com>
812d77f
to
bcf6f74
Compare
}, | ||
|
||
onNext(info, oldFileInfo) { | ||
this.Viewer.onNext(oldFileInfo) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @azul, I just rezlized we did a mistake, the onPrev and onNext have different parametters.
It should most likely be consistent:
this.Viewer.onNext(info, oldFileInfo)
Apps using the viewer might want to react to changes in the viewer.
In particular make use of the callbacks
to updating the url in the files app when navigating between files.
This way the url can be copied and used to navigate to one particular image in a collection.
It also can be used to add browser history entries.
For this first call the callback and then update the title.
This way the callback can create a new history entry
and the title of that entry will then be updated.
onPrev
andonNext
callbacks receive the old and the currentfileInfo
as arguments.
onClose
callback does not receive any arguments as of now.Pull Request consists of two commits:
actionHandler
.This pull request is a result of the discussion in #488