add status 9, statusToast bugfix
This commit is contained in:
@@ -49,7 +49,6 @@ export function QueryProvider({ children }: { children: ReactNode }) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const invalidateConenctedAircrafts = () => {
|
const invalidateConenctedAircrafts = () => {
|
||||||
console.log("invalidateConenctedAircrafts");
|
|
||||||
queryClient.invalidateQueries({
|
queryClient.invalidateQueries({
|
||||||
queryKey: ["aircrafts"],
|
queryKey: ["aircrafts"],
|
||||||
});
|
});
|
||||||
@@ -61,7 +60,6 @@ export function QueryProvider({ children }: { children: ReactNode }) {
|
|||||||
const handleNotification = (notification: NotificationPayload) => {
|
const handleNotification = (notification: NotificationPayload) => {
|
||||||
switch (notification.type) {
|
switch (notification.type) {
|
||||||
case "hpg-validation":
|
case "hpg-validation":
|
||||||
console.log("hpg-validation notification received", notification);
|
|
||||||
toast.custom(
|
toast.custom(
|
||||||
(t) => <HPGnotificationToast event={notification} mapStore={mapStore} t={t} />,
|
(t) => <HPGnotificationToast event={notification} mapStore={mapStore} t={t} />,
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -5,8 +5,9 @@ import { FMS_STATUS_COLORS } from "_helpers/fmsStatusColors";
|
|||||||
import { editConnectedAircraftAPI, getConnectedAircraftsAPI } from "_querys/aircrafts";
|
import { editConnectedAircraftAPI, getConnectedAircraftsAPI } from "_querys/aircrafts";
|
||||||
import { getStationsAPI } from "_querys/stations";
|
import { getStationsAPI } from "_querys/stations";
|
||||||
import { useMapStore } from "_store/mapStore";
|
import { useMapStore } from "_store/mapStore";
|
||||||
|
import { cpSync } from "fs";
|
||||||
import { X } from "lucide-react";
|
import { X } from "lucide-react";
|
||||||
import { useEffect, useRef } from "react";
|
import { useEffect, useRef, useState } from "react";
|
||||||
import { Toast, toast } from "react-hot-toast";
|
import { Toast, toast } from "react-hot-toast";
|
||||||
|
|
||||||
export const QUICK_RESPONSE: Record<string, string[]> = {
|
export const QUICK_RESPONSE: Record<string, string[]> = {
|
||||||
@@ -18,26 +19,32 @@ export const QUICK_RESPONSE: Record<string, string[]> = {
|
|||||||
export const StatusToast = ({ event, t }: { event: StationStatus; t: Toast }) => {
|
export const StatusToast = ({ event, t }: { event: StationStatus; t: Toast }) => {
|
||||||
const status0Sounds = useRef<HTMLAudioElement | null>(null);
|
const status0Sounds = useRef<HTMLAudioElement | null>(null);
|
||||||
const status5Sounds = useRef<HTMLAudioElement | null>(null);
|
const status5Sounds = useRef<HTMLAudioElement | null>(null);
|
||||||
|
const status9Sounds = useRef<HTMLAudioElement | null>(null);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (typeof window !== "undefined") {
|
if (typeof window !== "undefined") {
|
||||||
status0Sounds.current = new Audio("/sounds/status-0.mp3");
|
status0Sounds.current = new Audio("/sounds/status-0.mp3");
|
||||||
status5Sounds.current = new Audio("/sounds/status-5.mp3");
|
status5Sounds.current = new Audio("/sounds/status-5.mp3");
|
||||||
|
status9Sounds.current = new Audio("/sounds/status-9.mp3");
|
||||||
}
|
}
|
||||||
}, []);
|
}, []);
|
||||||
|
const [aircraftDataAcurate, setAircraftDataAccurate] = useState(false);
|
||||||
const mapStore = useMapStore((s) => s);
|
const mapStore = useMapStore((s) => s);
|
||||||
|
|
||||||
const { data: connectedAircrafts } = useQuery({
|
const { data: connectedAircrafts } = useQuery({
|
||||||
queryKey: ["aircrafts"],
|
queryKey: ["aircrafts"],
|
||||||
queryFn: () => getConnectedAircraftsAPI(),
|
queryFn: () => getConnectedAircraftsAPI(),
|
||||||
refetchInterval: 10000,
|
refetchInterval: 10000,
|
||||||
|
initialData: [],
|
||||||
});
|
});
|
||||||
const { data: stations } = useQuery({
|
const { data: stations } = useQuery({
|
||||||
queryKey: ["stations"],
|
queryKey: ["stations"],
|
||||||
queryFn: () => getStationsAPI(),
|
queryFn: () => getStationsAPI(),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const connectedAircraft = connectedAircrafts?.find((a) => a.id === event.data?.aircraftId);
|
||||||
|
const station = stations?.find((s) => s.id === event.data?.stationId);
|
||||||
|
|
||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
const changeAircraftMutation = useMutation({
|
const changeAircraftMutation = useMutation({
|
||||||
mutationFn: async ({
|
mutationFn: async ({
|
||||||
@@ -54,20 +61,41 @@ export const StatusToast = ({ event, t }: { event: StationStatus; t: Toast }) =>
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const connectedAircraft = connectedAircrafts?.find((a) => a.id === event.data?.aircraftId);
|
useEffect(() => {
|
||||||
const station = stations?.find((s) => s.id === event.data?.stationId);
|
if (event.status !== connectedAircraft?.fmsStatus && aircraftDataAcurate) {
|
||||||
|
toast.remove(t.id);
|
||||||
|
} else if (event.status == connectedAircraft?.fmsStatus && !aircraftDataAcurate) {
|
||||||
|
setAircraftDataAccurate(true);
|
||||||
|
}
|
||||||
|
}, [connectedAircraft, station]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (connectedAircraft?.fmsStatus === "0" && status0Sounds.current) {
|
let soundRef: React.RefObject<HTMLAudioElement | null> | null = null;
|
||||||
status0Sounds.current.currentTime = 0;
|
switch (event.status) {
|
||||||
status0Sounds.current.volume = 0.7;
|
case "0":
|
||||||
status0Sounds.current.play();
|
soundRef = status0Sounds;
|
||||||
} else if (connectedAircraft?.fmsStatus === "5" && status5Sounds.current) {
|
break;
|
||||||
status5Sounds.current.currentTime = 0;
|
case "5":
|
||||||
status5Sounds.current.volume = 0.7;
|
soundRef = status5Sounds;
|
||||||
status5Sounds.current.play();
|
break;
|
||||||
|
case "9":
|
||||||
|
soundRef = status9Sounds;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
soundRef = null;
|
||||||
}
|
}
|
||||||
}, [connectedAircraft?.fmsStatus]);
|
if (soundRef?.current) {
|
||||||
|
soundRef.current.currentTime = 0;
|
||||||
|
soundRef.current.volume = 0.7;
|
||||||
|
soundRef.current.play().catch(() => {});
|
||||||
|
}
|
||||||
|
return () => {
|
||||||
|
if (soundRef?.current) {
|
||||||
|
soundRef.current.pause();
|
||||||
|
soundRef.current.currentTime = 0;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}, [event.status]);
|
||||||
|
|
||||||
if (!connectedAircraft || !station) return null;
|
if (!connectedAircraft || !station) return null;
|
||||||
return (
|
return (
|
||||||
@@ -90,10 +118,10 @@ export const StatusToast = ({ event, t }: { event: StationStatus; t: Toast }) =>
|
|||||||
>
|
>
|
||||||
{station.bosCallsign}
|
{station.bosCallsign}
|
||||||
</span>
|
</span>
|
||||||
sendet Status {connectedAircraft.fmsStatus}
|
sendet Status {event.status}
|
||||||
</p>
|
</p>
|
||||||
<div className="flex gap-2 items-center">
|
<div className="flex gap-2 items-center">
|
||||||
{QUICK_RESPONSE[String(connectedAircraft.fmsStatus)]?.map((status) => (
|
{QUICK_RESPONSE[String(event.status)]?.map((status) => (
|
||||||
<button
|
<button
|
||||||
key={status}
|
key={status}
|
||||||
className={
|
className={
|
||||||
@@ -104,8 +132,13 @@ export const StatusToast = ({ event, t }: { event: StationStatus; t: Toast }) =>
|
|||||||
color: "white",
|
color: "white",
|
||||||
}}
|
}}
|
||||||
onClick={async () => {
|
onClick={async () => {
|
||||||
|
if (!event.data?.aircraftId) {
|
||||||
|
toast.remove(t.id);
|
||||||
|
toast.error("Keine Flugzeug-ID gefunden");
|
||||||
|
return;
|
||||||
|
}
|
||||||
await changeAircraftMutation.mutateAsync({
|
await changeAircraftMutation.mutateAsync({
|
||||||
id: connectedAircraft.id,
|
id: event.data?.aircraftId,
|
||||||
update: {
|
update: {
|
||||||
fmsStatus: status,
|
fmsStatus: status,
|
||||||
},
|
},
|
||||||
|
|||||||
BIN
apps/dispatch/public/sounds/status-9.mp3
Normal file
BIN
apps/dispatch/public/sounds/status-9.mp3
Normal file
Binary file not shown.
@@ -31,7 +31,7 @@ export interface AdminMessage {
|
|||||||
|
|
||||||
export interface StationStatus {
|
export interface StationStatus {
|
||||||
type: "station-status";
|
type: "station-status";
|
||||||
status: "5";
|
status: string;
|
||||||
message: string;
|
message: string;
|
||||||
data?: {
|
data?: {
|
||||||
stationId: number;
|
stationId: number;
|
||||||
|
|||||||
Reference in New Issue
Block a user