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

Reset state to inline-open when speaker note popup is closed #1441

Merged
merged 3 commits into from
Nov 16, 2023

Conversation

elliotbrandwein
Copy link
Contributor

@elliotbrandwein elliotbrandwein commented Oct 31, 2023

Partially addresses #182.

@mgeisler mgeisler changed the title fix issue #182 Reset state to inline-open when speaker note popup is closed Oct 31, 2023
@mgeisler
Copy link
Collaborator

Hi @elliotbrandwein, thanks for the PR!

I tried a few things to get this working back when I implemented it: and I ran into a lot of weird restrictions on when one can use the onbeforeunload event...

Your solution works okay until you navigate away from the page that opened the popup window. The two windows are synchronized, but after navigating forward or backward in either window, the unload event no longer triggers and so the state isn't reset.

My understanding is that browsers basically refuse to implement this according to spec because of spammy popup windows.

@elliotbrandwein
Copy link
Contributor Author

elliotbrandwein commented Nov 1, 2023

Hi @elliotbrandwein, thanks for the PR!

I tried a few things to get this working back when I implemented it: and I ran into a lot of weird restrictions on when one can use the onbeforeunload event...

Your solution works okay until you navigate away from the page that opened the popup window. The two windows are synchronized, but after navigating forward or backward in either window, the unload event no longer triggers and so the state isn't reset.

My understanding is that browsers basically refuse to implement this according to spec because of spammy popup windows.

I see. at this point i might be dipping into #1232 but i can see the fix for this issue being that i build a speaker notes state system that keeps track of the page of the speaker notes & if the popup is active or not. If you dont mind feature creep I can implement that into this pr

@mgeisler
Copy link
Collaborator

mgeisler commented Nov 2, 2023

If you dont mind feature creep I can implement that into this pr

That would be wonderful actually! I've been waiting for someone with enough JavaScript skills to come and help out 😅

@randomPoison randomPoison added the waiting for author Waiting on the issue author to reply label Nov 7, 2023
@moaminsharifi
Copy link
Collaborator

Do you need help on this?
@elliotbrandwein @mgeisler

@mgeisler
Copy link
Collaborator

Hey @moaminsharifi, I would be happy to get help here 😄

@moaminsharifi
Copy link
Collaborator

After checking JS window documentation, My idea due to current system which is mostly based on pure js and not any webframe work is make it something like SPA-ish:

1- Disable navigation links' default behavior (using the css selector of a.mobile-nav-chapters)

2- when user clicks on navigation links , we use fetch module of browser to get all html content and render it

  • We need to render the sidebar
  • We need to render the content part
  • We need to check if popup open then render that part ( and if user click in popup then update main window)

https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API
https://www.w3schools.com/jsref/met_doc_write.asp

3- check URL in browser with JS.

https://stackoverflow.com/questions/824349/how-do-i-modify-the-url-without-reloading-the-page

I want to know I much I can modify in js part? like adding new js lib is ok? @mgeisler

@elliotbrandwein
Copy link
Contributor Author

After checking JS window documentation, My idea due to current system which is mostly based on pure js and not any webframe work is make it something like SPA-ish:

1- Disable navigation links' default behavior (using the css selector of a.mobile-nav-chapters)

2- when user clicks on navigation links , we use fetch module of browser to get all html content and render it

  • We need to render the sidebar
  • We need to render the content part
  • We need to check if popup open then render that part ( and if user click in popup then update main window)

https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API
https://www.w3schools.com/jsref/met_doc_write.asp

3- check URL in browser with JS.

https://stackoverflow.com/questions/824349/how-do-i-modify-the-url-without-reloading-the-page

I want to know I much I can modify in js part? like adding new js lib is ok? @mgeisler

That definitely works to solve the ticket here but for the issue at hand of the main tab not getting the signal that the notes tab closed we still need to solve for.

My thinking is that since onbeforeunload isn't reliable we use localStorage and a storage listener to trigger the logic for when the popup tab is open/closed.

That being this fix would have to wait until after you create the new tab lib, or it would need to be redone as part of your cl.

@mgeisler
Copy link
Collaborator

I want to know I much I can modify in js part? like adding new js lib is ok? @mgeisler

Hi @moaminsharifi, I would be fine with that — we don't have any particular limitations for for this, apart that the result should be maintainable and load fast, etc 🙂

My thinking is that since onbeforeunload isn't reliable we use localStorage and a storage listener to trigger the logic for when the popup tab is open/closed.

I might have tried this, but I'm not sure! It's nearly a year since I played around with this, so I'm really appreciating someone new taking a look at this with fresh eyes!

@moaminsharifi
Copy link
Collaborator

I want to know I much I can modify in js part? like adding new js lib is ok? @mgeisler

Hi @moaminsharifi, I would be fine with that — we don't have any particular limitations for for this, apart that the result should be maintainable and load fast, etc 🙂

My thinking is that since onbeforeunload isn't reliable we use localStorage and a storage listener to trigger the logic for when the popup tab is open/closed.

I might have tried this, but I'm not sure! It's nearly a year since I played around with this, so I'm really appreciating someone new taking a look at this with fresh eyes!

It will be my pleasure to contribute in whatever way I can to the improvement of this book. I have other ideas to make this part better for both teachers and students besides my comments here.

@mgeisler I'll work on it in my local branch https://github.com/moaminsharifi/comprehensive-rust/tree/fixture-pop-up-close-issue

@mgeisler
Copy link
Collaborator

@elliotbrandwein, since I think the change here does improve the situation in some cases, we can merge the PR if you like? Then you and @moaminsharifi could discuss a better long-term solution (if one exists 😄). That way we can stop discussing on the PR and collect our thoughts in concrete issues instead.

@elliotbrandwein
Copy link
Contributor Author

updated the format of the pr so it should (hopefully) pass the pre submits and get merged

@mgeisler mgeisler enabled auto-merge (squash) November 16, 2023 11:42
@mgeisler
Copy link
Collaborator

updated the format of the pr so it should (hopefully) pass the pre submits and get merged

Thanks @elliotbrandwein! I hope you and @moaminsharifi can come up with some good solution for the general problem of syncing the state.

@mgeisler mgeisler merged commit 6624c58 into google:main Nov 16, 2023
31 checks passed
@elliotbrandwein elliotbrandwein deleted the elliot branch November 21, 2023 15:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
waiting for author Waiting on the issue author to reply
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants