import {ReactNode} from 'react'; import type {LatLngExpression} from 'leaflet'; import {create} from 'zustand'; import {TravelEntity} from '../generated/graphql'; type State = { map?: any; markers: Array; focusedTravel?: string; bounds: Array; setMap: (map: any) => void; setMarkers: (markers: Array) => void; setFocusOnTravel: (travel?: TravelEntity) => void; setBounds: (bounds: Array) => void; }; const useMapStore = create((set, get) => ({ map: undefined, markers: [], focusedTravel: undefined, bounds: [], setMap: map => set({map}), setMarkers: markers => set({markers}), setFocusOnTravel: travel => { const currentFocusId = get().focusedTravel; if (!travel || travel.id === currentFocusId) set({focusedTravel: undefined}); else { set({focusedTravel: travel.id}); const lat = travel.attributes?.meeting_latitude; const long = travel.attributes?.meeting_longitude; if (lat && long) get().map?.panTo([lat, long]); } }, setBounds: bounds => { set({bounds}); }, })); export default useMapStore;