added DME, fixed sync and bugs. Rewrote setDisplay logic
This commit is contained in:
@@ -1,115 +1,23 @@
|
||||
import { useSession } from "next-auth/react";
|
||||
import { ConnectedAircraft } from "@repo/db";
|
||||
import { usePilotConnectionStore } from "_store/pilot/connectionStore";
|
||||
import { useMrtStore } from "_store/pilot/MrtStore";
|
||||
import { pilotSocket } from "pilot/socket";
|
||||
import { editConnectedAircraftAPI } from "querys/aircrafts";
|
||||
import { Station } from "@repo/db";
|
||||
import { DisplayLineProps } from "pilot/_components/mrt/Mrt";
|
||||
|
||||
export const fmsStatusDescription: { [key: string]: string } = {
|
||||
NaN: "Keine Daten",
|
||||
"0": "Prio. Sprechwunsch",
|
||||
"1": "Frei auf Funk",
|
||||
"2": "Einsatzbereit am LRZ",
|
||||
"3": "Auf dem Weg",
|
||||
"4": "Am Einsatzort",
|
||||
"5": "Sprechwunsch",
|
||||
"6": "Nicht einsatzbereit",
|
||||
"7": "Patient aufgenommen",
|
||||
"8": "Am Transportziel",
|
||||
"9": "Fremdanmeldung",
|
||||
E: "Indent/Abbruch/Einsatzbefehl abgebrochen",
|
||||
C: "Anmelden zur Übernahme des Einsatzes",
|
||||
F: "Kommen über Draht",
|
||||
H: "Fahren auf Wache",
|
||||
J: "Sprechaufforderung",
|
||||
L: "Lagebericht abgeben",
|
||||
P: "Einsatz mit Polizei/Pause machen",
|
||||
U: "Ungültiger Status",
|
||||
c: "Status korrigieren",
|
||||
d: "Transportziel angeben",
|
||||
h: "Zielklinik verständigt",
|
||||
o: "Warten, alle Abfrageplätze belegt",
|
||||
u: "Verstanden",
|
||||
};
|
||||
|
||||
export const getSendingLines = (station: Station): DisplayLineProps[] => {
|
||||
return [
|
||||
{
|
||||
textLeft: `VAR#.${station?.bosCallsign}123`,
|
||||
style: { fontWeight: "bold" },
|
||||
textSize: "2",
|
||||
},
|
||||
{ textLeft: "ILS VAR#", textSize: "3" },
|
||||
{
|
||||
textMid: "sending...",
|
||||
style: { fontWeight: "bold" },
|
||||
textSize: "4",
|
||||
},
|
||||
{
|
||||
textLeft: "Status wird gesendet...",
|
||||
textSize: "1",
|
||||
},
|
||||
];
|
||||
};
|
||||
|
||||
export const getHomeLines = (
|
||||
station: Station,
|
||||
fmsStatus: string,
|
||||
): DisplayLineProps[] => {
|
||||
return [
|
||||
{
|
||||
textLeft: `VAR#.${station?.bosCallsign}`,
|
||||
style: { fontWeight: "bold" },
|
||||
textSize: "2",
|
||||
},
|
||||
{ textLeft: "ILS VAR#", textSize: "3" },
|
||||
{
|
||||
textLeft: fmsStatus,
|
||||
style: { fontWeight: "extrabold" },
|
||||
textSize: "4",
|
||||
},
|
||||
{
|
||||
textLeft: fmsStatusDescription[fmsStatus],
|
||||
textSize: "1",
|
||||
},
|
||||
];
|
||||
};
|
||||
|
||||
export const getNewStatusLines = (
|
||||
station: Station,
|
||||
fmsStatus: string,
|
||||
): DisplayLineProps[] => {
|
||||
return [
|
||||
{
|
||||
textLeft: `VAR#.${station?.bosCallsign}`,
|
||||
style: { fontWeight: "bold" },
|
||||
textSize: "2",
|
||||
},
|
||||
{ textLeft: "ILS VAR#", textSize: "3" },
|
||||
{
|
||||
textLeft: fmsStatus,
|
||||
style: { fontWeight: "extrabold" },
|
||||
textSize: "4",
|
||||
},
|
||||
{
|
||||
textLeft: fmsStatusDescription[fmsStatus],
|
||||
textSize: "1",
|
||||
},
|
||||
];
|
||||
};
|
||||
import { useEffect } from "react";
|
||||
|
||||
export const useButtons = () => {
|
||||
const user = useSession().data?.user;
|
||||
const station = usePilotConnectionStore((state) => state.selectedStation);
|
||||
const connectedAircraft = usePilotConnectionStore(
|
||||
(state) => state.connectedAircraft,
|
||||
);
|
||||
const connectionStatus = usePilotConnectionStore((state) => state.status);
|
||||
|
||||
const { page, setLines } = useMrtStore((state) => state);
|
||||
const { page, setPage } = useMrtStore((state) => state);
|
||||
|
||||
const handleButton =
|
||||
(button: "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" | "0") =>
|
||||
() => {
|
||||
if (connectionStatus !== "connected") return;
|
||||
if (!station) return;
|
||||
if (!connectedAircraft?.id) return;
|
||||
if (
|
||||
@@ -125,16 +33,32 @@ export const useButtons = () => {
|
||||
button === "0"
|
||||
) {
|
||||
if (page !== "home") return;
|
||||
setLines(getSendingLines(station));
|
||||
setPage({ page: "sending-status", station });
|
||||
|
||||
setTimeout(async () => {
|
||||
await editConnectedAircraftAPI(connectedAircraft!.id, {
|
||||
fmsStatus: button,
|
||||
});
|
||||
setLines(getNewStatusLines(station, button));
|
||||
setPage({
|
||||
page: "home",
|
||||
station,
|
||||
fmsStatus: button,
|
||||
});
|
||||
}, 1000);
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
pilotSocket.on("connect", () => {
|
||||
if (!station) return;
|
||||
setPage({ page: "home", fmsStatus: "6", station });
|
||||
});
|
||||
|
||||
pilotSocket.on("aircraft-update", () => {
|
||||
if (!station) return;
|
||||
setPage({ page: "new-status", station });
|
||||
});
|
||||
}, [setPage, station]);
|
||||
|
||||
return { handleButton };
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user