From a4a1b148e9c93da72bccb77ef23d31ad7d1eb985 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Sat, 18 Feb 2023 04:12:46 +0100 Subject: [PATCH] veri important updat --- hooks/useKonamiCode.ts | 46 ++++++++++++++++++++++++++++++++++++++++++ pages/garasauto.tsx | 20 ++++++++++++++++++ pages/index.tsx | 6 ++++++ 3 files changed, 72 insertions(+) create mode 100644 hooks/useKonamiCode.ts create mode 100644 pages/garasauto.tsx diff --git a/hooks/useKonamiCode.ts b/hooks/useKonamiCode.ts new file mode 100644 index 0000000..75b59ec --- /dev/null +++ b/hooks/useKonamiCode.ts @@ -0,0 +1,46 @@ +import {useCallback, useEffect, useState} from "react" + + +const KONAMI_CODE = ["ArrowUp", "ArrowUp", "ArrowDown", "ArrowDown", "ArrowLeft", "ArrowRight", "ArrowLeft", "ArrowRight", "KeyB", "KeyA"] + + +export function useKonamiCode(onDone: () => void) { + const [remainingKeys, setRemainingKeys] = useState(() => [...KONAMI_CODE]) + const nextKey = remainingKeys?.[0]; + + const checkInput = useCallback( + (event: KeyboardEvent) => { + if(event.code === nextKey) { + setRemainingKeys(rem => { + rem = [...rem] + rem.shift() + return rem + }) + } + else { + setRemainingKeys([...KONAMI_CODE]) + } + }, + [nextKey] + ) + + useEffect( + () => { + if(!nextKey) { + onDone() + setRemainingKeys([...KONAMI_CODE]) + } + }, + [nextKey, onDone] + ) + + useEffect( + () => { + document.addEventListener("keydown", checkInput) + return () => { + document.removeEventListener("keydown", checkInput) + } + }, + [checkInput] + ) +} \ No newline at end of file diff --git a/pages/garasauto.tsx b/pages/garasauto.tsx new file mode 100644 index 0000000..63077ee --- /dev/null +++ b/pages/garasauto.tsx @@ -0,0 +1,20 @@ +import {NextPage} from "next" +import React from "react" +import {LinkPanel} from "../components/LinkPanel" +import {faCar} from "@fortawesome/free-solid-svg-icons" + + +const Garasauto: NextPage = () => { + return <> +
+
+

+ Silly stuff +

+ +
+
+ +} + +export default Garasauto \ No newline at end of file diff --git a/pages/index.tsx b/pages/index.tsx index 7a043da..a4197cc 100644 --- a/pages/index.tsx +++ b/pages/index.tsx @@ -1,13 +1,19 @@ import {FontAwesomeIcon} from "@fortawesome/react-fontawesome" +import {useRouter} from "next/router" import React from 'react' import type {NextPage} from "next" import {default as Link} from "next/link" import {faRedditAlien, faMastodon, faGithub, faDiscord, faTelegram, faSteam, faItchIo, faTwitter, faLinkedin, faStackOverflow} from "@fortawesome/free-brands-svg-icons" import {faBorderAll, faEnvelope, faGlobe, faPlus, faFileCode, faBagShopping} from "@fortawesome/free-solid-svg-icons" import {LinkPanel} from "../components/LinkPanel" +import {useKonamiCode} from "../hooks/useKonamiCode" const Index: NextPage = () => { + const router = useRouter() + + useKonamiCode(() => router.push("/garasauto")) + return <>