added ntfy

This commit is contained in:
PxlLoewe
2025-05-19 23:11:33 -07:00
parent 61e7caf6c8
commit 060810f1b0
11 changed files with 277 additions and 76 deletions

View File

@@ -38,6 +38,7 @@ export function QueryProvider({ children }: { children: ReactNode }) {
};
const invalidateConenctedAircrafts = () => {
console.log("invalidateConenctedAircrafts");
queryClient.invalidateQueries({
queryKey: ["aircrafts"],
});

View File

@@ -1,6 +1,6 @@
import { create } from "zustand";
import { dispatchSocket } from "../../dispatch/socket";
import { ConnectedAircraft, Mission, Station } from "@repo/db";
import { ConnectedAircraft, Mission, Station, User } from "@repo/db";
import { pilotSocket } from "pilot/socket";
import { useDmeStore } from "_store/pilot/dmeStore";
@@ -19,6 +19,7 @@ interface ConnectionStore {
stationId: string,
logoffTime: string,
station: Station,
user: User,
) => Promise<void>;
disconnect: () => void;
}
@@ -29,12 +30,18 @@ export const usePilotConnectionStore = create<ConnectionStore>((set) => ({
selectedStation: null,
connectedAircraft: null,
activeMission: null,
connect: async (uid, stationId, logoffTime, station) =>
connect: async (uid, stationId, logoffTime, station, user) =>
new Promise((resolve) => {
set({ status: "connecting", message: "", selectedStation: station });
pilotSocket.auth = { uid };
pilotSocket.connect();
pilotSocket.once("connect", () => {
useDmeStore.getState().setPage({
page: "home",
station,
user,
});
pilotSocket.emit("connect-pilot", {
logoffTime,
stationId,

View File

@@ -43,6 +43,8 @@ interface MrtStore {
setLines: (lines: MrtStore["lines"]) => void;
}
let interval: NodeJS.Timeout | null = null;
export const useDmeStore = create<MrtStore>(
syncTabs(
(set) => ({
@@ -52,42 +54,52 @@ export const useDmeStore = create<MrtStore>(
},
lines: [
{
textLeft: "VAR.#",
textLeft: "",
},
{
textMid: "VAR . DME# No Data",
textSize: "2",
},
{
textLeft: "No Data",
textLeft: "",
},
],
setLines: (lines) => set({ lines }),
setPage: (pageData) => {
if (interval) clearInterval(interval);
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: "" },
],
});
const setHomePage = () =>
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: "" },
],
});
setHomePage();
interval = setInterval(() => {
setHomePage();
}, 1000);
break;
}

View File

@@ -10,12 +10,16 @@ export const useButtons = () => {
const handleButton = (button: "main" | "menu" | "left" | "right") => () => {
switch (button) {
case "main":
if (page === "mission") {
if (page === "mission" || page === "new-mission") {
setPage({ page: "acknowledge" });
}
break;
case "menu":
console.log("home", page, { station, user });
if (page === "mission" || page === "new-mission") {
setPage({ page: "acknowledge" });
if (station && user) setPage({ page: "home", station, user });
break;
}
if (station && user) {
setPage({ page: "home", station, user });
} else {

View File

@@ -130,16 +130,20 @@ export const ConnectionBtn = () => {
type="submit"
onSubmit={() => false}
onClick={() => {
connection.connect(
uid,
form.selectedStationId?.toString() || "",
form.logoffTime || "",
stations?.find(
(station) =>
station.id ===
parseInt(form.selectedStationId?.toString() || ""),
)!,
const selectedStation = stations?.find(
(station) =>
station.id ===
parseInt(form.selectedStationId?.toString() || ""),
);
if (selectedStation) {
connection.connect(
uid,
form.selectedStationId?.toString() || "",
form.logoffTime || "",
selectedStation,
session.data!.user,
);
}
}}
className="btn btn-soft btn-info"
>