Skip to content
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

Merged
merged 1 commit into from
Aug 2, 2020

Conversation

azul
Copy link
Contributor

@azul azul commented May 11, 2020

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 and onNext callbacks receive the old and the current fileInfo
as arguments.
onClose callback does not receive any arguments as of now.

Pull Request consists of two commits:

  1. introduce the callbacks
  2. make use of them when defining the actionHandler.

This pull request is a result of the discussion in #488

@azul azul force-pushed the callbacks branch 2 times, most recently from 44cd8d5 to 4acdf8f Compare May 11, 2020 12:18
@azul azul requested a review from skjnldsv May 11, 2020 12:21
src/views/Viewer.vue Outdated Show resolved Hide resolved
src/views/Viewer.vue Outdated Show resolved Hide resolved
@@ -222,7 +223,7 @@ export default {
if (path.trim() !== '') {
console.info('Opening viewer for file ', path)
this.openFile(path)
} else {
} else if (this.initiated) {
Copy link
Contributor Author

@azul azul May 12, 2020

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?

Copy link
Member

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!

Copy link
Contributor Author

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() 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.

Copy link
Contributor Author

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 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.

@azul azul mentioned this pull request Jun 19, 2020
6 tasks
@azul azul force-pushed the callbacks branch 3 times, most recently from 2464d5c to dc72592 Compare June 22, 2020 08:13
@azul
Copy link
Contributor Author

azul commented Jun 24, 2020

@skjnldsv If you could take another look... that would be great 😃

(added another commit fixing the double call of onClose callback.)

@skjnldsv
Copy link
Member

skjnldsv commented Jul 7, 2020

@skjnldsv If you could take another look... that would be great

Sorry, I'm overwhelmed since a few months! :(
I definitely did not forget about this pr :)
Thanks for the heads up!!

@skjnldsv skjnldsv added 2. developing Work in progress enhancement New feature or request labels Jul 7, 2020
@azul
Copy link
Contributor Author

azul commented Jul 7, 2020

Sorry, I'm overwhelmed since a few months! :(

That's what i was assuming. I know how it feels. Take your time. 🍵 🥰

src/views/Viewer.vue Outdated Show resolved Hide resolved
Comment on lines 93 to 94
* @param {string} path the path to open
* @param {Object[]} [list] the list of files as objects (fileinfo) format
Copy link
Member

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 🙈)

src/services/Viewer.js Outdated Show resolved Hide resolved
@skjnldsv
Copy link
Member

Please also rebase! :)
A few comments and reviews, let's try to get this in soon so you don't feel frustrated by the wait! 😉
Thanks again for your patience!! 🤗

@skjnldsv
Copy link
Member

Let's rebase, squash and get this in? :)

@azul
Copy link
Contributor Author

azul commented Jul 27, 2020

@skjnldsv I'm in a call right now. This is the next thing I'll work on.

@azul azul force-pushed the callbacks branch 2 times, most recently from c66416e to fd03cec Compare July 27, 2020 10:22
@azul
Copy link
Contributor Author

azul commented Jul 27, 2020

@skjnldsv I rebased and updated the jsdoc.
I'm not so familiar with jsdoc syntax. So please take a look if it's correct 👓
Shall I squash everything into a single commit?

@azul azul requested a review from skjnldsv July 27, 2020 10:24
@skjnldsv
Copy link
Member

skjnldsv commented Aug 1, 2020

Shall I squash everything into a single commit?

Yes please :)

@skjnldsv
Copy link
Member

skjnldsv commented Aug 1, 2020

Btw @azul , this also fixes #497, right?

@azul
Copy link
Contributor Author

azul commented Aug 2, 2020

✔️ squashed
✔️ rebased again

Btw @azul , this also fixes #497, right?

This is #497 - I tried to find the issue you meant to point at but did not see it.

@skjnldsv - ready to merge?

@skjnldsv
Copy link
Member

skjnldsv commented Aug 2, 2020

This is #497 - I tried to find the issue you meant to point at but did not see it.

sorry, #486 😁

@skjnldsv
Copy link
Member

skjnldsv commented Aug 2, 2020

/compile amend /

@skjnldsv skjnldsv added 4. to release Ready to be released and/or waiting for tests to finish and removed 2. developing Work in progress labels Aug 2, 2020
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>
@skjnldsv skjnldsv merged commit d2ee1fa into nextcloud:master Aug 2, 2020
@azul
Copy link
Contributor Author

azul commented Aug 2, 2020

@skjnldsv It's a first step towards solving #486. Now we add browser history entries for the files we navigate to. But the files app still needs a handler for dealing with clicks to the browser back button that make the viewer display the file. I'll work on that as one of the next things.

},

onNext(info, oldFileInfo) {
this.Viewer.onNext(oldFileInfo)
Copy link
Member

@skjnldsv skjnldsv Mar 30, 2021

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4. to release Ready to be released and/or waiting for tests to finish enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants