Dispo-Option, die HPG validierung nicht zu nutzen
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
|
||||
import { toast } from "react-hot-toast";
|
||||
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
||||
import { ReactNode, useEffect, useState } from "react";
|
||||
import { ReactNode, useEffect, useRef, useState } from "react";
|
||||
import { dispatchSocket } from "(app)/dispatch/socket";
|
||||
import { NotificationPayload } from "@repo/db";
|
||||
import { HPGnotificationToast } from "_components/customToasts/HPGnotification";
|
||||
@@ -15,6 +15,7 @@ import { MissionAutoCloseToast } from "_components/customToasts/MissionAutoClose
|
||||
|
||||
export function QueryProvider({ children }: { children: ReactNode }) {
|
||||
const mapStore = useMapStore((s) => s);
|
||||
const notificationSound = useRef<HTMLAudioElement | null>(null);
|
||||
|
||||
const [queryClient] = useState(
|
||||
() =>
|
||||
@@ -30,6 +31,9 @@ export function QueryProvider({ children }: { children: ReactNode }) {
|
||||
},
|
||||
}),
|
||||
);
|
||||
useEffect(() => {
|
||||
notificationSound.current = new Audio("/sounds/notification.mp3");
|
||||
}, []);
|
||||
useEffect(() => {
|
||||
const invalidateMission = () => {
|
||||
queryClient.invalidateQueries({
|
||||
@@ -59,8 +63,18 @@ export function QueryProvider({ children }: { children: ReactNode }) {
|
||||
};
|
||||
|
||||
const handleNotification = (notification: NotificationPayload) => {
|
||||
const playNotificationSound = () => {
|
||||
if (notificationSound.current) {
|
||||
notificationSound.current.currentTime = 0;
|
||||
notificationSound.current
|
||||
.play()
|
||||
.catch((e) => console.error("Notification sound error:", e));
|
||||
}
|
||||
}
|
||||
|
||||
switch (notification.type) {
|
||||
case "hpg-validation":
|
||||
playNotificationSound();
|
||||
toast.custom(
|
||||
(t) => <HPGnotificationToast event={notification} mapStore={mapStore} t={t} />,
|
||||
{
|
||||
@@ -70,6 +84,7 @@ export function QueryProvider({ children }: { children: ReactNode }) {
|
||||
|
||||
break;
|
||||
case "admin-message":
|
||||
playNotificationSound();
|
||||
toast.custom((t) => <AdminMessageToast event={notification} t={t} />, {
|
||||
duration: 999999,
|
||||
});
|
||||
@@ -81,6 +96,7 @@ export function QueryProvider({ children }: { children: ReactNode }) {
|
||||
});
|
||||
break;
|
||||
case "mission-auto-close":
|
||||
playNotificationSound();
|
||||
toast.custom(
|
||||
(t) => <MissionAutoCloseToast event={notification} t={t} mapStore={mapStore} />,
|
||||
{
|
||||
@@ -90,6 +106,7 @@ export function QueryProvider({ children }: { children: ReactNode }) {
|
||||
break;
|
||||
case "mission-closed":
|
||||
toast("Dein aktueller Einsatz wurde geschlossen.");
|
||||
|
||||
break;
|
||||
default:
|
||||
toast("unbekanntes Notification-Event");
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
import { BaseNotification } from "_components/customToasts/BaseNotification"
|
||||
import { TriangleAlert } from "lucide-react"
|
||||
import toast, { Toast } from "react-hot-toast"
|
||||
|
||||
|
||||
export const HPGnotValidatedToast = ({_toast}: {_toast: Toast}) => {
|
||||
return <BaseNotification icon={<TriangleAlert />} className="flex flex-row">
|
||||
<div className="flex-1">
|
||||
<h1 className="font-bold text-red-600">Einsatz nicht HPG-validiert</h1>
|
||||
<p className="text-sm">Vergleiche die Position des Einsatzes mit der HPG-Position in Hubschrauber</p>
|
||||
</div>
|
||||
<div className="ml-11">
|
||||
<button className="btn" onClick={() => toast.dismiss(_toast.id)}>
|
||||
schließen
|
||||
</button>
|
||||
</div>
|
||||
</BaseNotification>
|
||||
}
|
||||
|
||||
export const showToast = () => {
|
||||
toast.custom((t) => {
|
||||
return (<HPGnotValidatedToast _toast={t} />);
|
||||
}, {duration: 1000 * 60 * 10}); // 10 minutes
|
||||
}
|
||||
Reference in New Issue
Block a user