Skip to content

Commit

Permalink
Merge pull request #28 from RedDuck-Software/feat/onunload
Browse files Browse the repository at this point in the history
feat: add beforeunload handler and update textarea disabled state
  • Loading branch information
NikiTaysRD authored Jan 14, 2025
2 parents ccba7c2 + 1f785c2 commit 3cb1efe
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions src/components/pages/game/game.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<div className="container flex flex-col gap-[20px] py-[20px] font-inknut">
<div className="text-center font-bona-nova-sc text-[30px] sm:text-[50px]">Your Future In One Forecast</div>
Expand Down Expand Up @@ -174,13 +190,13 @@ export const GameSection = () => {
</BaseTooltip>
</div>

<div className="grid">
<div className="grid overflow-hidden">
<div className="text-red-700"> {errors.question?.message ? errors.question.message : '⠀'} </div>
<textarea
{...register('question')}
className="min-h-[150px] rounded-[8px] border border-[#3A3939] bg-transparent p-4 placeholder-[#3A3939] outline-none"
placeholder="Type your question here"
disabled={isPending}
disabled={isPending || showTip}
rows={7}
/>
</div>
Expand All @@ -198,7 +214,10 @@ export const GameSection = () => {
onClick={
isRetry
? () => {
window.location.reload();
toast.info('To make a new forecast, please reload the page');
setTimeout(() => {
window.location.reload();
}, 10);
}
: handleSubmit(onSubmit)
}
Expand Down

0 comments on commit 3cb1efe

Please sign in to comment.