Show popup with search from address input and table

dev
Platon Yasev 3 years ago
parent 93faf495c9
commit 04a31955d1

@ -5,6 +5,8 @@ import { api } from "../api";
import { useEffect, useMemo, useState } from "react"; import { useEffect, useMemo, useState } from "react";
import { useMap } from "react-map-gl"; import { useMap } from "react-map-gl";
import parse from "wellknown"; import parse from "wellknown";
import { usePopup } from "../stores/usePopup.js";
import { useClickedPointConfig } from "../stores/useClickedPointConfig.js";
function useDebounce(value, delay) { function useDebounce(value, delay) {
const [debouncedValue, setDebouncedValue] = useState(value); const [debouncedValue, setDebouncedValue] = useState(value);
@ -22,6 +24,8 @@ export const AddressSearch = () => {
const { map } = useMap(); const { map } = useMap();
const [value, setValue] = useState(""); const [value, setValue] = useState("");
const debouncedValue = useDebounce(value); const debouncedValue = useDebounce(value);
const { setPopup } = usePopup();
const { setClickedPointConfig } = useClickedPointConfig();
const { data } = useQuery(["address", debouncedValue], async () => { const { data } = useQuery(["address", debouncedValue], async () => {
const result = await api.get( const result = await api.get(
@ -56,6 +60,13 @@ export const AddressSearch = () => {
zoom: 13, zoom: 13,
essential: true, essential: true,
}); });
const feature = {
properties: option.item,
};
setPopup({ features: [feature], coordinates: geometry.coordinates });
setClickedPointConfig(feature.properties.id, false);
}; };
return ( return (

@ -12,10 +12,11 @@ import { FeatureProperties } from "./mode-popup/FeatureProperties";
const SingleFeaturePopup = ({ feature }) => { const SingleFeaturePopup = ({ feature }) => {
const { mode } = useMode(); const { mode } = useMode();
const isRivals = const isRivals =
feature.layer.id === LAYER_IDS.pvz || feature.layer.id === LAYER_IDS.other; feature.layer?.id === LAYER_IDS.pvz ||
feature.layer?.id === LAYER_IDS.other;
const isInitialLayer = const isInitialLayer =
feature.layer.id === LAYER_IDS["initial-match"] || feature.layer?.id === LAYER_IDS["initial-match"] ||
feature.layer.id === LAYER_IDS["initial-unmatch"]; feature.layer?.id === LAYER_IDS["initial-unmatch"];
if (isRivals) { if (isRivals) {
return <FeatureProperties feature={feature} />; return <FeatureProperties feature={feature} />;

@ -16,7 +16,8 @@ export const FeatureProperties = ({ feature, dynamicStatus, postamatId }) => {
const isResidential = feature.properties.category === CATEGORIES.residential; const isResidential = feature.properties.category === CATEGORIES.residential;
const isWorking = feature.properties.status === STATUSES.working; const isWorking = feature.properties.status === STATUSES.working;
const isRivals = const isRivals =
feature.layer.id === LAYER_IDS.pvz || feature.layer.id === LAYER_IDS.other; feature.layer?.id === LAYER_IDS.pvz ||
feature.layer?.id === LAYER_IDS.other;
const getConfig = () => { const getConfig = () => {
if (isRivals) { if (isRivals) {

@ -8,6 +8,7 @@ import scrollIntoView from "scroll-into-view-if-needed";
import { twMerge } from "tailwind-merge"; import { twMerge } from "tailwind-merge";
import { HeaderWrapper } from "./HeaderWrapper"; import { HeaderWrapper } from "./HeaderWrapper";
import { useTable } from "../../stores/useTable"; import { useTable } from "../../stores/useTable";
import { usePopup } from "../../stores/usePopup.js";
export const Table = React.memo( export const Table = React.memo(
({ ({
@ -22,9 +23,11 @@ export const Table = React.memo(
fullWidth, fullWidth,
loading, loading,
}) => { }) => {
const { clickedPointConfig } = useClickedPointConfig(); const { clickedPointConfig, setClickedPointConfig } =
useClickedPointConfig();
const { map } = useMap(); const { map } = useMap();
const { tableState, toggleOpened } = useTable(); const { tableState, toggleOpened } = useTable();
const { setPopup } = usePopup();
const SCROLL = { const SCROLL = {
y: tableState.fullScreen ? "calc(100vh - 136px)" : "200px", y: tableState.fullScreen ? "calc(100vh - 136px)" : "200px",
@ -77,6 +80,15 @@ export const Table = React.memo(
zoom: 13, zoom: 13,
essential: true, essential: true,
}); });
const feature = {
properties: record,
};
setPopup({
features: [feature],
coordinates: geometry.coordinates,
});
}, },
}; };
}} }}

Loading…
Cancel
Save