diff --git a/src/app/globals.css b/src/app/globals.css index e041843..419c601 100644 --- a/src/app/globals.css +++ b/src/app/globals.css @@ -91,3 +91,10 @@ a { width: 100%; height: 100dvh; } + +.flex-center { + display: flex; + flex-direction: column; + align-items: center; + justify-content: center; +} \ No newline at end of file diff --git a/src/components/OldTextInput.tsx b/src/components/OldTextInput.tsx index cd5058c..f0c24dd 100644 --- a/src/components/OldTextInput.tsx +++ b/src/components/OldTextInput.tsx @@ -3,6 +3,7 @@ import { ChangeEventHandler, CSSProperties } from "react"; import styles from "@/css/OldTextInput.module.css"; interface OldTextInput { + type?: string; value?: string; onChange?: ChangeEventHandler; ariaLabel?: string; @@ -13,6 +14,7 @@ interface OldTextInput { }; export default function OldTextInput({ + type = "text", value, onChange, ariaLabel, @@ -22,16 +24,14 @@ export default function OldTextInput({ disabled = false, }: OldTextInput) { return ( - + ); } \ No newline at end of file diff --git a/src/components/screens/Intro.tsx b/src/components/screens/Intro.tsx index e5a8804..bc42da3 100644 --- a/src/components/screens/Intro.tsx +++ b/src/components/screens/Intro.tsx @@ -3,21 +3,33 @@ import { PREF } from "@/utils/const" import ChargedButton from "../ChargedButton"; import { usePermissions } from "@/hooks/usePermission"; import styles from "@/css/Intro.module.css"; -import { InputEvent, MouseEvent, MouseEventHandler, PointerEvent, useRef, useState } from "react"; +import { ChangeEvent, InputEvent, MouseEvent, MouseEventHandler, PointerEvent, useRef, useState } from "react"; import Image from "next/image"; import PermissionCheck from "../PermissionCheck"; import { PermissionStateResult } from "@/utils/permissions"; import StyledContainer from "../StyledContainer"; import OldButton from "../OldButton"; +import OldTextInput from "../OldTextInput"; + +const MIN_PLAYERS = 2; +const MAX_PLAYERS = 8; export default function Intro() { const [ stepStr, setStep ] = useLocalStorage(PREF.step, "0"); const [ rewatchScreen, setRewatchScreen ] = useState(false); + const [ enterPlayerCount, setEnterPlayerCount ] = useState(false); const [ videoEnded, setVideoEnded ] = useState(false); const [ videoPaused, setVideoPaused ] = useState(false); const introVideoRef = useRef(null); const [ granted, setGranted ] = useState(false); + const [ , setPlayerCount ] = useLocalStorage(PREF.playerCount, ""); + const [ playerCountStr, setPlayerCountStr] = useState(""); + + const validPlayerCount = (number: number) => { + return !isNaN(number) && (number <= MAX_PLAYERS && number >= MIN_PLAYERS); + }; + const handleVideoClick = (e: PointerEvent): boolean => { e.currentTarget.play(); return true; @@ -27,6 +39,22 @@ export default function Intro() { setGranted(gps === "granted" && cam === "granted"); }; + const handleChange = (event: ChangeEvent): boolean => { + const value = event.target.value; + let parsedValue = Number.parseInt(value); + + if (isNaN(parsedValue)) { + if (value.length > 0) { + event.preventDefault(); + return false; + } + } + parsedValue = Math.min(MAX_PLAYERS, Math.max(MIN_PLAYERS, parsedValue)); + + setPlayerCountStr(parsedValue.toString()); + return true; + }; + return (
Background - { !rewatchScreen ? + { !enterPlayerCount || !granted ?
- WEITER - { false && { + { + setRewatchScreen(false); + setEnterPlayerCount(true); + }} + style={{margin: "auto", marginTop: "3rem"}} + disabled={!granted} + >WEITER +
+ : !rewatchScreen ? +
+

Spieleranzahl

+

Wie viele Abenteurer seid ihr?

+ +

+ { + setPlayerCount(playerCountStr); setRewatchScreen(true); - }} holdDuration={500} disabled={!granted}> - Halten, um das Video ansehen - } + }} holdDuration={500} disabled={!validPlayerCount(Number.parseInt(playerCountStr))}> + Halten, um das Video anzusehen! +
:
diff --git a/src/components/screens/Tour.tsx b/src/components/screens/Tour.tsx index d8bedf4..66b10fa 100644 --- a/src/components/screens/Tour.tsx +++ b/src/components/screens/Tour.tsx @@ -69,6 +69,11 @@ export default function Tour() { }} holdDuration={500}> Zurücksetzen + { + + }} holdDuration={500}> + Test +
diff --git a/src/utils/const.ts b/src/utils/const.ts index dd7e22d..f44c79c 100644 --- a/src/utils/const.ts +++ b/src/utils/const.ts @@ -4,4 +4,5 @@ export enum PREF { players = "PREF_PLAYERS", completed_riddles = "PREF_COMPLETED_RIDDLES", step = "PREF_APP_SCREEN_STEP", + playerCount = "PREF_PLAYER_COUNT", }; \ No newline at end of file