security.txt + bugfixes
This commit is contained in:
16
react/shared/hooks/before-unload.js
Normal file
16
react/shared/hooks/before-unload.js
Normal file
@@ -0,0 +1,16 @@
|
||||
import {useCallback, useEffect} from "react";
|
||||
|
||||
export default function useBeforeUnload(modified) {
|
||||
|
||||
const capture = useCallback((event) => {
|
||||
if (modified) {
|
||||
event.preventDefault();
|
||||
}
|
||||
}, [modified]);
|
||||
|
||||
useEffect(() => {
|
||||
window.addEventListener("beforeunload", capture, {capture: true});
|
||||
return () => window.removeEventListener("beforeunload", capture, { capture: true });
|
||||
}, []);
|
||||
|
||||
}
|
||||
21
react/shared/hooks/editor-navigate.js
Normal file
21
react/shared/hooks/editor-navigate.js
Normal file
@@ -0,0 +1,21 @@
|
||||
import {useNavigate} from "react-router-dom";
|
||||
|
||||
export default function useEditorNavigate(L, showDialog) {
|
||||
|
||||
const navigate = useNavigate();
|
||||
|
||||
return (uri, modified, options = null) => {
|
||||
|
||||
if (!modified) {
|
||||
navigate(uri, options ?? {});
|
||||
} else {
|
||||
showDialog(
|
||||
"You still have unsaved changes, are you really sure you want to leave this view?",
|
||||
"Unsaved changes",
|
||||
[L("general.cancel"), L("general.leave")],
|
||||
(buttonIndex) => buttonIndex === 1 && navigate(uri, options ?? {})
|
||||
)
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user