From ea21c8d141b22ea89d707c12a2f984b049d16b3b Mon Sep 17 00:00:00 2001 From: nocnico Date: Thu, 5 Jun 2025 22:56:17 +0200 Subject: [PATCH] Fix some bugs #34 --- .../_components/navbar/ModeSwitchDropdown.tsx | 29 ++++-- .../pilot/_components/ConnectedDispatcher.tsx | 96 +++++++++++++++++++ apps/dispatch/app/pilot/page.tsx | 2 + pnpm-lock.yaml | 3 - 4 files changed, 118 insertions(+), 12 deletions(-) create mode 100644 apps/dispatch/app/pilot/_components/ConnectedDispatcher.tsx diff --git a/apps/dispatch/app/_components/navbar/ModeSwitchDropdown.tsx b/apps/dispatch/app/_components/navbar/ModeSwitchDropdown.tsx index 2e89c7b6..3a323a6c 100644 --- a/apps/dispatch/app/_components/navbar/ModeSwitchDropdown.tsx +++ b/apps/dispatch/app/_components/navbar/ModeSwitchDropdown.tsx @@ -1,30 +1,41 @@ "use client"; -import { ArrowLeftRight, Plane, Workflow } from "lucide-react"; +import { ArrowLeftRight, Plane, Radar, Workflow } from "lucide-react"; +import { useSession } from "next-auth/react"; import Link from "next/link"; import { usePathname } from "next/navigation"; export default function ModeSwitchDropdown() { const path = usePathname(); + const session = useSession(); return (
- {path.includes("pilot") && "Pilot"} + {path.includes("pilot") && "Pilot"} {path.includes("dispatch") && "Leitstelle"}
diff --git a/apps/dispatch/app/pilot/_components/ConnectedDispatcher.tsx b/apps/dispatch/app/pilot/_components/ConnectedDispatcher.tsx new file mode 100644 index 00000000..d81bf1b4 --- /dev/null +++ b/apps/dispatch/app/pilot/_components/ConnectedDispatcher.tsx @@ -0,0 +1,96 @@ +import { BADGES, PublicUser } from "@repo/db"; +import { useQuery } from "@tanstack/react-query"; +import { Badge } from "_components/Badge/Badge"; +import { getConnectedAircraftsAPI } from "_querys/aircrafts"; +import { getConnectedDispatcherAPI } from "_querys/connected-user"; +import { Plane, Workflow } from "lucide-react"; + +export const ConnectedDispatcher = () => { + const { data: dispatcher } = useQuery({ + queryKey: ["dispatcher"], + queryFn: () => getConnectedDispatcherAPI(), + refetchInterval: 10000, + }); + const { data: aircrafts } = useQuery({ + queryKey: ["aircrafts"], + queryFn: () => getConnectedAircraftsAPI(), + refetchInterval: 10000, + }); + + const connections = (aircrafts?.length || 0) + (dispatcher?.length || 0); + + return ( +
+
+
+ + {/*
Kein Disponent Online
*/} +
+ + {connections} {connections == 1 ? "Verbundenes Mitglied" : "Verbundene Mitglieder"} + +
+
0 ? "badge-success" : "badge-error" + }`} + > + {dispatcher?.length || 0} +
+
+ {aircrafts?.length || 0} +
+
+
+
+ {!dispatcher?.length && ( +

Aktuell sind keine Disponenten verbunden

+ )} +
    + {dispatcher?.map((d) => { + return ( +
  • +
    +
    +

    + {new Date(d.loginTime).toLocaleTimeString([], { + hour: "2-digit", + minute: "2-digit", + })} +

    +
    + {d.esimatedLogoutTime && ( +
    +

    + {new Date(d.esimatedLogoutTime).toLocaleTimeString([], { + hour: "2-digit", + minute: "2-digit", + })} +

    +
    + )} +
    +
    +
    {(d.publicUser as unknown as PublicUser)?.firstname}
    +
    {d.zone}
    +
    +
    + {(d.publicUser as unknown as PublicUser).badges + .filter((b) => b.startsWith("D")) + .map((b) => ( + + ))} +
    +
  • + ); + })} +
+
+
+
+
+ ); +}; diff --git a/apps/dispatch/app/pilot/page.tsx b/apps/dispatch/app/pilot/page.tsx index 20d8d35c..24b817e6 100644 --- a/apps/dispatch/app/pilot/page.tsx +++ b/apps/dispatch/app/pilot/page.tsx @@ -5,6 +5,7 @@ import { Chat } from "../_components/left/Chat"; import { Report } from "../_components/left/Report"; import { Dme } from "pilot/_components/dme/Dme"; import dynamic from "next/dynamic"; +import { ConnectedDispatcher } from "./_components/ConnectedDispatcher"; const Map = dynamic(() => import("../_components/map/Map"), { ssr: false, }); @@ -22,6 +23,7 @@ const DispatchPage = () => {
+
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index f3926b44..f7bacd60 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -57,9 +57,6 @@ importers: '@repo/typescript-config': specifier: workspace:* version: link:../../packages/typescript-config - '@types/cookie-parser': - specifier: ^1.4.8 - version: 1.4.8(@types/express@5.0.2) '@types/cors': specifier: ^2.8.18 version: 2.8.18