added mrt, dev

This commit is contained in:
PxlLoewe
2025-05-18 23:21:08 -07:00
parent 6b58f564b2
commit 1b16b365bd
25 changed files with 514 additions and 5 deletions

View File

@@ -0,0 +1,46 @@
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";
type PageData = {
home: undefined;
"sending-status": undefined;
"new-status": undefined;
error: {
message: string;
};
};
interface MrtStore {
page: Page;
pageData: PageData[Page];
lines: DisplayLineProps[];
setPage: <P extends Page>(page: P, pageData?: PageData[P]) => void;
setLines: (lines: MrtStore["lines"]) => void;
}
export const useMrtStore = create<MrtStore>(
syncTabs(
(set) => ({
page: "home",
pageData: {
message: "",
},
lines: Array.from(Array(10).keys()).map(() => ({
textLeft: "",
textMid: "",
textRight: "",
textSize: "1",
})),
setLines: (lines) => set({ lines }),
setPage: (page, pageData) => set({ page, pageData }),
}),
{
name: "mrt-store", // unique name
},
),
);

View File

@@ -1,12 +1,14 @@
import { create } from "zustand";
import { dispatchSocket } from "../../dispatch/socket";
import { Mission, Station } from "@repo/db";
import { ConnectedAircraft, Mission, Station } from "@repo/db";
import { pilotSocket } from "pilot/socket";
import { useMrtStore } from "_store/pilot/MrtStore";
interface ConnectionStore {
status: "connected" | "disconnected" | "connecting" | "error";
message: string;
selectedStation: Station | null;
connectedAircraft: ConnectedAircraft | null;
activeMission:
| (Mission & {
Stations: Station[];
@@ -25,6 +27,7 @@ export const usePilotConnectionStore = create<ConnectionStore>((set) => ({
status: "disconnected",
message: "",
selectedStation: null,
connectedAircraft: null,
activeMission: null,
connect: async (uid, stationId, logoffTime, station) =>
new Promise((resolve) => {
@@ -68,6 +71,13 @@ pilotSocket.on("force-disconnect", (reason: string) => {
});
});
pilotSocket.on("aircraft-update", (data) => {
usePilotConnectionStore.setState({
connectedAircraft: data,
});
useMrtStore.getState().setLines(getNew);
});
pilotSocket.on("mission-alert", (data) => {
usePilotConnectionStore.setState({
activeMission: data,