-
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.
feat(SearchResultsByCategory): Group all vehicle results into a singl…
…e category (#2168) * feat(SearchPageState): Add categoryResultLimits field This will replace the properties field * feat(SearchResultsByCategory): Group all vehicle results into a single category * feat: Update default search result limit * style(searchPageState.test): Remove blank line * Update assets/tests/components/mapPage/searchResultsByCategory.test.tsx Co-authored-by: Kayla Firestack <firestack@users.noreply.github.com> --------- Co-authored-by: Kayla Firestack <firestack@users.noreply.github.com>
- Loading branch information
1 parent
f177d8f
commit 6a91ed3
Showing
15 changed files
with
321 additions
and
304 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
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,66 @@ | ||
import { Socket } from "phoenix" | ||
import { | ||
CategoryResultLimits, | ||
SearchPropertyQuery, | ||
} from "../models/searchQuery" | ||
import { Loading, Ok } from "../util/fetchResult" | ||
import { | ||
LimitedSearchResults, | ||
useLimitedSearchResults, | ||
} from "./useSearchResults" | ||
import { useLocationSearchResults } from "./useLocationSearchResults" | ||
import { LocationSearchResult } from "../models/locationSearchResult" | ||
import { Vehicle, Ghost } from "../realtime" | ||
|
||
export type VehicleResultType = | ||
| Ok<LimitedSearchResults<Vehicle | Ghost>> | ||
| Loading | ||
| null | ||
|
||
type LocationResultsType = | ||
| Ok<LimitedSearchResults<LocationSearchResult>> | ||
| Loading | ||
| null | ||
|
||
export type SearchResultsByCategory = { | ||
vehicle: VehicleResultType | ||
location: LocationResultsType | ||
} | ||
|
||
const useSearchResultsByCategory = ( | ||
socket: Socket | undefined, | ||
text: string, | ||
queryType: SearchPropertyQuery, | ||
categoryLimits: CategoryResultLimits | ||
): SearchResultsByCategory => { | ||
// To avoid conditionally calling hooks, call hook to fetch results for each property, conditionally passing null | ||
// param when the property limit is null so that no results will actually be fetched & returned. | ||
const shouldSearchLocation = queryType === "all" || queryType === "location" | ||
const shouldSearchVehicles = queryType === "all" || queryType !== "location" | ||
const rawLocationResults = useLocationSearchResults( | ||
(shouldSearchLocation && text) || null | ||
) | ||
|
||
const limitedLocationResults: LocationResultsType = !shouldSearchLocation | ||
? null | ||
: (rawLocationResults && { | ||
ok: { | ||
matches: rawLocationResults.slice(0, categoryLimits.location), | ||
hasMoreMatches: rawLocationResults.length > categoryLimits.location, | ||
}, | ||
}) || { is_loading: true } | ||
return { | ||
vehicle: useLimitedSearchResults( | ||
socket, | ||
(shouldSearchVehicles && { | ||
property: queryType, | ||
text: text, | ||
limit: categoryLimits.vehicle, | ||
}) || | ||
null | ||
), | ||
location: limitedLocationResults, | ||
} | ||
} | ||
|
||
export default useSearchResultsByCategory |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.