From 265313919c0dddfb19dc6deda4293920a4163d3a Mon Sep 17 00:00:00 2001 From: Elijah Mock <28277163+ekcom@users.noreply.github.com> Date: Sat, 6 Jan 2024 21:51:35 +0000 Subject: [PATCH] Vue-ify and add documentation --- .../composables/use-navigation-warning.ts | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/frontend/composables/use-navigation-warning.ts b/frontend/composables/use-navigation-warning.ts index f07d842ae..2dff77d39 100644 --- a/frontend/composables/use-navigation-warning.ts +++ b/frontend/composables/use-navigation-warning.ts @@ -1,7 +1,22 @@ -export const activateNavigationWarning = () => { +export function useNavigationWarning() { + return { activateNavigationWarning, deactivateNavigationWarning }; +} + +/** + * Displays a warning before the user navigates to another page + * e.g., by clicking a link (which isn't internal and rendered without page load), + * reloading the page, + * or closing the tab. + */ +const activateNavigationWarning = () => { + console.log("ACTIVATE"); window.onbeforeunload = () => true; } -export const deactivateNavigationWarning = () => { +/** + * Disables the warning when navigating to a page + */ +const deactivateNavigationWarning = () => { + console.log("deACTIVATE"); window.onbeforeunload = null; }