mirror of
https://github.com/makeplane/plane
synced 2024-06-14 14:31:34 +00:00
4f2b106852
* fix: undo/redo, placeholder overlapping with text, horizontal cursor refractor: removed a lot of state-management that was not required * fix: forwarding ref to remirror for getting extra helper functions * fix: icon type error * fix: value type not supported error on page block * style: spacing, and UX for add link --------- Co-authored-by: Aaryan Khandelwal <aaryankhandu123@gmail.com>
29 lines
781 B
TypeScript
29 lines
781 B
TypeScript
import { useCallback, useEffect, useState } from "react";
|
|
|
|
const useReloadConfirmations = (message?: string) => {
|
|
const [showAlert, setShowAlert] = useState(false);
|
|
|
|
const handleBeforeUnload = useCallback(
|
|
(event: BeforeUnloadEvent) => {
|
|
event.preventDefault();
|
|
event.returnValue = "";
|
|
return message ?? "Are you sure you want to leave?";
|
|
},
|
|
[message]
|
|
);
|
|
|
|
useEffect(() => {
|
|
if (!showAlert) {
|
|
window.removeEventListener("beforeunload", handleBeforeUnload);
|
|
return;
|
|
}
|
|
|
|
window.addEventListener("beforeunload", handleBeforeUnload);
|
|
return () => window.removeEventListener("beforeunload", handleBeforeUnload);
|
|
}, [handleBeforeUnload, showAlert]);
|
|
|
|
return { setShowAlert };
|
|
};
|
|
|
|
export default useReloadConfirmations;
|