|
|
|
|
@ -2,7 +2,7 @@ import { AutoComplete, Input } from "antd";
|
|
|
|
|
import { useQuery } from "@tanstack/react-query";
|
|
|
|
|
import { SearchOutlined } from "@ant-design/icons";
|
|
|
|
|
import { api } from "../api";
|
|
|
|
|
import { useEffect, useMemo, useState } from "react";
|
|
|
|
|
import { useEffect, useMemo, useRef, useState } from "react";
|
|
|
|
|
import { useMap } from "react-map-gl";
|
|
|
|
|
import parse from "wellknown";
|
|
|
|
|
import { usePopup } from "../stores/usePopup.js";
|
|
|
|
|
@ -20,12 +20,15 @@ function useDebounce(value, delay) {
|
|
|
|
|
return debouncedValue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const AddressSearch = () => {
|
|
|
|
|
const renderLabel = (address) => <div>{address}</div>;
|
|
|
|
|
|
|
|
|
|
export const AddressSearch = ({ autoFocus = false }) => {
|
|
|
|
|
const { map } = useMap();
|
|
|
|
|
const [value, setValue] = useState("");
|
|
|
|
|
const debouncedValue = useDebounce(value);
|
|
|
|
|
const { setPopup } = usePopup();
|
|
|
|
|
const { setClickedPointConfig } = useClickedPointConfig();
|
|
|
|
|
const inputRef = useRef();
|
|
|
|
|
|
|
|
|
|
const { data } = useQuery(["address", debouncedValue], async () => {
|
|
|
|
|
const result = await api.get(
|
|
|
|
|
@ -39,7 +42,7 @@ export const AddressSearch = () => {
|
|
|
|
|
if (!data) return [];
|
|
|
|
|
|
|
|
|
|
return data.results.map((item) => ({
|
|
|
|
|
label: item.address,
|
|
|
|
|
label: renderLabel(item.address),
|
|
|
|
|
value: `${item.address}$${item.id}`,
|
|
|
|
|
item: item,
|
|
|
|
|
}));
|
|
|
|
|
@ -69,6 +72,12 @@ export const AddressSearch = () => {
|
|
|
|
|
setClickedPointConfig(feature.properties.id, false);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
if (autoFocus && inputRef?.current) {
|
|
|
|
|
inputRef.current.focus();
|
|
|
|
|
}
|
|
|
|
|
}, [autoFocus]);
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div>
|
|
|
|
|
<AutoComplete
|
|
|
|
|
@ -81,11 +90,14 @@ export const AddressSearch = () => {
|
|
|
|
|
onSelect={handleSelect}
|
|
|
|
|
allowClear={true}
|
|
|
|
|
onClear={() => setValue("")}
|
|
|
|
|
autoFocus={autoFocus}
|
|
|
|
|
popupClassName={"overflow-visible"}
|
|
|
|
|
>
|
|
|
|
|
<Input
|
|
|
|
|
prefix={<SearchOutlined />}
|
|
|
|
|
placeholder="Введите адрес точки"
|
|
|
|
|
className="text-ellipsis"
|
|
|
|
|
ref={inputRef}
|
|
|
|
|
/>
|
|
|
|
|
</AutoComplete>
|
|
|
|
|
</div>
|
|
|
|
|
|