Skip to content

Commit

Permalink
Reset input fields when switching search modes.
Browse files Browse the repository at this point in the history
Persistent input in search popup.

Enhanced search suggestion relevancy.

Signed-off-by: Celine Pöhl <[email protected]>
  • Loading branch information
CelineMP committed May 28, 2024
1 parent 5ae2e5e commit 50850a1
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions frontend/src/components/PopUp/SearchPopUp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,24 @@ const SearchPopUp: React.FC<SearchPopUpProps> = ({
const [suggestions, setSuggestions] = useState<Array<GeoSearchResult>>([]);
const { currentMapCache } = useContext(MapContext);

const provider = new OpenStreetMapProvider({
params: {
'accept-language': 'de',
countrycodes: 'de',
addressdetails: 1,
},
});

const reset = () => {
setSearchText("");
setLongitude("");
setLatitude("");
setSearchMode("single");
setSuggestions([]);
setLatitudeError(false);
setLongitudeError(false);
};

const flyToLocation = () => {
const { mapInstance } = currentMapCache;
if (mapInstance) {
Expand All @@ -59,7 +77,6 @@ const SearchPopUp: React.FC<SearchPopUpProps> = ({
setSuggestions([]);
return;
}
const provider = new OpenStreetMapProvider();
const results = await provider.search({ query: input });
const transformedResults: GeoSearchResult[] = results.map((result) => ({
x: result.x,
Expand All @@ -70,8 +87,8 @@ const SearchPopUp: React.FC<SearchPopUpProps> = ({
};

const handleModeSwitch = () => {
reset();
if (searchMode === "single") {
setSuggestions([]);
setSearchMode("coordinates");
} else {
setSearchMode("single");
Expand All @@ -91,7 +108,7 @@ const SearchPopUp: React.FC<SearchPopUpProps> = ({
return item.displayName;
}

const [latitudeTerm, longitudeTerm] = searchText.split(" ");
const [latitudeTerm, longitudeTerm] = [latitude, longitude];
const regex = new RegExp(
`^-?${latitudeTerm}[\\S\\d°'\\\\".]*\\s-?${longitudeTerm}[\\S\\d°'\\\\".]*$`
);
Expand Down Expand Up @@ -187,7 +204,10 @@ const SearchPopUp: React.FC<SearchPopUpProps> = ({
return (
<PopUp
title="Locations"
onClose={onToggleIfOpenedDialog}
onClose={() => {
onToggleIfOpenedDialog();
reset();
}}
ifOpenedDialog={ifOpenedDialog}
>
{searchMode === "single" ? (
Expand Down

0 comments on commit 50850a1

Please sign in to comment.