From 0e0fb8168f6da91dd25340c98454b9632395e40e Mon Sep 17 00:00:00 2001 From: Black Ram <67595890+BlackRam-oss@users.noreply.github.com> Date: Mon, 22 Jul 2024 11:48:28 +0200 Subject: [PATCH] improve skip --- src/screens/NextButton.tsx | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/screens/NextButton.tsx b/src/screens/NextButton.tsx index 3826e61..8665472 100644 --- a/src/screens/NextButton.tsx +++ b/src/screens/NextButton.tsx @@ -1,4 +1,3 @@ -import { GameStepManager } from '@drincs/pixi-vn'; import { StepLabelProps } from '@drincs/pixi-vn/dist/override'; import { Button } from '@mui/joy'; import { motion } from "framer-motion"; @@ -21,26 +20,29 @@ export default function NextButton({ nextOnClick }: { const navigate = useMyNavigate(); const { t } = useTranslation(["translation"]); useEffect(() => { - window.addEventListener('keydown', onkeydown); + window.addEventListener("keypress", onkeypress); + window.addEventListener("keyup", onkeyup); return () => { - window.removeEventListener('keydown', onkeydown); + window.removeEventListener("keypress", onkeypress); + window.removeEventListener("keyup", onkeyup); }; }, []); - function onkeydown(event: KeyboardEvent) { - if (event.code == 'Enter' || event.code == 'Space') { - if (!GameStepManager.canGoNext) { - return; - } + function onkeypress(event: KeyboardEvent) { + if ((event.code == 'Enter' || event.code == 'Space')) { + setSkip(true) + } + } + + function onkeyup(event: KeyboardEvent) { + if ((event.code == 'Enter' || event.code == 'Space')) { + setSkip(false) nextOnClick({ t, navigate, notify: (message, variant) => enqueueSnackbar(message, { variant }), }) - if (skip) { - setSkip(false) - } } }