Skip to content

Commit

Permalink
Moves showMapButton to app state instead of just render state
Browse files Browse the repository at this point in the history
  • Loading branch information
eireland committed Jan 31, 2024
1 parent ebf636a commit 655862d
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/components/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 3 additions & 4 deletions src/components/location-picker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<IPlace[]>([]);
const [showSelectionList, setShowSelectionList] = useState(false);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
});
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ export interface IState {
didUserSelectDate: boolean;
isMapOpen: boolean;
zoomMap: boolean;
showMapButton?: boolean;
}

export const unitMap: UnitMap = {
Expand Down

0 comments on commit 655862d

Please sign in to comment.