added mrt, dev
This commit is contained in:
46
apps/dispatch/app/_store/pilot/MrtStore.ts
Normal file
46
apps/dispatch/app/_store/pilot/MrtStore.ts
Normal 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
|
||||
},
|
||||
),
|
||||
);
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user