calblueprint / dccentralkitchen

Customer mobile app and rewards program for DC Central Kitchen's Healthy Corners initiative
https://dccentralkitchen.org/HealthyCornersApp
GNU General Public License v3.0
9 stars 4 forks source link

Refactor MapScreen to functional component #184

Closed wangannie closed 3 years ago

wangannie commented 3 years ago

What's new in this PR

The new MapScreen flow:

  1. useCurrentLocation prompts the user for location access and if granted, it sets the user's location incurrentLocation (otherwise null). Location permission status is saved in locationPermissions as either 'granted', 'denied', or 'error'
  2. useStores loads the list of stores from Airtable, not in any sorted order.
  3. Store distance calculations and sorting happen directly since they are neither async nor expensive. The sorted store list (with the added distance attribute) is passed into StoreListScreen and to other store-related components that reference distance.
  4. Once stores and location permissions are loaded, a useEffect sets the initial currentStore to focus on.
  5. useStoreProducts loads the products for currentStore, refreshing whenever currentStore is updated.

Other misc. changes

Relevant Links

Online sources

https://reactjs.org/docs/hooks-custom.html https://www.robinwieruch.de/react-hooks-fetch-data https://reactjs.org/docs/thinking-in-react.html

Next steps

Screenshots

Here's how it loads AFTER this refactor. SO MUCH FASTER! https://www.loom.com/share/090a25122bcd44a09e5960f2893b083e