Skip to content

Commit

Permalink
Merge pull request #33 from MertenD/23-pop-up-on-browser-window-reload
Browse files Browse the repository at this point in the history
feat: prevent 'beforeunload' event in editor
  • Loading branch information
MertenD committed Aug 6, 2023
2 parents b0e1eff + a502083 commit 0c9bdc7
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/app/editor/page.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
'use client'

import {ReactFlowProvider} from "reactflow";
import React from "react";
import {ReactFlowProvider, useReactFlow} from "reactflow";
import React, {useEffect} from "react";
import HeaderBar, {CANVAS_HEIGHT} from "@/components/editor/headerbar/HeaderBar";
import useEditorPageState from "@/stores/editor/EditorPageStore";
import {Alert, Snackbar} from "@mui/material";
import Engine from "@/components/editor/Engine";
import useReactFlowStore from "@/stores/editor/ReactFlowStore";

export default function Canvas() {

Expand All @@ -21,6 +22,17 @@ export default function Canvas() {
setIsSnackBarOpen(false)
}

useEffect(() => {
window.addEventListener('beforeunload', preventReload)
return () => {
window.removeEventListener('beforeunload', preventReload)
}
}, [])

const preventReload = (e: Event) => {
e.preventDefault()
}

return <div style={{ height: "100vh"}}>
<ReactFlowProvider>
<HeaderBar />
Expand Down

0 comments on commit 0c9bdc7

Please sign in to comment.