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

Share Dialog with QR Code #729

Merged
merged 7 commits into from
May 16, 2023
Merged

Conversation

mjaschen
Copy link
Contributor

@mjaschen mjaschen commented May 6, 2023

This pull-request implements sharing a route by QRCode, external services or by using the clipboard

  • add a new button "Share" to the main navigation
  • when clicked, a new modal dialog opens and shows share options for the planned route, which are currently:
    • a button to copy the URL of the current route to the clipboard
    • share buttons for 3rd party services, such as Facebook, Whatsapp, Email (and Mastodon, but currently disabled via config1)
    • a QRCode
  • the QRCode is a representation of the current route (i.e. the current URL) with an added query parameter to the URL: ?export=dialog
  • when BRouter-Web is loaded with the export=dialog query parameter, the export dialog is shown instantly (as discussed in Export GPX Route via QR Code #370)
    • using a query parameter (export) and a value (dialog) instead of only a paramater is required, because URLSearchParams needs both when adding a new parameter
    • we've the opportunity to add further options in the future (download, gpx etc.)
  • add a new keyboard shortcut 'A' (“action”) which opens the share dialog (would have used 'S', but that's already taken)
  • add 3rd-party QRCode library
  • add URLSearchParams polyfill for ancient browsers as Husky didn't allow me to commit otherwise …
  • add license information to README
  • TODO: Translations

Footnotes

  1. Mastodon instances respond with HTTP 502 when the submitted text (= the route URL in our case) is longer than the maximum post character limit on that instance. That will probably confuse users. I decided to keep the code here as this bug will probably be fixed in the future.

- when clicked, a new modal dialog opens and shows share options for the planned route, which are currently:
  - a button to copy the URL of the current route to the clipboard
  - share buttons for 3rd party services, such as Facebook, Whatsapp, Email (and Mastodon, but currently disabled via config[^1])
  - a QRCode
- the QRCode is a representation of the current route (i.e. the current URL) with an added query parameter to the URL: `?export=dialog`
- when BRouter-Web is loaded with the `export=dialog` query parameter, the export dialog is shown instantly (as discussed in nrenner#370)
  - using a query parameter (`export`) and a value (`dialog`) instead of only a paramater is required, because `URLSearchParams` needs both when adding a new parameter
  - we've the opportunity to add further options in the future (`download`, `gpx` etc.)
- add a new keyboard shortcut 'A' (“action”) which opens the share dialog (would have used 'S', but that's already taken)
- add 3rd-party QRCode library
- add `URLSearchParams` polyfill for ancient browsers as Husky didn't allow me to commit otherwise …
- add license information to README

[^1]: Mastodon instances respond with HTTP 502 when the submitted text (= the route URL in our case) is longer than the maximum post character limit on that instance. That will probably confuse users. I decided to keep the code here as this bug will probably be fixed in the future.
Copy link
Owner

@nrenner nrenner left a comment

Choose a reason for hiding this comment

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

Thanks for the PR, nice!

The url-search-params-polyfill isn't needed, as a URLSearchParams polyfill is already included in core-js. The added entry in .eslintrc.json is enough in this case, to make it stop complaining. That's just a manual checklist, it can't automatically detect missing polyfills.

There is an error on download when sharing a single route point, I would suggest to add an additional check before opening the export dialog, probably like if (routing.getWaypoints().length < 2) as in Export.update.

},

/**
* Renders QR Code for the currect route:
Copy link
Owner

Choose a reason for hiding this comment

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

currect -> current?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good catch ;-)

/**
* Renders QR Code for the currect route:
*
* - hides the export modal dialog (QR Code is shown in a new dialog)
Copy link
Owner

Choose a reason for hiding this comment

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

doesn't apply to current implementation anymore?

Copy link
Contributor Author

@mjaschen mjaschen May 14, 2023

Choose a reason for hiding this comment

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

No, of course not. I've updated this doc block.

@mjaschen
Copy link
Contributor Author

mjaschen commented May 14, 2023

  • I've added a check so that the button is enabled only if at least 2 route points are set.
  • URLSearchParams polyfill was removed.
  • the share icon in the navbar was changed to a nicer one.

@nrenner
Copy link
Owner

nrenner commented May 15, 2023

I've added a check so that the button is enabled only if at least 2 route points are set.

No strong opinions, we can merge as is, but there might be use cases where it makes sense to only share the current map view or a single route point. Therefore I meant to still allow sharing, just not to open the export dialog at the receiving end by adding that check to index.js.

Don't know if my comment was misleading or if you prefer to disable the share dialog instead?

@mjaschen
Copy link
Contributor Author

Just a misunderstanding – you're absolutely right. I'll push an update later.

…t dialog after opening QR Code URL if the route consists of less than 2 waypoints
@nrenner nrenner merged commit 3b3357c into nrenner:master May 16, 2023
@nrenner
Copy link
Owner

nrenner commented May 16, 2023

Thanks!

nrenner added a commit that referenced this pull request May 16, 2023
to only check once on init, not on every update. Waypoints available at time of callback. Add check for lonlats param as event isn't called without and error check.
nrenner added a commit that referenced this pull request May 19, 2023
@mjaschen mjaschen deleted the feature/share-dialog branch June 2, 2023 05:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants