@@ -30,7 +30,7 @@ import {
3030 useSelectedOrganization ,
3131 useUserCoordinates ,
3232 useOrgNameFilter ,
33- useOpenTimeFilter
33+ useOpenTimeFilter ,
3434} from "../../../../appReducer" ;
3535import { useMapbox } from "../../../../hooks/useMapbox" ;
3636import AdvancedFilters from "../AdvancedFilters/AdvancedFilters" ;
@@ -49,7 +49,13 @@ import {
4949} from "constants/stakeholder" ;
5050import debounceFn from "debounce-fn" ;
5151
52- const ResultsMap = ( { stakeholders, categoryIds, toggleCategory, loading, initialZoom } ) => {
52+ const ResultsMap = ( {
53+ stakeholders,
54+ categoryIds,
55+ toggleCategory,
56+ loading,
57+ initialZoom,
58+ } ) => {
5359 const [ markersLoaded , setMarkersLoaded ] = useState ( false ) ;
5460 const [ cursor , setCursor ] = useState ( "auto" ) ;
5561 const searchCoordinates = useSearchCoordinates ( ) ;
@@ -324,51 +330,53 @@ const ResultsMap = ({ stakeholders, categoryIds, toggleCategory, loading, initia
324330 } ;
325331 } , [ ] ) ;
326332
327- function updateUrlParams ( updates = { } ) {
328- const params = new URLSearchParams ( window . location . search ) ;
333+ function updateUrlParams ( updates = { } ) {
334+ const params = new URLSearchParams ( window . location . search ) ;
329335
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 ) ;
336+ // skip updating if the URL already has an "org" param
337+ if ( params . has ( "org" ) ) {
338+ return ;
335339 }
336- } ) ;
337340
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 ( ( ) => {
341+ Object . entries ( updates ) . forEach ( ( [ key , value ] ) => {
342+ if ( value === null || value === undefined || value === "" ) {
343+ params . delete ( key ) ;
344+ } else {
345+ params . set ( key , value ) ;
346+ }
347+ } ) ;
348+
349+ const newUrl = `${ window . location . pathname } ?${ params . toString ( ) } ` ;
350+ window . history . replaceState ( null , "" , newUrl ) ;
351+ }
352+
353+ useEffect ( ( ) => {
363354 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 ,
355+ name : orgNameFilter || null ,
356+ pantry : isPantrySelected ? "1" : "0" ,
357+ meal : isMealSelected ? "1" : "0" ,
358+ openRadio :
359+ openTimeFilter . radio !== "Show All" ? openTimeFilter . radio : null ,
360+ openDay :
361+ openTimeFilter . radio === "Customized" ? openTimeFilter . day : null ,
362+ openTime :
363+ openTimeFilter . radio === "Customized" ? openTimeFilter . time : null ,
367364 } ) ;
368- } , 100 ) ;
365+ } , [ orgNameFilter , isPantrySelected , isMealSelected , openTimeFilter ] ) ;
366+
367+ useEffect ( ( ) => {
368+ const timeout = setTimeout ( ( ) => {
369+ updateUrlParams ( {
370+ lat : viewport . latitude ?. toFixed ( 7 ) ,
371+ lng : viewport . longitude ?. toFixed ( 7 ) ,
372+ zoom : viewport . zoom
373+ ? ( Math . round ( viewport . zoom * 10 ) / 10 ) . toString ( )
374+ : null ,
375+ } ) ;
376+ } , 100 ) ;
369377
370- return ( ) => clearTimeout ( timeout ) ;
371- } , [ viewport ] ) ;
378+ return ( ) => clearTimeout ( timeout ) ;
379+ } , [ viewport ] ) ;
372380
373381 return (
374382 < div
@@ -469,6 +477,7 @@ useEffect(() => {
469477 </ Grid >
470478 ) }
471479 < FilterPanel
480+ filterCount = { stakeholders . length }
472481 mealPantry = { {
473482 toggleMeal,
474483 togglePantry,
0 commit comments