Skip to content

Commit

Permalink
Merge pull request #68 from concord-consortium/187000278-fix-show-map…
Browse files Browse the repository at this point in the history
…-button-bug

187000278 fix show map button bug
  • Loading branch information
eireland authored Feb 9, 2024
2 parents aab06b7 + 5de9c11 commit 9f57a23
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 9f57a23

Please sign in to comment.