added onClick events for marker-cluster
This commit is contained in:
@@ -3,6 +3,8 @@ import { ChatMessage } from "@repo/db";
|
|||||||
import { socket } from "dispatch/socket";
|
import { socket } from "dispatch/socket";
|
||||||
|
|
||||||
interface ChatStore {
|
interface ChatStore {
|
||||||
|
reportTabOpen: boolean;
|
||||||
|
setReportTabOpen: (open: boolean) => void;
|
||||||
ownId: null | string;
|
ownId: null | string;
|
||||||
selectedChat: string | null;
|
selectedChat: string | null;
|
||||||
chatOpen: boolean;
|
chatOpen: boolean;
|
||||||
@@ -20,6 +22,8 @@ interface ChatStore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const useChatStore = create<ChatStore>((set, get) => ({
|
export const useChatStore = create<ChatStore>((set, get) => ({
|
||||||
|
reportTabOpen: false,
|
||||||
|
setReportTabOpen: (open: boolean) => set({ reportTabOpen: open }),
|
||||||
ownId: null,
|
ownId: null,
|
||||||
chatOpen: false,
|
chatOpen: false,
|
||||||
selectedChat: null,
|
selectedChat: null,
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import { popup } from "leaflet";
|
|
||||||
import { create } from "zustand";
|
import { create } from "zustand";
|
||||||
|
|
||||||
interface MapStore {
|
interface MapStore {
|
||||||
|
|||||||
@@ -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<ReportStore>((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;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
@@ -3,16 +3,20 @@ import { ChatBubbleIcon, PaperPlaneIcon } from "@radix-ui/react-icons";
|
|||||||
import { useChatStore } from "_store/chatStore";
|
import { useChatStore } from "_store/chatStore";
|
||||||
import { useSession } from "next-auth/react";
|
import { useSession } from "next-auth/react";
|
||||||
import { Fragment, useEffect, useRef, useState } from "react";
|
import { Fragment, useEffect, useRef, useState } from "react";
|
||||||
import {
|
import { Dispatcher } from "dispatch/_components/navbar/_components/action";
|
||||||
Dispatcher,
|
|
||||||
getDispatcher,
|
|
||||||
} from "dispatch/_components/navbar/_components/action";
|
|
||||||
import { cn } from "helpers/cn";
|
import { cn } from "helpers/cn";
|
||||||
import { useReportStore } from "_store/reportStore";
|
|
||||||
|
export const getDispatcher = async () => {
|
||||||
|
const res = await fetch(`
|
||||||
|
${process.env.NEXT_PUBLIC_DISPATCH_SERVER_URL}/dispatcher`);
|
||||||
|
const data = await res.json();
|
||||||
|
return data as Dispatcher[];
|
||||||
|
};
|
||||||
|
|
||||||
export const Chat = () => {
|
export const Chat = () => {
|
||||||
const { setReportOpen } = useReportStore();
|
|
||||||
const {
|
const {
|
||||||
|
setReportTabOpen,
|
||||||
|
reportTabOpen,
|
||||||
chatOpen,
|
chatOpen,
|
||||||
setChatOpen,
|
setChatOpen,
|
||||||
sendMessage,
|
sendMessage,
|
||||||
@@ -62,7 +66,7 @@ export const Chat = () => {
|
|||||||
console.log("cleared");
|
console.log("cleared");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}, [addTabValue, chats]);
|
}, [addTabValue, chats, session.data?.user.id]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={cn("dropdown dropdown-right", chatOpen && "dropdown-open")}>
|
<div className={cn("dropdown dropdown-right", chatOpen && "dropdown-open")}>
|
||||||
@@ -73,7 +77,7 @@ export const Chat = () => {
|
|||||||
<button
|
<button
|
||||||
className="btn btn-soft btn-sm btn-primary"
|
className="btn btn-soft btn-sm btn-primary"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
setReportOpen(false);
|
setReportTabOpen(false);
|
||||||
setChatOpen(!chatOpen);
|
setChatOpen(!chatOpen);
|
||||||
if (selectedChat) {
|
if (selectedChat) {
|
||||||
setChatNotification(selectedChat, false);
|
setChatNotification(selectedChat, false);
|
||||||
|
|||||||
@@ -1,18 +1,15 @@
|
|||||||
"use client";
|
"use client";
|
||||||
import { ExclamationTriangleIcon, PaperPlaneIcon } from "@radix-ui/react-icons";
|
import { ExclamationTriangleIcon, PaperPlaneIcon } from "@radix-ui/react-icons";
|
||||||
import { useReportStore, sendReport } from "_store/reportStore";
|
|
||||||
import { useSession } from "next-auth/react";
|
import { useSession } from "next-auth/react";
|
||||||
import { useEffect, useRef, useState } from "react";
|
import { useEffect, useRef, useState } from "react";
|
||||||
import {
|
import { Dispatcher } from "dispatch/_components/navbar/_components/action";
|
||||||
Dispatcher,
|
|
||||||
getDispatcher,
|
|
||||||
} from "dispatch/_components/navbar/_components/action";
|
|
||||||
import { cn } from "helpers/cn";
|
import { cn } from "helpers/cn";
|
||||||
import { useChatStore } from "_store/chatStore";
|
import { useChatStore } from "_store/chatStore";
|
||||||
|
import { getDispatcher } from "dispatch/_components/left/Chat";
|
||||||
|
|
||||||
export const Report = () => {
|
export const Report = () => {
|
||||||
const { setChatOpen } = useChatStore();
|
const { setChatOpen, setReportTabOpen, reportTabOpen, setOwnId } =
|
||||||
const { reportOpen, setReportOpen, setOwnId } = useReportStore();
|
useChatStore();
|
||||||
const [sending, setSending] = useState(false);
|
const [sending, setSending] = useState(false);
|
||||||
const session = useSession();
|
const session = useSession();
|
||||||
const [selectedPlayer, setSelectedPlayer] = useState<string>("");
|
const [selectedPlayer, setSelectedPlayer] = useState<string>("");
|
||||||
@@ -23,7 +20,7 @@ export const Report = () => {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!session.data?.user.id) return;
|
if (!session.data?.user.id) return;
|
||||||
setOwnId(session.data.user.id);
|
setOwnId(session.data.user.id);
|
||||||
}, [session]);
|
}, [session, setOwnId]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const fetchDispatcher = async () => {
|
const fetchDispatcher = async () => {
|
||||||
@@ -53,20 +50,23 @@ export const Report = () => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className={cn("dropdown dropdown-right", reportOpen && "dropdown-open")}
|
className={cn(
|
||||||
|
"dropdown dropdown-right",
|
||||||
|
reportTabOpen && "dropdown-open",
|
||||||
|
)}
|
||||||
>
|
>
|
||||||
<div className="indicator">
|
<div className="indicator">
|
||||||
<button
|
<button
|
||||||
className="btn btn-soft btn-sm btn-error"
|
className="btn btn-soft btn-sm btn-error"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
setChatOpen(false);
|
setChatOpen(false);
|
||||||
setReportOpen(!reportOpen);
|
setReportTabOpen(!reportTabOpen);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<ExclamationTriangleIcon className="w-4 h-4" />
|
<ExclamationTriangleIcon className="w-4 h-4" />
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
{reportOpen && (
|
{reportTabOpen && (
|
||||||
<div
|
<div
|
||||||
tabIndex={0}
|
tabIndex={0}
|
||||||
className="dropdown-content card bg-base-200 w-150 shadow-md z-[1100] ml-2 border-1 border-error"
|
className="dropdown-content card bg-base-200 w-150 shadow-md z-[1100] ml-2 border-1 border-error"
|
||||||
@@ -107,7 +107,16 @@ export const Report = () => {
|
|||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
if (message.length < 1 || !selectedPlayer) return;
|
if (message.length < 1 || !selectedPlayer) return;
|
||||||
setSending(true);
|
setSending(true);
|
||||||
sendReport(selectedPlayer, message)
|
fetch("/api/dispatch/report", {
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
userId: selectedPlayer,
|
||||||
|
message: message,
|
||||||
|
}),
|
||||||
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
setMessage("");
|
setMessage("");
|
||||||
setSending(false);
|
setSending(false);
|
||||||
|
|||||||
@@ -356,7 +356,7 @@ const AircraftMarker = ({ aircraft }: { aircraft: Aircraft }) => {
|
|||||||
/>
|
/>
|
||||||
{openAircraftMarker.some((m) => m.id === aircraft.id) && !hideMarker && (
|
{openAircraftMarker.some((m) => m.id === aircraft.id) && !hideMarker && (
|
||||||
<SmartPopup
|
<SmartPopup
|
||||||
id={aircraft.id}
|
id={`aircraft-${aircraft.id}`}
|
||||||
ref={popupRef}
|
ref={popupRef}
|
||||||
position={[aircraft.location.lat, aircraft.location.lng]}
|
position={[aircraft.location.lat, aircraft.location.lng]}
|
||||||
autoClose={false}
|
autoClose={false}
|
||||||
|
|||||||
@@ -342,7 +342,7 @@ const MissionMarker = ({ mission }: { mission: Mission }) => {
|
|||||||
/>
|
/>
|
||||||
{openMissionMarker.some((m) => m.id === mission.id) && !hideMarker && (
|
{openMissionMarker.some((m) => m.id === mission.id) && !hideMarker && (
|
||||||
<SmartPopup
|
<SmartPopup
|
||||||
id={mission.id.toString()}
|
id={`cluster-${mission.id.toString()}`}
|
||||||
ref={popupRef}
|
ref={popupRef}
|
||||||
position={[mission.addressLat, mission.addressLng]}
|
position={[mission.addressLat, mission.addressLng]}
|
||||||
autoClose={false}
|
autoClose={false}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { Mission } from "@repo/db";
|
import { Mission } from "@repo/db";
|
||||||
import { SmartPopup, useSmartPopup } from "_components/SmartPopup";
|
import { SmartPopup, useSmartPopup } from "_components/SmartPopup";
|
||||||
import { Aircraft, useAircraftsStore } from "_store/aircraftsStore";
|
import { Aircraft, useAircraftsStore } from "_store/aircraftsStore";
|
||||||
|
import { useMapStore } from "_store/mapStore";
|
||||||
import { useMissionsStore } from "_store/missionsStore";
|
import { useMissionsStore } from "_store/missionsStore";
|
||||||
import {
|
import {
|
||||||
FMS_STATUS_COLORS,
|
FMS_STATUS_COLORS,
|
||||||
@@ -22,6 +23,10 @@ const PopupContent = ({
|
|||||||
missions: Mission[];
|
missions: Mission[];
|
||||||
}) => {
|
}) => {
|
||||||
const { anchor } = useSmartPopup();
|
const { anchor } = useSmartPopup();
|
||||||
|
const { setOpenAircraftMarker, setOpenMissionMarker } = useMapStore(
|
||||||
|
(state) => state,
|
||||||
|
);
|
||||||
|
const map = useMap();
|
||||||
|
|
||||||
let borderColor = "";
|
let borderColor = "";
|
||||||
|
|
||||||
@@ -33,7 +38,9 @@ const PopupContent = ({
|
|||||||
}
|
}
|
||||||
} else if (anchor.includes("bottom")) {
|
} else if (anchor.includes("bottom")) {
|
||||||
if (aircrafts.length > 0) {
|
if (aircrafts.length > 0) {
|
||||||
borderColor = FMS_STATUS_TEXT_COLORS[aircrafts[0]!.fmsStatus] || "white";
|
borderColor =
|
||||||
|
FMS_STATUS_TEXT_COLORS[aircrafts[aircrafts.length - 1]!.fmsStatus] ||
|
||||||
|
"white";
|
||||||
} else if (missions.length > 0) {
|
} else if (missions.length > 0) {
|
||||||
borderColor = MISSION_STATUS_TEXT_COLORS[missions[0]!.state];
|
borderColor = MISSION_STATUS_TEXT_COLORS[missions[0]!.state];
|
||||||
}
|
}
|
||||||
@@ -44,7 +51,7 @@ const PopupContent = ({
|
|||||||
<div className="relative flex flex-col text-white min-w-[200px]">
|
<div className="relative flex flex-col text-white min-w-[200px]">
|
||||||
<div
|
<div
|
||||||
className={cn(
|
className={cn(
|
||||||
"absolute w-[calc(100%+2px)] h-4 z-99",
|
"absolute w-[calc(100%+2px)] h-4 z-99 pointer-events-none",
|
||||||
anchor.includes("left") ? "-left-[2px]" : "-right-[2px]",
|
anchor.includes("left") ? "-left-[2px]" : "-right-[2px]",
|
||||||
anchor.includes("top") ? "-top-[2px]" : "-bottom-[2px]",
|
anchor.includes("top") ? "-top-[2px]" : "-bottom-[2px]",
|
||||||
)}
|
)}
|
||||||
@@ -69,9 +76,26 @@ const PopupContent = ({
|
|||||||
)}
|
)}
|
||||||
style={{
|
style={{
|
||||||
backgroundColor: MISSION_STATUS_COLORS[mission.state],
|
backgroundColor: MISSION_STATUS_COLORS[mission.state],
|
||||||
|
cursor: "pointer",
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<span className="mx-2 my-0.5">
|
<span
|
||||||
|
className="mx-2 my-0.5 flex-1 cursor-pointer"
|
||||||
|
onClick={() => {
|
||||||
|
setOpenMissionMarker({
|
||||||
|
open: [
|
||||||
|
{
|
||||||
|
id: mission.id,
|
||||||
|
tab: "home",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
close: [],
|
||||||
|
});
|
||||||
|
map.setView([mission.addressLat, mission.addressLng], 12, {
|
||||||
|
animate: true,
|
||||||
|
});
|
||||||
|
}}
|
||||||
|
>
|
||||||
{mission.missionKeywordAbbreviation}
|
{mission.missionKeywordAbbreviation}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
@@ -79,10 +103,24 @@ const PopupContent = ({
|
|||||||
{aircrafts.map((aircraft) => (
|
{aircrafts.map((aircraft) => (
|
||||||
<div
|
<div
|
||||||
key={aircraft.id}
|
key={aircraft.id}
|
||||||
className="relative w-auto inline-flex items-center gap-2 text-nowrap"
|
className="relative w-auto inline-flex items-center gap-2 text-nowrap cursor-pointer"
|
||||||
style={{
|
style={{
|
||||||
backgroundColor: FMS_STATUS_COLORS[aircraft.fmsStatus],
|
backgroundColor: FMS_STATUS_COLORS[aircraft.fmsStatus],
|
||||||
}}
|
}}
|
||||||
|
onClick={() => {
|
||||||
|
setOpenAircraftMarker({
|
||||||
|
open: [
|
||||||
|
{
|
||||||
|
id: aircraft.id,
|
||||||
|
tab: "aircraft",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
close: [],
|
||||||
|
});
|
||||||
|
map.setView([aircraft.location.lat, aircraft.location.lng], 12, {
|
||||||
|
animate: true,
|
||||||
|
});
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
<span
|
<span
|
||||||
className="mx-2 my-0.5 text-gt font-bold"
|
className="mx-2 my-0.5 text-gt font-bold"
|
||||||
@@ -227,10 +265,9 @@ export const MarkerCluster = () => {
|
|||||||
position={[c.lat, c.lng]}
|
position={[c.lat, c.lng]}
|
||||||
autoPan={false}
|
autoPan={false}
|
||||||
autoClose={false}
|
autoClose={false}
|
||||||
|
className="w-[202px]"
|
||||||
>
|
>
|
||||||
<div>
|
<PopupContent aircrafts={c.aircrafts} missions={c.missions} />
|
||||||
<PopupContent aircrafts={c.aircrafts} missions={c.missions} />
|
|
||||||
</div>
|
|
||||||
</SmartPopup>
|
</SmartPopup>
|
||||||
))}
|
))}
|
||||||
</>
|
</>
|
||||||
|
|||||||
@@ -9,10 +9,3 @@ export interface Dispatcher {
|
|||||||
name: string;
|
name: string;
|
||||||
socketId: string;
|
socketId: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const getDispatcher = async () => {
|
|
||||||
const res = await fetch(`
|
|
||||||
${process.env.NEXT_PUBLIC_DISPATCH_SERVER_URL}/dispatcher`);
|
|
||||||
const data = await res.json();
|
|
||||||
return data as Dispatcher[];
|
|
||||||
};
|
|
||||||
|
|||||||
Binary file not shown.
Reference in New Issue
Block a user