-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Groundwork for search by location (#2158)
* chore: models for location result data and results * chore: make API call to get location search results * fix: correct return format of search and suggest functions * test: factories for location result * feat: useLoationSearchResults hook * feat: provide logic to separate out location results * refactor: change argument type of useLocationSearchResults * feat: basic list display of location search results * feat: put location search results in cards * test: basic tests for showing locations in new search * refactor: make way for selecting locations * refactor: remove unneeded single underscore variable * feat: locations can be selected entities, not shown on map yet * feat: parse ID into location object on frontend * test: ensure show more button doesn't show up with <= 5 results * refactor: better naming of selection handler callbacks
- Loading branch information
Showing
16 changed files
with
568 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { useEffect, useState } from "react" | ||
import { fetchLocationSearchResults } from "../api" | ||
import { LocationSearchResult } from "../models/locationSearchResult" | ||
|
||
export const useLocationSearchResults = ( | ||
text: string | null | ||
): LocationSearchResult[] | null => { | ||
const [searchResults, setSearchResults] = useState< | ||
LocationSearchResult[] | null | ||
>(null) | ||
|
||
useEffect(() => { | ||
let shouldUpdate = true | ||
|
||
if (text) { | ||
fetchLocationSearchResults(text).then((results) => { | ||
if (shouldUpdate) { | ||
setSearchResults(results) | ||
} | ||
}) | ||
} else { | ||
setSearchResults(null) | ||
} | ||
|
||
return () => { | ||
shouldUpdate = false | ||
} | ||
}, [text]) | ||
|
||
return searchResults | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export interface LocationSearchResult { | ||
id: string | ||
name: string | null | ||
address: string | ||
latitude: number | ||
longitude: number | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { Infer, nullable, number, string, type } from "superstruct" | ||
import { LocationSearchResult } from "./locationSearchResult" | ||
|
||
export const LocationSearchResultData = type({ | ||
id: string(), | ||
name: nullable(string()), | ||
address: string(), | ||
latitude: number(), | ||
longitude: number(), | ||
}) | ||
export type LocationSearchResultData = Infer<typeof LocationSearchResultData> | ||
|
||
export const locationSearchResultFromData = ({ | ||
id, | ||
name, | ||
address, | ||
latitude, | ||
longitude, | ||
}: LocationSearchResultData): LocationSearchResult => ({ | ||
id, | ||
name, | ||
address, | ||
latitude, | ||
longitude, | ||
}) | ||
|
||
export const locationSearchResultsFromData = ( | ||
locationSearchResultsData: LocationSearchResultData[] | ||
): LocationSearchResult[] => | ||
locationSearchResultsData.map(locationSearchResultFromData) |
Oops, something went wrong.