Refresh layer after status update

dev
Platon Yasev 3 years ago
parent da337ea95a
commit 958726e783

@ -3,6 +3,7 @@ import { Layer, Source } from "react-map-gl";
import { aoLayer, rayonLayer, selectedRegionLayer } from "./layers-config"; import { aoLayer, rayonLayer, selectedRegionLayer } from "./layers-config";
import { useLayersVisibility } from "../stores/useLayersVisibility"; import { useLayersVisibility } from "../stores/useLayersVisibility";
import { useFilters } from "../stores/useFilters"; import { useFilters } from "../stores/useFilters";
import { BASE_URL } from "../api";
export const Layers = () => { export const Layers = () => {
const { const {
@ -15,9 +16,7 @@ export const Layers = () => {
<Source <Source
id="ao" id="ao"
type="vector" type="vector"
tiles={[ tiles={[`${BASE_URL}/martin/public.service_ao/{z}/{x}/{y}.pbf`]}
"https://postamates.spatiality.website/martin/public.msk_ao/{z}/{x}/{y}.pbf",
]}
> >
<Layer <Layer
{...aoLayer} {...aoLayer}
@ -31,9 +30,7 @@ export const Layers = () => {
<Source <Source
id="rayon" id="rayon"
type="vector" type="vector"
tiles={[ tiles={[`${BASE_URL}/martin/public.service_rayon/{z}/{x}/{y}.pbf`]}
"https://postamates.spatiality.website/martin/public.msk_rayoni/{z}/{x}/{y}.pbf",
]}
> >
<Layer <Layer
{...rayonLayer} {...rayonLayer}

@ -4,6 +4,7 @@ import { useLayersVisibility } from "../stores/useLayersVisibility";
import { BASE_URL } from "../api"; import { BASE_URL } from "../api";
import { useFilters } from "../stores/useFilters"; import { useFilters } from "../stores/useFilters";
import { usePointSelection } from "../stores/usePointSelection"; import { usePointSelection } from "../stores/usePointSelection";
import { useUpdateLayerCounter } from "../stores/useUpdateLayerCounter";
const getRegionField = (selectedRegion) => { const getRegionField = (selectedRegion) => {
if (!selectedRegion) return null; if (!selectedRegion) return null;
@ -22,6 +23,8 @@ export const Points = () => {
const includedArr = [...selection.included]; const includedArr = [...selection.included];
const excludedArr = [...selection.excluded]; const excludedArr = [...selection.excluded];
const { updateCounter } = useUpdateLayerCounter();
const includedExpression = [ const includedExpression = [
"in", "in",
["get", "location_id"], ["get", "location_id"],
@ -83,6 +86,7 @@ export const Points = () => {
<Source <Source
id="points" id="points"
type="vector" type="vector"
key={`points-${updateCounter}`}
tiles={[ tiles={[
`${BASE_URL}/martin/public.service_placementpoint/{z}/{x}/{y}.pbf`, `${BASE_URL}/martin/public.service_placementpoint/{z}/{x}/{y}.pbf`,
]} ]}

@ -84,7 +84,7 @@ export const aoLayer = {
id: "ao", id: "ao",
type: "line", type: "line",
source: "ao", source: "ao",
"source-layer": "public.msk_ao", "source-layer": "public.service_ao",
layout: { layout: {
"line-join": "round", "line-join": "round",
"line-cap": "round", "line-cap": "round",
@ -100,7 +100,7 @@ export const rayonLayer = {
id: "rayon", id: "rayon",
type: "line", type: "line",
source: "rayon", source: "rayon",
"source-layer": "public.msk_rayoni", "source-layer": "public.service_rayon",
layout: { layout: {
"line-join": "round", "line-join": "round",
"line-cap": "round", "line-cap": "round",

@ -40,7 +40,7 @@ export const RegionSelect = ({ disabled }) => {
const getRegions = async () => { const getRegions = async () => {
setLoading(true); setLoading(true);
try { try {
const response = await api.get("/api/placement_points/ao_rayons"); const response = await api.get("/api/ao_rayons");
setData(response.data); setData(response.data);
} catch (err) { } catch (err) {
console.error(err); console.error(err);

@ -4,12 +4,14 @@ import { api } from "../../api";
import { useFilters } from "../../stores/useFilters"; import { useFilters } from "../../stores/useFilters";
import { usePointSelection } from "../../stores/usePointSelection"; import { usePointSelection } from "../../stores/usePointSelection";
import { STATUSES } from "../../config"; import { STATUSES } from "../../config";
import { useUpdateLayerCounter } from "../../stores/useUpdateLayerCounter";
export const TakeToWorkButton = () => { export const TakeToWorkButton = () => {
const { filters } = useFilters(); const { filters } = useFilters();
const { prediction, categories } = filters; const { prediction, categories } = filters;
const { selection } = usePointSelection(); const { selection } = usePointSelection();
const queryClient = useQueryClient(); const queryClient = useQueryClient();
const { toggleUpdateCounter } = useUpdateLayerCounter();
const { mutate } = useMutation({ const { mutate } = useMutation({
mutationFn: () => { mutationFn: () => {
@ -25,7 +27,10 @@ export const TakeToWorkButton = () => {
`/api/placement_points/update_status?${params.toString()}` `/api/placement_points/update_status?${params.toString()}`
); );
}, },
onSuccess: () => queryClient.invalidateQueries(["table", 1, filters]), onSuccess: () => {
queryClient.invalidateQueries(["table", 1, filters]);
toggleUpdateCounter();
},
}); });
const takeToWork = () => { const takeToWork = () => {

@ -73,12 +73,13 @@ const PAGE_SIZE = 30;
const useTableData = (page) => { const useTableData = (page) => {
const [pageSize, setPageSize] = useState(PAGE_SIZE); const [pageSize, setPageSize] = useState(PAGE_SIZE);
const { filters } = useFilters(); const { filters } = useFilters();
const { prediction, status, categories } = filters; const { prediction, status, categories, region } = filters;
const { selection } = usePointSelection();
const { clickedPointConfig } = useClickedPointConfig(); const { clickedPointConfig } = useClickedPointConfig();
const [finalData, setFinalData] = useState(); const [finalData, setFinalData] = useState();
const { data } = useQuery( const { data } = useQuery(
["table", page, filters], ["table", page, filters, selection],
async () => { async () => {
const params = new URLSearchParams({ const params = new URLSearchParams({
page, page,
@ -86,8 +87,19 @@ const useTableData = (page) => {
"prediction_current[]": prediction, "prediction_current[]": prediction,
"status[]": status, "status[]": status,
"categories[]": categories, "categories[]": categories,
"included[]": [...selection.included],
}); });
if (region) {
if (region.type === "ao") {
params.append("ao[]", region.id);
}
if (region.type === "rayon") {
params.append("rayon[]", region.id);
}
}
const { data } = await api.get( const { data } = await api.get(
`/api/placement_points?${params.toString()}` `/api/placement_points?${params.toString()}`
); );
@ -251,10 +263,6 @@ export const Table = React.memo(({ height = 200 }) => {
return { return {
onClick: () => { onClick: () => {
const geometry = parse(record.geometry); const geometry = parse(record.geometry);
// const feature = {
// properties: record,
// geometry,
// };
map.flyTo({ map.flyTo({
center: [geometry.coordinates[0], geometry.coordinates[1]], center: [geometry.coordinates[0], geometry.coordinates[1]],
zoom: 15, zoom: 15,

@ -0,0 +1,14 @@
import { create } from "zustand";
import { immer } from "zustand/middleware/immer";
const store = (set) => ({
updateCounter: -1,
toggleUpdateCounter: () => {
set((state) => {
state.updateCounter = state.updateCounter === -1 ? 1 : -1;
});
},
});
export const useUpdateLayerCounter = create(immer(store));
Loading…
Cancel
Save