-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into pv-dependabot-fixes
- Loading branch information
Showing
84 changed files
with
1,662 additions
and
600 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
.env | ||
.env.production |
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 @@ | ||
export const SHELTERS_MAP_ID = 'shelters-map'; |
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 @@ | ||
export const SHELTERS_MAP_ID = 'ba-shelters-map'; |
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 |
---|---|---|
@@ -1,29 +1,50 @@ | ||
import { APIProvider as MapsApiProvider } from '@vis.gl/react-google-maps'; | ||
import { useState } from 'react'; | ||
import { useAtom } from 'jotai'; | ||
import { useEffect, useState } from 'react'; | ||
import { SHELTERS_MAP_ID } from '../../constants.app'; | ||
import { MaxWLayout } from '../../layout/maxWLayout'; | ||
import { Map } from '../../shared/components/maps/map'; | ||
import { TLatLng } from '../../shared/components/maps/types.maps'; | ||
import { locationAtom } from '../../shared/atoms/locationAtom'; | ||
import { sheltersAtom } from '../../shared/atoms/sheltersAtom'; | ||
import { Map } from '../../shared/components/map/map'; | ||
import { TLatLng, TMarker } from '../../shared/components/map/types.maps'; | ||
import { ShelterSearch } from '../../shared/components/shelters/shelterSearch'; | ||
|
||
const googleMapsApiKey = import.meta.env.VITE_GOOGLE_MAPS_API_KEY; | ||
|
||
export function Home() { | ||
const [coordinates, setCoordinates] = useState<TLatLng | null>(); | ||
const [_location, setLocation] = useAtom(locationAtom); | ||
const [shelters] = useAtom(sheltersAtom); | ||
const [shelterMarkers, setShelterMarkers] = useState<TMarker[]>([]); | ||
|
||
function onProviderError(error: unknown) { | ||
console.error(`MapsApiProvider error ${error}`); | ||
} | ||
useEffect(() => { | ||
const markers = shelters | ||
.filter((shelter) => !!shelter.location) | ||
.map((shelter) => { | ||
return { | ||
id: shelter.id, | ||
position: shelter.location, | ||
label: shelter.name, | ||
} as TMarker; | ||
}); | ||
|
||
setShelterMarkers(markers); | ||
}, [shelters]); | ||
|
||
function onLocationChange(coordinates: TLatLng | null) { | ||
setCoordinates(coordinates); | ||
function onCenterSelect(center: TLatLng) { | ||
setLocation({ | ||
...center, | ||
source: 'currentLocation', | ||
}); | ||
} | ||
|
||
return ( | ||
<MapsApiProvider apiKey={googleMapsApiKey} onError={onProviderError}> | ||
<> | ||
<MaxWLayout className="-mx-4"> | ||
<Map className="h-[480px] md:h-80" center={coordinates} /> | ||
<Map | ||
className="h-[70vh] md:h-80" | ||
mapId={SHELTERS_MAP_ID} | ||
markers={shelterMarkers} | ||
onCenterSelect={onCenterSelect} | ||
/> | ||
</MaxWLayout> | ||
<ShelterSearch onLocationChange={onLocationChange} /> | ||
</MapsApiProvider> | ||
<ShelterSearch /> | ||
</> | ||
); | ||
} |
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,10 @@ | ||
import { atom } from 'jotai'; | ||
import { TLatLng } from '../components/map/types.maps'; | ||
|
||
export type TLocationSource = 'currentLocation' | 'address'; | ||
|
||
export interface TLocation extends TLatLng { | ||
source: TLocationSource; | ||
} | ||
|
||
export const locationAtom = atom<TLocation | null | undefined>(undefined); |
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,4 @@ | ||
import { atom } from 'jotai'; | ||
import { TShelter } from '../components/shelter/shelterCard'; | ||
|
||
export const sheltersAtom = atom<TShelter[]>([]); |
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
103 changes: 0 additions & 103 deletions
103
apps/shelter-web/src/app/shared/components/currentLocation.tsx
This file was deleted.
Oops, something went wrong.
72 changes: 72 additions & 0 deletions
72
apps/shelter-web/src/app/shared/components/currentLocation/currentLocation.tsx
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,72 @@ | ||
import { PropsWithChildren } from 'react'; | ||
import { mergeCss } from '../../utils/styles/mergeCss'; | ||
import { TLatLng } from '../map/types.maps'; | ||
import { | ||
GeolocationErrorKey, | ||
TLocationError, | ||
getGeolocationErrorName, | ||
} from './currentLocationError'; | ||
|
||
const POSITION_TIMEOUT_MS = 20 * 1000; | ||
|
||
interface ICurrentLocation extends PropsWithChildren { | ||
onChange: (location: TLatLng) => void; | ||
onError: (error: TLocationError) => void; | ||
className?: string; | ||
timeout?: number; | ||
} | ||
|
||
export function CurrentLocation(props: ICurrentLocation) { | ||
const { | ||
onChange, | ||
onError, | ||
timeout = POSITION_TIMEOUT_MS, | ||
className, | ||
children, | ||
} = props; | ||
|
||
if (!navigator.geolocation) { | ||
onError && onError('FEATURE_UNAVAILABLE'); | ||
|
||
return null; | ||
} | ||
|
||
const onLocationSuccess = (position: GeolocationPosition): void => { | ||
onChange && | ||
onChange({ | ||
latitude: position.coords.latitude, | ||
longitude: position.coords.longitude, | ||
}); | ||
}; | ||
|
||
const onLocationError = (err: GeolocationPositionError): void => { | ||
onError && | ||
onError(getGeolocationErrorName(err.code as GeolocationErrorKey)); | ||
}; | ||
|
||
const getLocation = (): void => { | ||
const options: PositionOptions = { | ||
enableHighAccuracy: true, | ||
timeout, // error out if takes longer | ||
maximumAge: 0, | ||
}; | ||
|
||
navigator.geolocation.getCurrentPosition( | ||
onLocationSuccess, | ||
onLocationError, | ||
options | ||
); | ||
}; | ||
|
||
if (!children) { | ||
return null; | ||
} | ||
|
||
const btnCss = ['w-full', 'h-full', className]; | ||
|
||
return ( | ||
<button className={mergeCss(btnCss)} onClick={getLocation}> | ||
{children} | ||
</button> | ||
); | ||
} |
20 changes: 20 additions & 0 deletions
20
apps/shelter-web/src/app/shared/components/currentLocation/currentLocationError.ts
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,20 @@ | ||
export type TLocationError = | ||
| 'PERMISSION_DENIED' | ||
| 'POSITION_UNAVAILABLE' | ||
| 'TIMEOUT' | ||
| 'FEATURE_UNAVAILABLE' | ||
| 'UNKNOWN'; | ||
|
||
const GeolocationErrorNameMap = { | ||
1: 'PERMISSION_DENIED', | ||
2: 'POSITION_UNAVAILABLE', | ||
3: 'TIMEOUT', | ||
} as const; | ||
|
||
export type GeolocationErrorKey = keyof typeof GeolocationErrorNameMap; | ||
|
||
export function getGeolocationErrorName( | ||
errorCode: GeolocationErrorKey | ||
): TLocationError { | ||
return GeolocationErrorNameMap[errorCode]; | ||
} |
10 changes: 10 additions & 0 deletions
10
apps/shelter-web/src/app/shared/components/map/constants.maps.ts
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,10 @@ | ||
import { TLatLng } from './types.maps'; | ||
|
||
export const MILES_TO_DEGREES_AT_EQUATOR = 69.172; | ||
export const DEFAULT_BOUNDS_MILES = 2; | ||
export const LA_COUNTY_CENTER: TLatLng = { | ||
latitude: 34.04499, | ||
longitude: -118.251601, | ||
}; | ||
export const DEFAULT_MAP_ZOOM = 13; | ||
export const DEFAULT_GESTURE_HANDLING = 'greedy'; |
Oops, something went wrong.