From 655862d95924205912444095e0f9ff2646da6de6 Mon Sep 17 00:00:00 2001 From: eireland Date: Wed, 31 Jan 2024 15:04:53 -0800 Subject: [PATCH] Moves showMapButton to app state instead of just render state --- src/components/App.tsx | 1 + src/components/location-picker.tsx | 7 +++---- src/types.ts | 1 + 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/components/App.tsx b/src/components/App.tsx index cb16fa6..71d54af 100755 --- a/src/components/App.tsx +++ b/src/components/App.tsx @@ -60,6 +60,7 @@ export const App = () => { draft.zoomMap = newState.zoomMap; draft.frequencies = newState.frequencies; draft.didUserSelectDate = newState.didUserSelectDate; + draft.showMapButton = newState.showMapButton; draft.isMapOpen = newState.isMapOpen; const startDateStr = newState.startDate; diff --git a/src/components/location-picker.tsx b/src/components/location-picker.tsx index e85dfa0..eb42618 100644 --- a/src/components/location-picker.tsx +++ b/src/components/location-picker.tsx @@ -14,8 +14,7 @@ import "./location-picker.scss"; export const LocationPicker = () => { const {state, setState} = useStateContext(); - const {units, location, weatherStation, weatherStationDistance, startDate, endDate} = state; - const [showMapButton, setShowMapButton] = useState(false); + const {units, location, weatherStation, weatherStationDistance, startDate, endDate, showMapButton} = state; const [isEditing, setIsEditing] = useState(false); const [locationPossibilities, setLocationPossibilities] = useState([]); const [showSelectionList, setShowSelectionList] = useState(false); @@ -137,10 +136,10 @@ export const LocationPicker = () => { const placeNameSelected = (place: IPlace | undefined) => { setState(draft => { draft.location = place; + draft.showMapButton = true; }); setShowSelectionList(false); setIsEditing(false); - setShowMapButton(true); setLocationPossibilities([]); setHoveredIndex(null); setArrowedIndex(-1); @@ -273,8 +272,8 @@ export const LocationPicker = () => { geoLocSearch(lat, long).then((currPosName) => { setState(draft => { draft.location = {name: currPosName, latitude: lat, longitude: long}; + draft.showMapButton = true; }); - setShowMapButton(true); setIsEditing(false); setShowSelectionList(false); }); diff --git a/src/types.ts b/src/types.ts index d6b5b84..3510a60 100644 --- a/src/types.ts +++ b/src/types.ts @@ -124,6 +124,7 @@ export interface IState { didUserSelectDate: boolean; isMapOpen: boolean; zoomMap: boolean; + showMapButton?: boolean; } export const unitMap: UnitMap = {