Skip to content
Extraits de code Groupes Projets
Valider 0b98b0fd rédigé par Maverick Chardet's avatar Maverick Chardet
Parcourir les fichiers

Added warning when closing tab if dirty

parent c5c011fd
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -32,6 +32,7 @@ import {
} from "./features/activityData/activityDataSlice";
import { initialState as layoutInitialState } from "./features/layout/layoutSlice";
import ExitWarning from "./features/activityData/ExitWarning";
type AntiCheatOptions = {
preserveDom: boolean;
......@@ -81,6 +82,7 @@ const MetaPlayer: FC<MetaPlayerProps> = (props) => {
<PrimeReactProvider value={primeSettings}>
<Provider store={store}>
<ThemeSwitcher />
<ExitWarning />
<ErrorBoundary fallback={<div>Une erreur est survenue</div>}>
<ActivityJSProvider options={props.activityJSOptions}>
<Saver />
......
import { FC, useEffect } from "react";
import { useAppSelector } from "../../app/hooks";
import { selectIsDirty } from "./activityDataSlice";
const ExitWarning: FC = () => {
const isDirty = useAppSelector(selectIsDirty);
useEffect(() => {
const handleBeforeUnload = (e: BeforeUnloadEvent) => {
if (isDirty) {
e.preventDefault();
e.returnValue = true;
}
};
window.addEventListener("beforeunload", handleBeforeUnload);
return () => {
window.removeEventListener("beforeunload", handleBeforeUnload);
};
}, [isDirty]);
return null;
};
export default ExitWarning;
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter