Skip to content

Commit

Permalink
fix(location): Make it so distance select is grayed out when a valid …
Browse files Browse the repository at this point in the history
…location hasn't been entered
  • Loading branch information
devcshort committed Sep 25, 2024
1 parent 35ecf0e commit 66544f4
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/shared/components/search/distance-select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,24 @@ import {
} from '../ui/select';
import { useAppConfig } from '../../hooks/use-app-config';
import { useAtomValue, useSetAtom } from 'jotai';
import { searchAtom, searchDistanceAtom } from '../../store/search';
import {
searchAtom,
searchDistanceAtom,
searchLocationAtom,
userCoordinatesAtom,
} from '../../store/search';
import { setCookie } from 'nookies';
import { USER_PREF_DISTANCE } from '../../lib/constants';

export function DistanceSelect() {
const { t } = useTranslation();
const appConfig = useAppConfig();
const setSearch = useSetAtom(searchAtom);
const coords = useAtomValue(userCoordinatesAtom);
const distance = useAtomValue(searchDistanceAtom);

const hasLocation = coords?.length == 2;

const setDistance = (value) => {
setCookie(null, USER_PREF_DISTANCE, value, { path: '/' });
setSearch((prev) => ({
Expand All @@ -29,7 +37,11 @@ export function DistanceSelect() {
};

return (
<Select onValueChange={setDistance} value={distance}>
<Select
onValueChange={setDistance}
value={distance}
disabled={!hasLocation}
>
<SelectTrigger className="w-[125px]">
<SelectValue
placeholder={t('search.radius_placeholder', {
Expand Down

0 comments on commit 66544f4

Please sign in to comment.