Added time update from Dispatcher
This commit is contained in:
@@ -15,8 +15,8 @@ const removeClosedMissions = async () => {
|
||||
|
||||
const now = new Date();
|
||||
if (!lastAlertTime) return;
|
||||
// change State to closed if last alert was more than 120 minutes ago
|
||||
if (lastAlertTime && now.getTime() - lastAlertTime.getTime() > 120 * 60 * 1000) {
|
||||
// change State to closed if last alert was more than 180 minutes ago
|
||||
if (lastAlertTime && now.getTime() - lastAlertTime.getTime() > 180 * 60 * 1000) {
|
||||
const log: MissionLog = {
|
||||
type: "completed-log",
|
||||
auto: true,
|
||||
|
||||
@@ -71,8 +71,8 @@ export const handleConnectDispatch =
|
||||
socket.join(`user:${user.id}`); // Dem User-Raum beitreten
|
||||
|
||||
io.to(`user:${user.id}`).emit("dispatchers-update", connectedDispatcherEntry);
|
||||
io.to("dispatchers").emit("dispatchers-update");
|
||||
io.to("pilots").emit("dispatchers-update");
|
||||
io.to("dispatchers").emit("dispatchers-update", connectedDispatcherEntry);
|
||||
io.to("pilots").emit("dispatchers-update", connectedDispatcherEntry);
|
||||
|
||||
socket.on("stop-other-transmition", async ({ ownRole, otherRole }) => {
|
||||
const aircrafts = await prisma.connectedAircraft.findMany({
|
||||
|
||||
@@ -65,6 +65,7 @@ dispatchSocket.on("force-disconnect", (reason: string) => {
|
||||
});
|
||||
});
|
||||
dispatchSocket.on("dispatchers-update", (dispatch: ConnectedDispatcher) => {
|
||||
console.log("dispatchers-update", dispatch);
|
||||
useDispatchConnectionStore.setState({
|
||||
connectedDispatcher: dispatch,
|
||||
});
|
||||
|
||||
@@ -23,12 +23,30 @@ export const ConnectionBtn = () => {
|
||||
const uid = session.data?.user?.id;
|
||||
if (!uid) return null;
|
||||
|
||||
// useEffect für die Logoff-Zeit
|
||||
useEffect(() => {
|
||||
// Disconnect the socket when the component unmounts
|
||||
if (logoffDebounce) clearTimeout(logoffDebounce);
|
||||
|
||||
const timeout = setTimeout(async () => {
|
||||
if (!form.logoffTime || !connection.connectedDispatcher) return;
|
||||
await changeDispatcherMutation.mutateAsync({
|
||||
id: connection.connectedDispatcher?.id,
|
||||
data: {
|
||||
esimatedLogoutTime: new Date(
|
||||
new Date().toDateString() + " " + form.logoffTime,
|
||||
).toISOString(),
|
||||
},
|
||||
});
|
||||
toast.success("Änderung gespeichert!");
|
||||
}, 2000);
|
||||
|
||||
setLogoffDebounce(timeout);
|
||||
|
||||
// Cleanup function
|
||||
return () => {
|
||||
connection.disconnect();
|
||||
if (logoffDebounce) clearTimeout(logoffDebounce);
|
||||
};
|
||||
}, [connection.disconnect]);
|
||||
}, [form.logoffTime, connection.connectedDispatcher]);
|
||||
|
||||
return (
|
||||
<div className="rounded-box bg-base-200 flex justify-center items-center gap-2 p-1">
|
||||
@@ -79,18 +97,6 @@ export const ConnectionBtn = () => {
|
||||
...form,
|
||||
logoffTime: value,
|
||||
});
|
||||
if (logoffDebounce) clearTimeout(logoffDebounce);
|
||||
const timeout = setTimeout(async () => {
|
||||
if (!connection.connectedDispatcher) return;
|
||||
await changeDispatcherMutation.mutateAsync({
|
||||
id: connection.connectedDispatcher?.id,
|
||||
data: {
|
||||
esimatedLogoutTime: value,
|
||||
},
|
||||
});
|
||||
toast.success("Änderung gespeichert!");
|
||||
}, 2000);
|
||||
setLogoffDebounce(timeout);
|
||||
}}
|
||||
value={form.logoffTime}
|
||||
type="time"
|
||||
|
||||
@@ -50,6 +50,34 @@ export const ConnectionBtn = () => {
|
||||
};
|
||||
}, [connection.disconnect]);
|
||||
|
||||
const logoffTime = form.logoffTime;
|
||||
|
||||
useEffect(() => {
|
||||
if (!logoffTime || !connection.connectedAircraft) return;
|
||||
|
||||
if (logoffDebounce) clearTimeout(logoffDebounce);
|
||||
|
||||
const timeout = setTimeout(async () => {
|
||||
if (!connection.connectedAircraft?.id) return;
|
||||
await aircraftMutation.mutateAsync({
|
||||
sessionId: connection.connectedAircraft.id,
|
||||
change: {
|
||||
esimatedLogoutTime: logoffTime
|
||||
? new Date(new Date().toDateString() + " " + logoffTime).toISOString()
|
||||
: null,
|
||||
},
|
||||
});
|
||||
toast.success("Änderung gespeichert!");
|
||||
}, 2000);
|
||||
|
||||
setLogoffDebounce(timeout);
|
||||
|
||||
// Cleanup function to clear timeout
|
||||
return () => {
|
||||
if (logoffDebounce) clearTimeout(logoffDebounce);
|
||||
};
|
||||
}, [logoffTime, connection.connectedAircraft]);
|
||||
|
||||
const session = useSession();
|
||||
const uid = session.data?.user?.id;
|
||||
if (!uid) return null;
|
||||
@@ -126,20 +154,6 @@ export const ConnectionBtn = () => {
|
||||
...form,
|
||||
logoffTime: value,
|
||||
});
|
||||
if (logoffDebounce) clearTimeout(logoffDebounce);
|
||||
const timeout = setTimeout(async () => {
|
||||
if (!connection.connectedAircraft) return;
|
||||
await aircraftMutation.mutateAsync({
|
||||
sessionId: connection.connectedAircraft.id,
|
||||
change: {
|
||||
esimatedLogoutTime: value
|
||||
? new Date(new Date().toDateString() + " " + value).toISOString()
|
||||
: null,
|
||||
},
|
||||
});
|
||||
toast.success("Änderung gespeichert!");
|
||||
}, 2000);
|
||||
setLogoffDebounce(timeout);
|
||||
}}
|
||||
value={form.logoffTime ?? ""}
|
||||
type="time"
|
||||
|
||||
Reference in New Issue
Block a user