Skip to content

Commit

Permalink
Removes saving showMapButton state from app state and instead just de…
Browse files Browse the repository at this point in the history
…tect whether a location has been selected.
  • Loading branch information
eireland committed Jan 31, 2024
1 parent 655862d commit 956dee0
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
1 change: 0 additions & 1 deletion src/components/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ 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
13 changes: 10 additions & 3 deletions src/components/location-picker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import "./location-picker.scss";

export const LocationPicker = () => {
const {state, setState} = useStateContext();
const {units, location, weatherStation, weatherStationDistance, startDate, endDate, showMapButton} = state;
const {units, location, weatherStation, weatherStationDistance, startDate, endDate} = state;
const [showMapButton, setShowMapButton] = useState(false);
const [isEditing, setIsEditing] = useState(false);
const [locationPossibilities, setLocationPossibilities] = useState<IPlace[]>([]);
const [showSelectionList, setShowSelectionList] = useState(false);
Expand Down Expand Up @@ -67,6 +68,12 @@ export const LocationPicker = () => {
}
}, [isEditing]);

useEffect(() => {
if (location) {
setShowMapButton(true);
}
}, [location]);

useEffect(() => {
const _startDate = startDate ? startDate : new Date( -5364662060); // 1/1/1750
const _endDate = endDate ? endDate : new Date(Date.now());
Expand Down Expand Up @@ -136,10 +143,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 @@ -272,8 +279,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: 0 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ export interface IState {
didUserSelectDate: boolean;
isMapOpen: boolean;
zoomMap: boolean;
showMapButton?: boolean;
}

export const unitMap: UnitMap = {
Expand Down

0 comments on commit 956dee0

Please sign in to comment.