diff --git a/apps/dispatch/app/_components/SmartPopup.tsx b/apps/dispatch/app/_components/SmartPopup.tsx index 3ff5b0dc..975211d7 100644 --- a/apps/dispatch/app/_components/SmartPopup.tsx +++ b/apps/dispatch/app/_components/SmartPopup.tsx @@ -24,7 +24,7 @@ export const useSmartPopup = () => { export const calculateAnchor = ( id: string, mode: "popup" | "marker", - ignoreMarker?: boolean, + options?: { ignoreMarker?: boolean; ignoreCluster?: boolean }, ) => { const otherMarkers = document.querySelectorAll(".map-collision"); // get markers and check if they are overlapping @@ -36,8 +36,9 @@ export const calculateAnchor = ( if (!otherMarkers || !ownMarker) return "topleft"; const marksersInCluster = Array.from(otherMarkers).filter((marker) => { - if (mode === "popup" && marker.id === `marker-${id}`) return false; - if (ignoreMarker && marker.id.startsWith("marker")) return false; + if (mode === "popup" && marker.id === `marker-domain-${id}`) return false; + if (options?.ignoreMarker && marker.id.includes("marker")) return false; + if (options?.ignoreCluster && marker.id.includes("cluster")) return false; const rect1 = (marker as HTMLElement).getBoundingClientRect(); const rect2 = (ownMarker as HTMLElement).getBoundingClientRect(); @@ -76,12 +77,6 @@ export const calculateAnchor = ( centerOfOverlappingMarkers.x /= markersPosition.length; centerOfOverlappingMarkers.y /= markersPosition.length; - if (id == "2") { - console.log("markersInCluser", marksersInCluster); - console.log("ownMarkerPosition", ownMarkerPosition); - console.log("centerOfOverlappingMarkers", centerOfOverlappingMarkers); - } - if (marksersInCluster.length > 1) { if (centerOfOverlappingMarkers.y < ownMarkerPosition.y) { if (centerOfOverlappingMarkers.x > ownMarkerPosition.x) { @@ -107,24 +102,25 @@ export interface SmartPopupRef { } export const SmartPopup = ( - props: PopupProps & { ignoreMarker?: boolean } & RefAttributes & { + props: PopupProps & + RefAttributes & { + options?: { ignoreMarker?: boolean; ignoreCluster?: boolean }; smartPopupRef?: Ref; id: string; wrapperClassName?: string; }, ) => { const [showContent, setShowContent] = useState(false); - const { smartPopupRef, id, className, wrapperClassName, ignoreMarker } = - props; + const { smartPopupRef, id, className, wrapperClassName, options } = props; const [anchor, setAnchor] = useState< "topleft" | "topright" | "bottomleft" | "bottomright" >("topleft"); const handleConflict = useCallback(() => { - const newAnchor = calculateAnchor(id, "popup", ignoreMarker); + const newAnchor = calculateAnchor(id, "popup", options); setAnchor(newAnchor); - }, [id, ignoreMarker]); + }, [id, options]); useImperativeHandle(smartPopupRef, () => ({ handleConflict, diff --git a/apps/dispatch/app/_store/mapStore.ts b/apps/dispatch/app/_store/mapStore.ts index 7a6c681b..ac6c2ec8 100644 --- a/apps/dispatch/app/_store/mapStore.ts +++ b/apps/dispatch/app/_store/mapStore.ts @@ -1,4 +1,3 @@ -import { popup } from "leaflet"; import { create } from "zustand"; interface MapStore { diff --git a/apps/dispatch/app/_store/missionsStore.ts b/apps/dispatch/app/_store/missionsStore.ts index 95dc59f8..89cf1378 100644 --- a/apps/dispatch/app/_store/missionsStore.ts +++ b/apps/dispatch/app/_store/missionsStore.ts @@ -3,6 +3,7 @@ import { MissionOptionalDefaults } from "@repo/db/zod"; import { serverApi } from "helpers/axios"; import { create } from "zustand"; import { toast } from "react-hot-toast"; +import axios from "axios"; interface MissionStore { missions: Mission[]; @@ -17,15 +18,8 @@ export const useMissionsStore = create((set) => ({ missions: [], setMissions: (missions) => set({ missions }), createMission: async (mission) => { - const res = await fetch("/api/mission", { - method: "PUT", - headers: { - "Content-Type": "application/json", - }, - body: JSON.stringify(mission), - }); - if (!res.ok) return new Error("Failed to create mission"); - const data = await res.json(); + const { data } = await serverApi.put("/mission", mission); + set((state) => ({ missions: [...state.missions, data] })); return data; }, diff --git a/apps/dispatch/app/_store/reportStore.ts b/apps/dispatch/app/_store/reportStore.ts deleted file mode 100644 index 43d7e854..00000000 --- a/apps/dispatch/app/_store/reportStore.ts +++ /dev/null @@ -1,32 +0,0 @@ -import { create } from "zustand"; -import { PrismaClient } from "@prisma/client"; - -interface ReportStore { - ownId: null | string; - reportOpen: boolean; - setReportOpen: (open: boolean) => void; - setOwnId: (id: string) => void; -} - -export const useReportStore = create((set) => ({ - ownId: null, - reportOpen: false, - setReportOpen: (open: boolean) => set({ reportOpen: open }), - setOwnId: (id: string) => set({ ownId: id }), -})); - -const prisma = new PrismaClient(); - -export const sendReport = async (receiverId: string, message: string) => { - try { - await prisma.reportMessage.create({ - data: { - receiverId, - message, - }, - }); - } catch (error) { - console.error("Failed to send report:", error); - throw error; - } -}; diff --git a/apps/dispatch/app/dispatch/_components/left/Chat.tsx b/apps/dispatch/app/dispatch/_components/left/Chat.tsx index 07c307bb..742dfc69 100644 --- a/apps/dispatch/app/dispatch/_components/left/Chat.tsx +++ b/apps/dispatch/app/dispatch/_components/left/Chat.tsx @@ -5,17 +5,11 @@ import { useSession } from "next-auth/react"; import { Fragment, useEffect, useRef, useState } from "react"; import { Dispatcher } from "dispatch/_components/navbar/_components/action"; import { cn } from "helpers/cn"; -import { useReportStore } from "_store/reportStore"; -import { serverApi } from "helpers/axios"; - -export const getDispatcher = async () => { - const res = await serverApi.get(`/dispatcher`); - return res.data; -}; +import { getDispatcher } from "pilot/_components/navbar/action"; export const Chat = () => { - const { setReportOpen } = useReportStore(); const { + setReportTabOpen, chatOpen, setChatOpen, sendMessage, @@ -65,7 +59,7 @@ export const Chat = () => { console.log("cleared"); } }; - }, [addTabValue, chats]); + }, [addTabValue, chats, session.data?.user.id]); return (
@@ -76,7 +70,7 @@ export const Chat = () => {