Files
stash/ui/v2.5/src/ConnectionMonitor.tsx
WithoutPants e5929389b4 Make migration an asynchronous task (#4666)
* Add failed state and error to Job
* Move migration code
* Add websocket monitor
* Make migrate a job managed task
2024-03-14 11:06:23 +11:00

35 lines
927 B
TypeScript

import { useEffect, useState } from "react";
import { getWSClient, useWSState } from "./core/StashService";
import { useToast } from "./hooks/Toast";
import { useIntl } from "react-intl";
export const ConnectionMonitor: React.FC = () => {
const Toast = useToast();
const intl = useIntl();
const { state } = useWSState(getWSClient());
const [cachedState, setCacheState] = useState<typeof state>(state);
useEffect(() => {
if (cachedState === "connecting" && state === "error") {
Toast.error(
intl.formatMessage({
id: "connection_monitor.websocket_connection_failed",
})
);
}
if (state === "connected" && cachedState === "error") {
Toast.success(
intl.formatMessage({
id: "connection_monitor.websocket_connection_reestablished",
})
);
}
setCacheState(state);
}, [state, cachedState, Toast, intl]);
return null;
};