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

fix(search): Repeat city searching now working #1134

Merged
merged 8 commits into from
Mar 6, 2024
45 changes: 24 additions & 21 deletions packages/ui/components/core/SearchBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ import { useSearchState } from '~ui/hooks/useSearchState'
import { Icon } from '~ui/icon'
import { trpc as api } from '~ui/lib/trpcClient'

const DEFAULT_RADIUS = 200
const DEFAULT_UNIT = 'mi'

const useStyles = createStyles((theme) => ({
autocompleteContainer: {
width: '100%',
Expand Down Expand Up @@ -201,30 +204,30 @@ export const SearchBox = ({
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [autocompleteData, autocompleteLoading, search, isOrgSearch, orgSearchData, orgSearchLoading])

api.geo.geoByPlaceId.useQuery(locationSearch, {
const { data: locationResult } = api.geo.geoByPlaceId.useQuery(locationSearch, {
enabled: notBlank(locationSearch) && !isOrgSearch,
onSuccess: (data) => {
const DEFAULT_RADIUS = 200
const DEFAULT_UNIT = 'mi'
if (!data.result) return
const params = SearchParamsSchema.safeParse([
data.result.country,
data.result.geometry.location.lng,
data.result.geometry.location.lat,
DEFAULT_RADIUS,
DEFAULT_UNIT,
])
if (!params.success) return
router.push({
pathname: '/search/[...params]',
query: {
params: params.data.map((val) => val.toString()),
},
})
setLoading(false)
},
})

useEffect(() => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes sense

if (!locationResult?.result) return
const params = SearchParamsSchema.safeParse([
locationResult.result.country,
locationResult.result.geometry.location.lng,
locationResult.result.geometry.location.lat,
DEFAULT_RADIUS,
DEFAULT_UNIT,
])
if (!params.success) return
router.push({
pathname: '/search/[...params]',
query: {
params: params.data.map((val) => val.toString()),
},
})
setLoading(false)
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [locationResult])

const rightIcon =
isLoading || searchLoading ? (
<Group>
Expand Down
Loading