Skip to content

Commit

Permalink
feat(Save/Restore ui): add warning before exit and reload
Browse files Browse the repository at this point in the history
  • Loading branch information
LorenzoValentine committed Sep 16, 2023
1 parent 71cc2d2 commit dcf7dfe
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/pages/index.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import ParBar from '../components/ParametersBar';
import ControlBar from '../components/ControlBar';
import { DiffusionPlane, type SimulationParams } from '../components/Simulation';
import {
DiffusionPlane,
type SimulationParams,
} from '../components/Simulation';
import { Canvas } from '@react-three/fiber';
import styled from 'styled-components';
import { useEffect } from 'react';

const SimulatorContainer = styled.div`
position: relative;
Expand Down Expand Up @@ -34,7 +38,17 @@ interface IndexProp {

export default function Home(props: IndexProp): React.ReactElement {
const { simulationParams, setSimulationParams, worker } = props;

useEffect(() => {
const confirmExit = (e: BeforeUnloadEvent) => {
console.log('beforeunload event triggered');
e.preventDefault();
e.returnValue = '';
};
window.addEventListener('beforeunload', confirmExit);
return () => {
window.removeEventListener('beforeunload', confirmExit);
};
}, []);
return (
<>
<ParBar params={simulationParams} setParams={setSimulationParams} />
Expand Down

0 comments on commit dcf7dfe

Please sign in to comment.