@@ -29,6 +29,8 @@ import {
2929 useSearchCoordinates ,
3030 useSelectedOrganization ,
3131 useUserCoordinates ,
32+ useOrgNameFilter ,
33+ useOpenTimeFilter
3234} from "../../../../appReducer" ;
3335import { useMapbox } from "../../../../hooks/useMapbox" ;
3436import AdvancedFilters from "../AdvancedFilters/AdvancedFilters" ;
@@ -47,11 +49,13 @@ import {
4749} from "constants/stakeholder" ;
4850import debounceFn from "debounce-fn" ;
4951
50- const ResultsMap = ( { stakeholders, categoryIds, toggleCategory, loading } ) => {
52+ const ResultsMap = ( { stakeholders, categoryIds, toggleCategory, loading, initialZoom } ) => {
5153 const [ markersLoaded , setMarkersLoaded ] = useState ( false ) ;
5254 const [ cursor , setCursor ] = useState ( "auto" ) ;
5355 const searchCoordinates = useSearchCoordinates ( ) ;
5456 const selectedOrganization = useSelectedOrganization ( ) ;
57+ const orgNameFilter = useOrgNameFilter ( ) ;
58+ const openTimeFilter = useOpenTimeFilter ( ) ;
5559 const navigate = useNavigate ( ) ;
5660 const location = useLocation ( ) ;
5761 const { isMobile } = useBreakpoints ( ) ;
@@ -72,7 +76,7 @@ const ResultsMap = ({ stakeholders, categoryIds, toggleCategory, loading }) => {
7276 const [ viewport , setViewport ] = useState ( {
7377 latitude,
7478 longitude,
75- zoom : DEFAULT_VIEWPORT . zoom ,
79+ zoom : initialZoom || DEFAULT_VIEWPORT . zoom ,
7680 } ) ;
7781 const dispatch = useAppDispatch ( ) ;
7882 const neighborhood = useNeighborhood ( ) ;
@@ -94,6 +98,7 @@ const ResultsMap = ({ stakeholders, categoryIds, toggleCategory, loading }) => {
9498 ...viewport ,
9599 latitude : latitude ,
96100 longitude,
101+ zoom : initialZoom ? initialZoom : viewport . zoom ,
97102 } ) ) ;
98103 } , [ searchCoordinates , longitude , latitude , isMobile ] ) ;
99104
@@ -108,6 +113,7 @@ const ResultsMap = ({ stakeholders, categoryIds, toggleCategory, loading }) => {
108113 flyTo ( {
109114 longitude : startIconCoordinates . longitude ,
110115 latitude : startIconCoordinates . latitude ,
116+ initialZoom,
111117 } ) ;
112118 } , [ startIconCoordinates , flyTo , mapRef ] ) ;
113119
@@ -318,6 +324,52 @@ const ResultsMap = ({ stakeholders, categoryIds, toggleCategory, loading }) => {
318324 } ;
319325 } , [ ] ) ;
320326
327+ function updateUrlParams ( updates = { } ) {
328+ const params = new URLSearchParams ( window . location . search ) ;
329+
330+ Object . entries ( updates ) . forEach ( ( [ key , value ] ) => {
331+ if ( value === null || value === undefined || value === "" ) {
332+ params . delete ( key ) ;
333+ } else {
334+ params . set ( key , value ) ;
335+ }
336+ } ) ;
337+
338+ const newUrl = `${ window . location . pathname } ?${ params . toString ( ) } ` ;
339+ window . history . replaceState ( null , "" , newUrl ) ;
340+ }
341+
342+ useEffect ( ( ) => {
343+ updateUrlParams ( {
344+ name : orgNameFilter || null ,
345+ pantry : isPantrySelected ? "1" : "0" ,
346+ meal : isMealSelected ? "1" : "0" ,
347+ openRadio :
348+ openTimeFilter . radio !== "Show All" ? openTimeFilter . radio : null ,
349+ openDay :
350+ openTimeFilter . radio === "Customized" ? openTimeFilter . day : null ,
351+ openTime :
352+ openTimeFilter . radio === "Customized" ? openTimeFilter . time : null ,
353+ } ) ;
354+ } , [
355+ orgNameFilter ,
356+ isPantrySelected ,
357+ isMealSelected ,
358+ openTimeFilter ,
359+ ] ) ;
360+
361+ useEffect ( ( ) => {
362+ const timeout = setTimeout ( ( ) => {
363+ updateUrlParams ( {
364+ lat : viewport . latitude ?. toFixed ( 7 ) ,
365+ lng : viewport . longitude ?. toFixed ( 7 ) ,
366+ zoom : viewport . zoom ? ( Math . round ( viewport . zoom * 10 ) / 10 ) . toString ( ) : null ,
367+ } ) ;
368+ } , 100 ) ;
369+
370+ return ( ) => clearTimeout ( timeout ) ;
371+ } , [ viewport ] ) ;
372+
321373 return (
322374 < div
323375 style = { { position : "relative" , height : "100%" , width : "100%" } }
0 commit comments