Skip to content

Commit

Permalink
Merge pull request #325 from hackforla/client/location-sort
Browse files Browse the repository at this point in the history
sort locations by name when userLocation not given
  • Loading branch information
jmensch1 authored Dec 19, 2020
2 parents 5d45371 + 2dd7dbe commit 0f371d4
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions client/web/src/store/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,14 @@ const geocodedLocations = createSelector([locations], (locations) => {

/*
Adds a 'distanceFromUser' property to each geocoded location and sorts
the locations by distance.
the locations by distance. If userLocation not given, sorts by location
name.
*/
export const sortedLocations = createSelector(
[geocodedLocations, userLocation],
(locations, userLocation) => {
if (!userLocation) return locations
if (!userLocation)
return locations.slice().sort((a, b) => (a.name > b.name ? 1 : -1))

return locations
.map((loc) => ({
Expand Down

0 comments on commit 0f371d4

Please sign in to comment.