Files
var-monorepo/apps/dispatch/app/_store/aircraftsStore.ts
2025-04-25 12:02:59 -07:00

113 lines
2.1 KiB
TypeScript

import { create } from "zustand";
export interface Aircraft {
id: string;
bosName: string;
bosNameShort: string;
bosNutzung: string;
fmsStatus: string;
fmsLog: {
status: string;
timestamp: string;
user: string;
}[];
location: {
lat: number;
lng: number;
altitude: number;
speed: number;
};
locationHistory: {
lat: number;
lon: number;
altitude: number;
speed: number;
timestamp: string;
}[];
}
interface AircraftStore {
aircrafts: Aircraft[];
setAircrafts: (aircrafts: Aircraft[]) => void;
setAircraft: (aircraft: Aircraft) => void;
}
export const useAircraftsStore = create<AircraftStore>((set) => ({
aircrafts: [
{
id: "1",
bosName: "Christoph 31",
bosNameShort: "CHX31",
bosNutzung: "RTH",
fmsStatus: "1",
fmsLog: [],
location: {
lat: 52.546781040592776,
lng: 13.369535209542219,
altitude: 0,
speed: 0,
},
locationHistory: [],
},
{
id: "2",
bosName: "Christoph Berlin",
bosNameShort: "CHX83",
bosNutzung: "ITH",
fmsStatus: "2",
fmsLog: [],
location: {
lat: 52.54588546048977,
lng: 13.46470691054384,
altitude: 0,
speed: 0,
},
locationHistory: [],
},
{
id: "3",
bosName: "Christoph 100",
bosNameShort: "CHX100",
bosNutzung: "RTH",
fmsStatus: "7",
fmsLog: [],
location: {
lat: 52.497519717230155,
lng: 13.342040806552554,
altitude: 0,
speed: 0,
},
locationHistory: [],
},
{
id: "4",
bosName: "Christophorus 1",
bosNameShort: "A4",
bosNutzung: "RTH",
fmsStatus: "6",
fmsLog: [],
location: {
lat: 52.50175041192073,
lng: 13.478628701227349,
altitude: 0,
speed: 0,
},
locationHistory: [],
},
],
setAircrafts: (aircrafts) => set({ aircrafts }),
setAircraft: (aircraft) =>
set((state) => {
const existingAircraftIndex = state.aircrafts.findIndex(
(a) => a.id === aircraft.id,
);
if (existingAircraftIndex !== -1) {
const updatedAircrafts = [...state.aircrafts];
updatedAircrafts[existingAircraftIndex] = aircraft;
return { aircrafts: updatedAircrafts };
} else {
return { aircrafts: [...state.aircrafts, aircraft] };
}
}),
}));