Skip to content

Commit

Permalink
Polishing search PopUp (#203)
Browse files Browse the repository at this point in the history
  • Loading branch information
Corgam authored May 29, 2024
2 parents fa08a3d + 804af30 commit 1d563cc
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 1d563cc

Please sign in to comment.