Skip to content

Commit

Permalink
Fixes bug with map button not showing or showing inappropriately.
Browse files Browse the repository at this point in the history
Also fixes bluring location input field when user types Enter
  • Loading branch information
eireland committed Feb 9, 2024
1 parent 37fe9c4 commit 5de9c11
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/components/location-picker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export const LocationPicker = ({setActiveStations, setStatus}: IProps) => {
if (locationInputEl.current && !locationInputEl.current.contains(event.target as Node) && !locationSelectionListElRef.current?.contains(event.target as Node) && !locationDivRef.current?.contains(event.target as Node)) {
setIsEditing(false);
setShowSelectionList(false);
setShowMapButton(false);
setShowMapButton(locationInputEl.current.value !== "");
setState((draft) => {
draft.location = locationInputEl.current?.value === "" ? undefined : location;
draft.zoomMap = false;
Expand Down Expand Up @@ -88,7 +88,7 @@ export const LocationPicker = ({setActiveStations, setStatus}: IProps) => {

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

Expand Down Expand Up @@ -184,19 +184,26 @@ export const LocationPicker = ({setActiveStations, setStatus}: IProps) => {
setCandidateLocation(place?.name || "");
setShowSelectionList(false);
setIsEditing(false);
setShowMapButton(place?.name !== undefined);
setShowMapButton(place?.name !== undefined || (location !== undefined && locationInputEl.current?.value !== ""));
setLocationPossibilities([]);
setHoveredIndex(null);
setArrowedIndex(-1);
};

const handleInputKeyDown = async(e: React.KeyboardEvent<HTMLInputElement>) => {
if (e.key === "Enter") {
if (e.currentTarget.value) {
if (e.currentTarget.value === "") {
setShowMapButton(false);
setState(draft => {
draft.location = undefined;
draft.weatherStation = undefined;
});
} else {
const locale = await geoNameSearch(e.currentTarget.value);
placeNameSelected(locale?.[0]);
}
setIsEditing(false);
locationInputEl.current?.blur();
} else
if (e.key === "ArrowDown" && locationPossibilities.length > 0) {
setHoveredIndex(0);
Expand Down

0 comments on commit 5de9c11

Please sign in to comment.