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

Simplify dialog navigation to fix back button #23220

Merged
merged 5 commits into from
Dec 10, 2024
Merged

Simplify dialog navigation to fix back button #23220

merged 5 commits into from
Dec 10, 2024

Conversation

MindFreeze
Copy link
Contributor

@MindFreeze MindFreeze commented Dec 9, 2024

Proposed change

Removed replaceDialog and all related logic as it is not used anywhere. @bramkragten correct me if this is wrong but I couldn't find anything using it.
This allowed me to simplify the history management logic for dialogs and fix back button issues.
Multiple modals on top of each other work well now. Esc closes all dialogs but this is managed by the dialogs themselves via the escapeKeyAction attribute. An example of this is a siren with advanced options in the more-info dialog.

Browser history was too limiting to do what we wanted. Only access to current state, no callbacks in the state, etc. So the dialog states are now managed in a stack inside make-dialog-manager.ts and only a single state is pushed to the browser history.
Going forward in history will not open a dialog anymore as it made no sense in most cases.

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New feature (thank you!)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Example configuration

Additional information

Checklist

  • The code change is tested and works locally.
  • There is no commented out code in this PR.
  • Tests have been added to verify that the new code works.

If user exposed functionality or configuration variables are added/changed:

@MindFreeze MindFreeze added WTH Issues & PRs generated from the "Month of What the Heck?" Bug Fix labels Dec 9, 2024
@bramkragten bramkragten self-requested a review December 9, 2024 14:52
@MindFreeze MindFreeze marked this pull request as draft December 9, 2024 16:13
@MindFreeze
Copy link
Contributor Author

Still have some work to do on alerts. The back button should work on them as well I guess

@MindFreeze MindFreeze marked this pull request as ready for review December 10, 2024 08:30
@MindFreeze
Copy link
Contributor Author

Alright, I think it's in a pretty good state now. Ideally the urlSyncMixin shouldn't have anything to do with the dialogs but we still need it to add the popstate listener

if ("dialog" in ev.state) {
// coming to a dialog
// in practice the dialog stack is empty when navigating forward, so this is a no-op
showDialogFromHistory(ev.state.dialog);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not really a no-op, as it will trigger a history.back (causing the forward button to be enabled again) that will then trigger a closeLastDialog which will no-op

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I meant to say nothing will happen from a user perspective but no-op was shorter :D

@MindFreeze MindFreeze merged commit ed625d4 into dev Dec 10, 2024
15 checks passed
@MindFreeze MindFreeze deleted the fix_back_btn branch December 10, 2024 11:26
@piitaya piitaya mentioned this pull request Dec 11, 2024
9 tasks
boern99 pushed a commit to boern99/ha_frontend that referenced this pull request Dec 11, 2024
* Simplify dialog navigation to fix back btn

* add back comment

* manage dialog stack in the manager instead of history

* handle dialogs that refuse to close
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Fix cla-signed WTH Issues & PRs generated from the "Month of What the Heck?"
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Back Button doesn't work Back arrow in settings doesn't play nice with device windows
2 participants