added DME, fixed sync and bugs. Rewrote setDisplay logic
This commit is contained in:
@@ -5,6 +5,7 @@ interface ConnectionStore {
|
||||
status: "connected" | "disconnected" | "connecting" | "error";
|
||||
message: string;
|
||||
selectedZone: string;
|
||||
logoffTime: string;
|
||||
connect: (
|
||||
uid: string,
|
||||
selectedZone: string,
|
||||
@@ -17,6 +18,7 @@ export const useDispatchConnectionStore = create<ConnectionStore>((set) => ({
|
||||
status: "disconnected",
|
||||
message: "",
|
||||
selectedZone: "LST_01",
|
||||
logoffTime: "",
|
||||
connect: async (uid, selectedZone, logoffTime) =>
|
||||
new Promise((resolve) => {
|
||||
set({ status: "connecting", message: "" });
|
||||
@@ -58,3 +60,12 @@ dispatchSocket.on("force-disconnect", (reason: string) => {
|
||||
message: reason,
|
||||
});
|
||||
});
|
||||
|
||||
dispatchSocket.on("reconnect", () => {
|
||||
const { logoffTime, selectedZone } = useDispatchConnectionStore.getState();
|
||||
|
||||
dispatchSocket.emit("connect-dispatch", {
|
||||
logoffTime,
|
||||
selectedZone,
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,25 +1,36 @@
|
||||
import { Station } from "@repo/db";
|
||||
import { fmsStatusDescription } from "_data/fmsStatusDescription";
|
||||
import { DisplayLineProps } from "pilot/_components/mrt/Mrt";
|
||||
import { create } from "zustand";
|
||||
import { syncTabs } from "zustand-sync-tabs";
|
||||
|
||||
type Page = "home" | "sending-status" | "new-status" | "error";
|
||||
interface SetHomePageParams {
|
||||
page: "home";
|
||||
station: Station;
|
||||
fmsStatus: string;
|
||||
}
|
||||
|
||||
type PageData = {
|
||||
home: undefined;
|
||||
"sending-status": undefined;
|
||||
"new-status": undefined;
|
||||
error: {
|
||||
message: string;
|
||||
};
|
||||
};
|
||||
interface SetSendingStatusPageParams {
|
||||
page: "sending-status";
|
||||
station: Station;
|
||||
}
|
||||
|
||||
interface SetNewStatusPageParams {
|
||||
page: "new-status";
|
||||
station: Station;
|
||||
}
|
||||
|
||||
type SetPageParams =
|
||||
| SetHomePageParams
|
||||
| SetSendingStatusPageParams
|
||||
| SetNewStatusPageParams;
|
||||
|
||||
interface MrtStore {
|
||||
page: Page;
|
||||
pageData: PageData[Page];
|
||||
page: SetPageParams["page"];
|
||||
|
||||
lines: DisplayLineProps[];
|
||||
|
||||
setPage: <P extends Page>(page: P, pageData?: PageData[P]) => void;
|
||||
setPage: (pageData: SetPageParams) => void;
|
||||
setLines: (lines: MrtStore["lines"]) => void;
|
||||
}
|
||||
|
||||
@@ -30,14 +41,93 @@ export const useMrtStore = create<MrtStore>(
|
||||
pageData: {
|
||||
message: "",
|
||||
},
|
||||
lines: Array.from(Array(10).keys()).map(() => ({
|
||||
textLeft: "",
|
||||
textMid: "",
|
||||
textRight: "",
|
||||
textSize: "1",
|
||||
})),
|
||||
lines: [
|
||||
{
|
||||
textLeft: "VAR.#",
|
||||
textSize: "2",
|
||||
},
|
||||
{
|
||||
textLeft: "No Data",
|
||||
textSize: "3",
|
||||
},
|
||||
],
|
||||
setLines: (lines) => set({ lines }),
|
||||
setPage: (page, pageData) => set({ page, pageData }),
|
||||
setPage: (pageData) => {
|
||||
switch (pageData.page) {
|
||||
case "home": {
|
||||
const { station, fmsStatus } = pageData as SetHomePageParams;
|
||||
set({
|
||||
page: "home",
|
||||
lines: [
|
||||
{
|
||||
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",
|
||||
},
|
||||
],
|
||||
});
|
||||
break;
|
||||
}
|
||||
|
||||
case "sending-status": {
|
||||
const { station } = pageData as SetSendingStatusPageParams;
|
||||
set({
|
||||
page: "sending-status",
|
||||
lines: [
|
||||
{
|
||||
textLeft: `VAR#.${station?.bosCallsign}`,
|
||||
style: { fontWeight: "bold" },
|
||||
textSize: "2",
|
||||
},
|
||||
{ textLeft: "ILS VAR#", textSize: "3" },
|
||||
{
|
||||
textMid: "sending...",
|
||||
style: { fontWeight: "bold" },
|
||||
textSize: "4",
|
||||
},
|
||||
{
|
||||
textLeft: "Status wird gesendet...",
|
||||
textSize: "1",
|
||||
},
|
||||
],
|
||||
});
|
||||
break;
|
||||
}
|
||||
case "new-status": {
|
||||
const { station } = pageData as SetNewStatusPageParams;
|
||||
set({
|
||||
page: "new-status",
|
||||
lines: [
|
||||
{
|
||||
textLeft: `VAR#.${station?.bosCallsign}`,
|
||||
style: { fontWeight: "bold" },
|
||||
textSize: "2",
|
||||
},
|
||||
{ textLeft: "ILS VAR#", textSize: "3" },
|
||||
{
|
||||
textLeft: "new status received",
|
||||
style: { fontWeight: "bold" },
|
||||
textSize: "4",
|
||||
},
|
||||
],
|
||||
});
|
||||
break;
|
||||
}
|
||||
default:
|
||||
set({ page: "home" });
|
||||
break;
|
||||
}
|
||||
},
|
||||
}),
|
||||
{
|
||||
name: "mrt-store", // unique name
|
||||
|
||||
@@ -2,7 +2,7 @@ import { create } from "zustand";
|
||||
import { dispatchSocket } from "../../dispatch/socket";
|
||||
import { ConnectedAircraft, Mission, Station } from "@repo/db";
|
||||
import { pilotSocket } from "pilot/socket";
|
||||
import { useMrtStore } from "_store/pilot/MrtStore";
|
||||
import { useDmeStore } from "_store/pilot/dmeStore";
|
||||
|
||||
interface ConnectionStore {
|
||||
status: "connected" | "disconnected" | "connecting" | "error";
|
||||
@@ -75,11 +75,14 @@ pilotSocket.on("aircraft-update", (data) => {
|
||||
usePilotConnectionStore.setState({
|
||||
connectedAircraft: data,
|
||||
});
|
||||
useMrtStore.getState().setLines(getNew);
|
||||
/* useMrtStore.getState().setLines(getNew); */
|
||||
});
|
||||
|
||||
pilotSocket.on("mission-alert", (data) => {
|
||||
pilotSocket.on("mission-alert", (data: Mission & { Stations: Station[] }) => {
|
||||
usePilotConnectionStore.setState({
|
||||
activeMission: data,
|
||||
});
|
||||
useDmeStore.getState().setPage({
|
||||
page: "new-mission",
|
||||
});
|
||||
});
|
||||
|
||||
195
apps/dispatch/app/_store/pilot/dmeStore.ts
Normal file
195
apps/dispatch/app/_store/pilot/dmeStore.ts
Normal file
@@ -0,0 +1,195 @@
|
||||
import { Mission, Station, User } from "@repo/db";
|
||||
import { DisplayLineProps } from "pilot/_components/dme/Dme";
|
||||
import { create } from "zustand";
|
||||
import { syncTabs } from "zustand-sync-tabs";
|
||||
|
||||
interface SetHomePageParams {
|
||||
page: "home";
|
||||
user: User;
|
||||
station: Station;
|
||||
}
|
||||
|
||||
interface SetErrorPageParams {
|
||||
page: "error";
|
||||
error: string;
|
||||
}
|
||||
|
||||
interface SetNewMissionPageParams {
|
||||
page: "new-mission";
|
||||
}
|
||||
|
||||
interface SetMissionPageParams {
|
||||
page: "mission";
|
||||
mission: Mission & { Stations: Station[] };
|
||||
}
|
||||
|
||||
interface SetAcknowledgePageParams {
|
||||
page: "acknowledge";
|
||||
}
|
||||
|
||||
type SetPageParams =
|
||||
| SetHomePageParams
|
||||
| SetNewMissionPageParams
|
||||
| SetMissionPageParams
|
||||
| SetErrorPageParams
|
||||
| SetAcknowledgePageParams;
|
||||
|
||||
interface MrtStore {
|
||||
page: SetPageParams["page"];
|
||||
|
||||
lines: DisplayLineProps[];
|
||||
|
||||
setPage: (pageData: SetPageParams) => void;
|
||||
setLines: (lines: MrtStore["lines"]) => void;
|
||||
}
|
||||
|
||||
export const useDmeStore = create<MrtStore>(
|
||||
syncTabs(
|
||||
(set) => ({
|
||||
page: "home",
|
||||
pageData: {
|
||||
message: "",
|
||||
},
|
||||
lines: [
|
||||
{
|
||||
textLeft: "VAR.#",
|
||||
textSize: "2",
|
||||
},
|
||||
{
|
||||
textLeft: "No Data",
|
||||
},
|
||||
],
|
||||
setLines: (lines) => set({ lines }),
|
||||
setPage: (pageData) => {
|
||||
switch (pageData.page) {
|
||||
case "home": {
|
||||
set({
|
||||
page: "home",
|
||||
lines: [
|
||||
{ textMid: "⠀" },
|
||||
{
|
||||
textMid: pageData.station.bosCallsign
|
||||
? `VAR#.${pageData.station.bosCallsign}`
|
||||
: "no Data",
|
||||
style: { fontWeight: "bold" },
|
||||
},
|
||||
{ textMid: "⠀" },
|
||||
{
|
||||
textMid: new Date().toLocaleDateString(),
|
||||
},
|
||||
{
|
||||
textMid: new Date().toLocaleTimeString(),
|
||||
style: { fontWeight: "bold" },
|
||||
},
|
||||
{ textMid: "⠀" },
|
||||
{
|
||||
textMid: `${pageData.user.lastname} ${pageData.user.firstname}`,
|
||||
},
|
||||
{ textMid: "⠀" },
|
||||
],
|
||||
});
|
||||
break;
|
||||
}
|
||||
|
||||
case "new-mission": {
|
||||
set({
|
||||
page: "new-mission",
|
||||
lines: [
|
||||
{ textMid: "⠀" },
|
||||
{
|
||||
textMid: "new mission received",
|
||||
style: { fontWeight: "bold" },
|
||||
},
|
||||
{ textMid: "⠀" },
|
||||
],
|
||||
});
|
||||
break;
|
||||
}
|
||||
case "mission": {
|
||||
set({
|
||||
page: "mission",
|
||||
lines: [
|
||||
{
|
||||
textLeft: `${pageData.mission.missionKeywordAbbreviation}`,
|
||||
textRight: pageData.mission.Stations.map(
|
||||
(s) => s.bosCallsignShort,
|
||||
).join(","),
|
||||
style: { fontWeight: "bold" },
|
||||
},
|
||||
{
|
||||
textMid: `${pageData.mission.missionKeywordName}`,
|
||||
style: { fontWeight: "bold" },
|
||||
},
|
||||
{ textLeft: `${pageData.mission.addressStreet}` },
|
||||
{
|
||||
textLeft: `${pageData.mission.addressZip} ${pageData.mission.addressCity}`,
|
||||
},
|
||||
{
|
||||
textMid: "Patienteninfos:",
|
||||
style: { fontWeight: "bold" },
|
||||
},
|
||||
{
|
||||
textLeft:
|
||||
pageData.mission.missionPatientInfo || "keine Daten",
|
||||
},
|
||||
{
|
||||
textMid: "Weitere Infos:",
|
||||
style: { fontWeight: "bold" },
|
||||
},
|
||||
{
|
||||
textLeft:
|
||||
pageData.mission.missionAdditionalInfo || "keine Daten",
|
||||
},
|
||||
],
|
||||
});
|
||||
break;
|
||||
}
|
||||
case "error": {
|
||||
set({
|
||||
page: "error",
|
||||
lines: [
|
||||
{ textMid: "Fehler:" },
|
||||
{
|
||||
textMid: pageData.error,
|
||||
style: { fontWeight: "bold" },
|
||||
},
|
||||
{ textMid: "⠀" },
|
||||
],
|
||||
});
|
||||
break;
|
||||
}
|
||||
case "acknowledge": {
|
||||
set({
|
||||
page: "acknowledge",
|
||||
lines: [
|
||||
{ textMid: "⠀" },
|
||||
{
|
||||
textMid: "Einsatz angenommen",
|
||||
style: { fontWeight: "bold" },
|
||||
},
|
||||
{ textMid: "⠀" },
|
||||
],
|
||||
});
|
||||
break;
|
||||
}
|
||||
default:
|
||||
set({
|
||||
page: "error",
|
||||
lines: [
|
||||
{ textMid: "Fehler:" },
|
||||
{
|
||||
textMid: `Unbekannte Seite`,
|
||||
style: { fontWeight: "bold" },
|
||||
},
|
||||
{ textMid: "⠀" },
|
||||
],
|
||||
});
|
||||
break;
|
||||
}
|
||||
},
|
||||
}),
|
||||
{
|
||||
name: "dme-store", // unique name
|
||||
},
|
||||
),
|
||||
);
|
||||
Reference in New Issue
Block a user