changes pilot socket to reperate pilto socket, added pilot stats
This commit is contained in:
@@ -1,12 +1,17 @@
|
||||
import { create } from "zustand";
|
||||
import { dispatchSocket } from "../../dispatch/socket";
|
||||
import { Station } from "@repo/db";
|
||||
import { Mission, Station } from "@repo/db";
|
||||
import { pilotSocket } from "pilot/socket";
|
||||
|
||||
interface ConnectionStore {
|
||||
status: "connected" | "disconnected" | "connecting" | "error";
|
||||
message: string;
|
||||
selectedStation: Station | null;
|
||||
activeMission:
|
||||
| (Mission & {
|
||||
Stations: Station[];
|
||||
})
|
||||
| null;
|
||||
connect: (
|
||||
uid: string,
|
||||
stationId: string,
|
||||
@@ -20,13 +25,14 @@ export const usePilotConnectionStore = create<ConnectionStore>((set) => ({
|
||||
status: "disconnected",
|
||||
message: "",
|
||||
selectedStation: null,
|
||||
activeMission: null,
|
||||
connect: async (uid, stationId, logoffTime, station) =>
|
||||
new Promise((resolve) => {
|
||||
set({ status: "connecting", message: "", selectedStation: station });
|
||||
dispatchSocket.auth = { uid };
|
||||
dispatchSocket.connect();
|
||||
dispatchSocket.once("connect", () => {
|
||||
dispatchSocket.emit("connect-pilot", {
|
||||
pilotSocket.auth = { uid };
|
||||
pilotSocket.connect();
|
||||
pilotSocket.once("connect", () => {
|
||||
pilotSocket.emit("connect-pilot", {
|
||||
logoffTime,
|
||||
stationId,
|
||||
});
|
||||
@@ -34,30 +40,36 @@ export const usePilotConnectionStore = create<ConnectionStore>((set) => ({
|
||||
});
|
||||
}),
|
||||
disconnect: () => {
|
||||
dispatchSocket.disconnect();
|
||||
pilotSocket.disconnect();
|
||||
},
|
||||
}));
|
||||
|
||||
dispatchSocket.on("connect", () => {
|
||||
pilotSocket.disconnect();
|
||||
pilotSocket.on("connect", () => {
|
||||
dispatchSocket.disconnect();
|
||||
usePilotConnectionStore.setState({ status: "connected", message: "" });
|
||||
});
|
||||
|
||||
dispatchSocket.on("connect_error", (err) => {
|
||||
pilotSocket.on("connect_error", (err) => {
|
||||
usePilotConnectionStore.setState({
|
||||
status: "error",
|
||||
message: err.message,
|
||||
});
|
||||
});
|
||||
|
||||
dispatchSocket.on("disconnect", () => {
|
||||
pilotSocket.on("disconnect", () => {
|
||||
usePilotConnectionStore.setState({ status: "disconnected", message: "" });
|
||||
});
|
||||
|
||||
dispatchSocket.on("force-disconnect", (reason: string) => {
|
||||
pilotSocket.on("force-disconnect", (reason: string) => {
|
||||
console.log("force-disconnect", reason);
|
||||
usePilotConnectionStore.setState({
|
||||
status: "disconnected",
|
||||
message: reason,
|
||||
});
|
||||
});
|
||||
|
||||
pilotSocket.on("mission-alert", (data) => {
|
||||
usePilotConnectionStore.setState({
|
||||
activeMission: data,
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
"use client";
|
||||
import React, { useState } from "react";
|
||||
import { FMS_STATUS_TEXT_COLORS } from "../AircraftMarker";
|
||||
/* import { Select } from "_components/Select";
|
||||
import { Station } from "@repo/db";
|
||||
import { getStations } from "dispatch/_components/pannel/action"; */
|
||||
import { toast } from "react-hot-toast";
|
||||
import {
|
||||
Ban,
|
||||
BellRing,
|
||||
@@ -29,7 +27,11 @@ import {
|
||||
import { usePannelStore } from "_store/pannelStore";
|
||||
import { useSession } from "next-auth/react";
|
||||
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
||||
import { deleteMissionAPI, editMissionAPI } from "querys/missions";
|
||||
import {
|
||||
deleteMissionAPI,
|
||||
editMissionAPI,
|
||||
sendMissionAPI,
|
||||
} from "querys/missions";
|
||||
|
||||
const Einsatzdetails = ({ mission }: { mission: Mission }) => {
|
||||
const queryClient = useQueryClient();
|
||||
@@ -42,6 +44,20 @@ const Einsatzdetails = ({ mission }: { mission: Mission }) => {
|
||||
});
|
||||
},
|
||||
});
|
||||
const sendAlertMutation = useMutation({
|
||||
mutationKey: ["missions"],
|
||||
mutationFn: sendMissionAPI,
|
||||
onError: (error) => {
|
||||
console.error(error);
|
||||
toast.error("Fehler beim Alarmieren");
|
||||
},
|
||||
onSuccess: (data) => {
|
||||
toast.success(data.message);
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ["missions"],
|
||||
});
|
||||
},
|
||||
});
|
||||
const { setMissionFormValues, setOpen } = usePannelStore((state) => state);
|
||||
return (
|
||||
<div className="p-4 text-base-content">
|
||||
@@ -76,7 +92,10 @@ const Einsatzdetails = ({ mission }: { mission: Mission }) => {
|
||||
</div>
|
||||
<div className="divider mt-0 mb-0" />
|
||||
<div className="flex items-center gap-2 w-full">
|
||||
<button className="btn btn-sm btn-info btn-outline flex-3">
|
||||
<button
|
||||
className="btn btn-sm btn-info btn-outline flex-3"
|
||||
onClick={() => sendAlertMutation.mutate(mission.id)}
|
||||
>
|
||||
<span className="flex items-center gap-2">
|
||||
<BellRing size={16} /> Alarmieren
|
||||
</span>
|
||||
|
||||
@@ -176,7 +176,7 @@ export const MissionForm = () => {
|
||||
form={form}
|
||||
options={stations?.map((s) => ({
|
||||
label: s.bosCallsign,
|
||||
value: s.id.toString(),
|
||||
value: s.id,
|
||||
}))}
|
||||
/>
|
||||
</div>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { pilotSocket } from "pilot/socket";
|
||||
"use client";
|
||||
import { io } from "socket.io-client";
|
||||
|
||||
export const dispatchSocket = io(process.env.NEXT_PUBLIC_DISPATCH_SERVER_URL, {
|
||||
|
||||
@@ -1,14 +1,12 @@
|
||||
"use client";
|
||||
|
||||
import { Pannel } from "dispatch/_components/pannel/Pannel";
|
||||
import { usePannelStore } from "_store/pannelStore";
|
||||
import { cn } from "helpers/cn";
|
||||
import dynamic from "next/dynamic";
|
||||
import { Chat } from "../_components/left/Chat";
|
||||
import { Report } from "../_components/left/Report";
|
||||
import { usePilotConnectionStore } from "_store/pilot/connectionStore";
|
||||
|
||||
const DispatchPage = () => {
|
||||
const { isOpen } = usePannelStore();
|
||||
const { activeMission } = usePilotConnectionStore();
|
||||
|
||||
return (
|
||||
<div className="relative flex-1 flex transition-all duration-500 ease w-full">
|
||||
{/* <MapToastCard2 /> */}
|
||||
@@ -20,14 +18,7 @@ const DispatchPage = () => {
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
className={cn(
|
||||
"absolute right-0 w-[500px] z-999 transition-transform",
|
||||
isOpen ? "translate-x-0" : "translate-x-full",
|
||||
)}
|
||||
>
|
||||
<Pannel />
|
||||
</div>
|
||||
<div>{JSON.stringify(activeMission)}</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
"use client";
|
||||
|
||||
import { io } from "socket.io-client";
|
||||
import { dispatchSocket } from "dispatch/socket";
|
||||
|
||||
export const pilotSocket = io(process.env.NEXT_PUBLIC_DISPATCH_SERVER_URL, {
|
||||
autoConnect: false,
|
||||
|
||||
@@ -27,6 +27,13 @@ export const editMissionAPI = async (
|
||||
return respone.data;
|
||||
};
|
||||
|
||||
export const sendMissionAPI = async (id: number) => {
|
||||
const respone = await serverApi.post<{
|
||||
message: string;
|
||||
}>(`/mission/${id}/send-alert`);
|
||||
return respone.data;
|
||||
};
|
||||
|
||||
export const deleteMissionAPI = async (id: number) => {
|
||||
await serverApi.delete(`/mission/${id}`);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user