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 an option for users to use their browser's geolocation feature #520

Merged
merged 2 commits into from
Dec 12, 2023

Conversation

greg-does-weather
Copy link
Collaborator

What does this PR do? 🛠️

Adds a button users can click to use their browser's geolocation feature instead of typing in a location. The behavior is roughly as follows:

image

The idea is if the user has not already given us permission, we will first let them know we're going to ask for it and disclose how we'll use that information. Then we ask the browser, which will usually generate a browser-supplied prompt to allow/prevent.

Closes #184

What does the reviewer need to know? 🤔

make cc should do the job.

Screenshots (if appropriate): 📸

The location search component gets a new button:

Screenshot 2023-12-08 at 12-24-43 Welcome to Weather 2 0 Weather gov

The prompt if the user has not previously given us permission to use location:

Screenshot 2023-12-08 at 12 25 10 PM

@greg-does-weather
Copy link
Collaborator Author

@shadkeene @colinmurphy01 Especially interested in that kind of behavior flow above and whether that makes sense. If it's helpful, we can hop on a call and I can demo it so you get a feel for how it behaves.

@colinmurphy01
Copy link
Collaborator

Assigning to myself and will take a look next week

@colinmurphy01 colinmurphy01 self-assigned this Dec 8, 2023
@colinmurphy01
Copy link
Collaborator

@greg-does-weather makes sense to me.

Do all browsers support geolocation?

@colinmurphy01 colinmurphy01 removed their assignment Dec 11, 2023
@greg-does-weather
Copy link
Collaborator Author

Pretty much all browsers, yes: https://caniuse.com/?search=geolocation

And for those that don't, this code (should) hide the button.

Copy link
Collaborator

@eric-gade eric-gade left a comment

Choose a reason for hiding this comment

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

Code looks good 👍 -- just a couple of inline comments.

Also it looks like the JS confirm dialog does not appear in desktop Safari (the normal browser prompt does, however)

Code Review Checklist

This is an automated comment on every pull request requiring a review. A checked item is either an assertion that I have tested this item or an indication that I have verified it does not apply to this pull request.

The Basics

  • Checks are passing
  • I read the code
  • I ran the code
  • (if applicable) Post deploy steps are run
  • (if applicable) I validated the change on the deployed version in

Documentation

  • changes to “how we do things” are documented in READMEs
  • all new functions and methods are commented using plain language
  • any new modules added documented in modules.md

Security

  • security false positives are documented
  • data from external sources is cleaned and clearly marked

Reliability

  • error handling exists for unusual or missing values
  • interactions with external systems are wrapped in try/except
  • functionality is tested with unit or integration tests
  • dependency updates in composer.json also got changed in composer-lock.json

Infrastructure

  • all changes are auditable and documented via a script
  • it is clear who can and should run the script
  • (if applicable) diagrams have been updated or added in PlantUML

Accessibility

  • New pages have been added to cypress-axe file so that they will be tested with our automated accessibility testing
  • Meets WCAG 2.0 AA or 2.1 AA for Section 508 compliance
    • Site is keyboard accessible. All interactions can be accessed with a keyboard
    • Site is free of keyboard traps. The keyboard focus is never trapped in a loop
    • All form inputs have explicit labels
    • Form instructions are associated with inputs
    • All relevant images use an img tag
    • All images have appropriate alt attributes
    • Multimedia is tagged. All multimedia has appropriate captioning and audio description
    • Text has sufficient color contrast. All text has a contrast ratio of 4.5:1 with the background
    • Site never loses focus. Focus is always visible when moving through the page with the keyboard
    • Tab order is logical
    • Tables are coded properly. Tables have proper headers and column attributes
    • Headings are nested properly. Heading elements are nested in a logical way
    • Language is set. The language for the page is set
    • CSS is not required to use the page. The page makes sense with or without CSS
    • Links are unique and contextual. All links can be understood taken alone, e.g., ‘Read more - about 508’
    • Page titles are descriptive

Device Matrix

  • firefox/gecko (renders correctly and user interactions work)
  • chrome/chromium/edge (renders correctly and user interactions work)
  • safari/webkit (renders correctly and user interactions work)
  • web page is readable and usable
    • at 480px (mobile)
    • at 640px (tablet)
    • at 1024px (desktop)

Comment on lines 108 to 115
({ code }) => {
if (code > 1) {
// There was a problem getting the user's location. They allowed it,
// but the browser gave us an error.
// (Error code 1 is for when the user denies access to location, so
// for our purposes, that is not an error.)
}
},
Copy link
Collaborator

Choose a reason for hiding this comment

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

My $0.02 is that in this case, the end user should be informed of this failure somehow (even if it's just an alert() for now)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ooh, good call! I'll add that in.

Comment on lines +1 to +6
const goToLocationPage = (latitude, longitude) => {
// Push the next URL into the history to preserve the current URL in the
// browser history stack.
window.history.pushState(null, null, `/point/${latitude}/${longitude}`);
window.location.href = `/point/${latitude}/${longitude}`;
};
Copy link
Collaborator

Choose a reason for hiding this comment

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

We might have a chance to spare the server some requests at this point if we make the API call from points -> WFO&grid from the browser instead, and navigating to the actual forecast page from there. Of course, that involves making API requests from the browser for the first time in this application, which is the main tradeoff.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm not opposed. Especially since the server is going to make the call to the /points endpoint again anyway to get the place name. (It's very silly...)

@greg-does-weather
Copy link
Collaborator Author

greg-does-weather commented Dec 11, 2023

I'd like to see if I can figure out what's happening in Safari before merging. It feels minor, but at the same time, we don't really want different user experiences based on browser, to the extent we can prevent it.

@greg-does-weather
Copy link
Collaborator Author

Hrm. I couldn't reproduce the weirdness in Safari desktop. 😕 But still, I added code to pass location errors directly to users for now. As you said, we'll want to revisit it later, but this'll get us going.

Screen.Recording.2023-12-12.at.2.49.21.PM.mov

@greg-does-weather greg-does-weather added this pull request to the merge queue Dec 12, 2023
Merged via the queue into main with commit f3e6390 Dec 12, 2023
8 checks passed
@greg-does-weather greg-does-weather deleted the mgwalker/184-browser-location branch December 12, 2023 21:08
@colinmurphy01
Copy link
Collaborator

@greg-does-weather can you demo this on Friday?

@mgwalker
Copy link
Contributor

Yep

This pull request was closed.
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.

e2.v2 browser location
4 participants