mirror of
https://github.com/utopia-os/utopia-ui.git
synced 2025-12-13 07:46:10 +00:00
fix searchbar disapear issue
This commit is contained in:
parent
5c287f7df4
commit
a1faa91fba
@ -133,6 +133,7 @@ export const Layer = ({
|
|||||||
<>
|
<>
|
||||||
{items &&
|
{items &&
|
||||||
items.
|
items.
|
||||||
|
filter(item => item[itemTextField]).
|
||||||
filter(item => item.layer?.name === name)?.
|
filter(item => item.layer?.name === name)?.
|
||||||
filter(item =>
|
filter(item =>
|
||||||
filterTags.length == 0 ? item : filterTags.every(tag => getItemTags(item).some(filterTag => filterTag.id.toLocaleLowerCase() === tag.id.toLocaleLowerCase())))?.
|
filterTags.length == 0 ? item : filterTags.every(tag => getItemTags(item).some(filterTag => filterTag.id.toLocaleLowerCase() === tag.id.toLocaleLowerCase())))?.
|
||||||
|
|||||||
@ -3,7 +3,7 @@ import { useAddFilterTag, useFilterTags, useResetFilterTags, useSetSearchPhrase
|
|||||||
import useWindowDimensions from '../../hooks/useWindowDimension';
|
import useWindowDimensions from '../../hooks/useWindowDimension';
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
import { useRef, useState } from 'react';
|
import { useRef, useState } from 'react';
|
||||||
import { useMap } from 'react-leaflet';
|
import { useMap, useMapEvents } from 'react-leaflet';
|
||||||
import { LatLng, LatLngBounds } from 'leaflet';
|
import { LatLng, LatLngBounds } from 'leaflet';
|
||||||
import { useDebounce } from '../../hooks/useDebounce';
|
import { useDebounce } from '../../hooks/useDebounce';
|
||||||
import { useTags } from '../../hooks/useTags';
|
import { useTags } from '../../hooks/useTags';
|
||||||
@ -19,6 +19,8 @@ import MarkerIconFactory from '../../../../Utils/MarkerIconFactory';
|
|||||||
export const SearchControl = ({ clusterRef }) => {
|
export const SearchControl = ({ clusterRef }) => {
|
||||||
|
|
||||||
const windowDimensions = useWindowDimensions();
|
const windowDimensions = useWindowDimensions();
|
||||||
|
const [popupOpen, setPopupOpen] = useState(false);
|
||||||
|
|
||||||
const [value, setValue] = useState('');
|
const [value, setValue] = useState('');
|
||||||
const [geoResults, setGeoResults] = useState<Array<any>>([]);
|
const [geoResults, setGeoResults] = useState<Array<any>>([]);
|
||||||
const [tagsResults, setTagsResults] = useState<Array<any>>([]);
|
const [tagsResults, setTagsResults] = useState<Array<any>>([]);
|
||||||
@ -33,13 +35,21 @@ export const SearchControl = ({ clusterRef }) => {
|
|||||||
const resetFilterTags = useResetFilterTags();
|
const resetFilterTags = useResetFilterTags();
|
||||||
const filterTags = useFilterTags();
|
const filterTags = useFilterTags();
|
||||||
|
|
||||||
|
useMapEvents({
|
||||||
|
popupopen: () => {
|
||||||
|
setPopupOpen(true);
|
||||||
|
},
|
||||||
|
popupclose: () => {
|
||||||
|
setPopupOpen(false);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
useDebounce(() => {
|
useDebounce(() => {
|
||||||
const searchGeo = async () => {
|
const searchGeo = async () => {
|
||||||
try {
|
try {
|
||||||
const { data } = await axios.get(
|
const { data } = await axios.get(
|
||||||
`https://photon.komoot.io/api/?q=${value}&limit=5`
|
`https://photon.komoot.io/api/?q=${value}&limit=5`
|
||||||
);
|
);
|
||||||
|
|
||||||
setGeoResults(data.features);
|
setGeoResults(data.features);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
console.log(error);
|
||||||
@ -60,7 +70,7 @@ export const SearchControl = ({ clusterRef }) => {
|
|||||||
const searchInput = useRef<HTMLInputElement>(null);
|
const searchInput = useRef<HTMLInputElement>(null);
|
||||||
|
|
||||||
return (<>
|
return (<>
|
||||||
{!(windowDimensions.height < 500) &&
|
{!(windowDimensions.height < 500 && popupOpen) &&
|
||||||
<div className='tw-w-[calc(100vw-2rem)] tw-max-w-[22rem] '>
|
<div className='tw-w-[calc(100vw-2rem)] tw-max-w-[22rem] '>
|
||||||
<div className='flex tw-flex-row'>
|
<div className='flex tw-flex-row'>
|
||||||
<input type="text" placeholder="search ..." autoComplete="off" value={value} className="tw-input tw-input-bordered tw-w-full tw-shadow-xl tw-rounded-lg tw-mr-2"
|
<input type="text" placeholder="search ..." autoComplete="off" value={value} className="tw-input tw-input-bordered tw-w-full tw-shadow-xl tw-rounded-lg tw-mr-2"
|
||||||
@ -157,29 +167,19 @@ export const SearchControl = ({ clusterRef }) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function isGeoCoordinate(input) {
|
function isGeoCoordinate(input) {
|
||||||
console.log(input);
|
|
||||||
|
|
||||||
const geokoordinatenRegex = /^[-+]?([1-8]?\d(\.\d+)?|90(\.0+)?),\s*[-+]?(180(\.0+)?|((1[0-7]\d)|([1-9]?\d))(\.\d+)?)$/;
|
const geokoordinatenRegex = /^[-+]?([1-8]?\d(\.\d+)?|90(\.0+)?),\s*[-+]?(180(\.0+)?|((1[0-7]\d)|([1-9]?\d))(\.\d+)?)$/;
|
||||||
|
|
||||||
return geokoordinatenRegex.test(input);
|
return geokoordinatenRegex.test(input);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function extractCoordinates(input): number[] | null {
|
function extractCoordinates(input): number[] | null {
|
||||||
const result = input.split(",")
|
const result = input.split(",")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (result) {
|
if (result) {
|
||||||
const latitude = parseFloat(result[0]);
|
const latitude = parseFloat(result[0]);
|
||||||
const longitude = parseFloat(result[1]);
|
const longitude = parseFloat(result[1]);
|
||||||
console.log([latitude, longitude])
|
|
||||||
|
|
||||||
if (!isNaN(latitude) && !isNaN(longitude)) {
|
if (!isNaN(latitude) && !isNaN(longitude)) {
|
||||||
return [latitude, longitude];
|
return [latitude, longitude];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return null; // Invalid input or error
|
return null; // Invalid input or error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user