Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add beforeunload handler and update textarea disabled state #28

Merged
merged 1 commit into from
Jan 14, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading