From 1f785c20a0e5d519694a8f7652843bc0f4488a08 Mon Sep 17 00:00:00 2001 From: Yarre Date: Tue, 14 Jan 2025 11:47:17 +0100 Subject: [PATCH] feat: add beforeunload handler and update textarea disabled state --- src/components/pages/game/game.tsx | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/src/components/pages/game/game.tsx b/src/components/pages/game/game.tsx index ae9b7e5..e2e7765 100644 --- a/src/components/pages/game/game.tsx +++ b/src/components/pages/game/game.tsx @@ -132,6 +132,22 @@ export const GameSection = () => { }; }, [isPending, currentPendingImage]); + useEffect(() => { + if (!showTip) { + return; + } + + const handler = (event: BeforeUnloadEvent) => { + event.preventDefault(); + }; + + window.addEventListener('beforeunload', handler); + + return () => { + window.removeEventListener('beforeunload', handler); + }; + }, [showTip]); + return (
Your Future In One Forecast
@@ -174,13 +190,13 @@ export const GameSection = () => {
-
+
{errors.question?.message ? errors.question.message : '⠀'}