Position übernehmen beim bearbeiten von Einsätzen ändert nun die Position von Einsätzen
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
import { OSMWay } from "@repo/db";
|
||||
import { OSMWay, Prisma } from "@repo/db";
|
||||
import { useDispatchConnectionStore } from "_store/dispatch/connectionStore";
|
||||
import { useMapStore } from "_store/mapStore";
|
||||
import { usePannelStore } from "_store/pannelStore";
|
||||
@@ -8,6 +8,8 @@ import { getOsmAddress } from "_querys/osm";
|
||||
import { useEffect, useState } from "react";
|
||||
import toast from "react-hot-toast";
|
||||
import { Popup, useMap } from "react-leaflet";
|
||||
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
||||
import { editMissionAPI } from "_querys/missions";
|
||||
|
||||
export const ContextMenu = () => {
|
||||
const map = useMap();
|
||||
@@ -19,9 +21,8 @@ export const ContextMenu = () => {
|
||||
setSearchPopup,
|
||||
toggleSearchElementSelection,
|
||||
} = useMapStore();
|
||||
const { missionFormValues, setMissionFormValues, setOpen, isOpen } = usePannelStore(
|
||||
(state) => state,
|
||||
);
|
||||
const { missionFormValues, setMissionFormValues, setOpen, isOpen, editingMissionId } =
|
||||
usePannelStore((state) => state);
|
||||
const [showRulerOptions, setShowRulerOptions] = useState(false);
|
||||
const [rulerHover, setRulerHover] = useState(false);
|
||||
const [rulerOptionsHover, setRulerOptionsHover] = useState(false);
|
||||
@@ -54,7 +55,7 @@ export const ContextMenu = () => {
|
||||
|
||||
const einsatzBtnText = missionFormValues && isOpen ? "Position übernehmen" : "Einsatz erstellen";
|
||||
|
||||
const addOSMobjects = async () => {
|
||||
const addOSMobjects = async (ignorePreviosSelected?: boolean) => {
|
||||
const res = await fetch(
|
||||
`https://overpass-api.de/api/interpreter?data=${encodeURIComponent(`
|
||||
[out:json];
|
||||
@@ -73,7 +74,7 @@ export const ContextMenu = () => {
|
||||
.map((e: any) => {
|
||||
const elementInMap = searchElements.find((el) => el.wayID === e.id);
|
||||
return {
|
||||
isSelected: elementInMap?.isSelected ?? false,
|
||||
isSelected: ignorePreviosSelected ? false : (elementInMap?.isSelected ?? false),
|
||||
wayID: e.id,
|
||||
nodes: e.nodes.map((nodeId: string) => {
|
||||
const node = data.elements.find((element: any) => element.id === nodeId);
|
||||
@@ -111,7 +112,7 @@ export const ContextMenu = () => {
|
||||
style={{ transform: "translateX(-50%)" }}
|
||||
onClick={async () => {
|
||||
const { parsed } = await getOsmAddress(contextMenu.lat, contextMenu.lng);
|
||||
const objects = await addOSMobjects();
|
||||
const objects = await addOSMobjects(true);
|
||||
const closestToContext = objects.reduce((prev, curr) => {
|
||||
const prevLat = prev.nodes?.[0]?.lat ?? 0;
|
||||
const prevLon = prev.nodes?.[0]?.lon ?? 0;
|
||||
@@ -135,10 +136,11 @@ export const ContextMenu = () => {
|
||||
);
|
||||
|
||||
if (closestToContext) {
|
||||
toggleSearchElementSelection(closestToContext.wayID);
|
||||
toggleSearchElementSelection(closestToContext.wayID, true);
|
||||
}
|
||||
|
||||
setMissionFormValues({
|
||||
...missionFormValues,
|
||||
...parsed,
|
||||
state: "draft",
|
||||
addressLat: contextMenu.lat,
|
||||
|
||||
Reference in New Issue
Block a user