security.txt + bugfixes

This commit is contained in:
2023-03-05 15:30:06 +01:00
parent 5acd13b945
commit c8965e209b
32 changed files with 336 additions and 46 deletions

View 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 });
}, []);
}

View 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 ?? {})
)
}
};
}