diff --git a/src/app/globals.css b/src/app/globals.css index 3420b22..e9cebb9 100644 --- a/src/app/globals.css +++ b/src/app/globals.css @@ -10,6 +10,12 @@ } } +@media (prefers-color-scheme: dark) { + html { + color-scheme: dark; + } +} + html { height: 100%; } @@ -46,54 +52,3 @@ a { width: 100%; height: 100%; } - -.charged-button { - position: relative; - display: inline-flex; - align-items: center; - justify-content: center; - padding: 0.5rem 1.25rem; - min-width: 8rem; - height: 2.75rem; - border: 2px solid white; - border-radius: 0.625rem; - outline: none; - isolation: isolate; - cursor: pointer; - background: #000; - color: #FFF; - box-shadow: 0 0 0 1px hsl(0 0% 0% / 0.15); - transition: box-shadow 120ms ease, transform 120ms ease; -} - -.charged-button:hover { - box-shadow: 0 0 0 1px hsl(0 0% 0% / 0.45); -} - -.charged-button:active { - transform: scale(0.97); -} - -.charged-button__label { - position: relative; - z-index: 1; - pointer-events: none; -} - -.charged-button-fill { - pointer-events: none; - position: absolute; - inset: 0; - border-radius: inherit; - opacity: 0.7; - background: linear-gradient(120deg, #1ea, #2af, #e1f, #2af); - background-size: 200% 200%; - transition: opacity 120ms ease; -} - -@media (prefers-color-scheme: dark) { - html { - color-scheme: dark; - } -} - diff --git a/src/app/page.tsx b/src/app/page.tsx index 4251503..441c250 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -1,19 +1,18 @@ "use client"; -import { useState } from "react"; +import { useEffect, useState } from "react"; import Image from "next/image"; import styles from "./page.module.css"; import ChargedButton from "@/components/ChargedButton"; import MapView from "@/components/MapView"; import WelcomeScreen from "@/components/screens/WelcomeScreen"; +import { useLocalStorage } from "@/hooks/useLocalStorage"; +import { PREF } from "@/utils/const"; export default function Main() { - const [doTest, setDoTest] = useState(false); - - return ( -
-
- { console.log("Click!"); }} @@ -22,7 +21,16 @@ export default function Main() { - {doTest && } + {doTest && }*/ + + console.log("STEP", step); + /*useEffect(() => { + setValue("1"); + }, []);*/ + + return ( +
+
diff --git a/src/app/sw.ts b/src/app/sw.ts index 7374545..5eef8d9 100644 --- a/src/app/sw.ts +++ b/src/app/sw.ts @@ -2,7 +2,7 @@ /// import { defaultCache } from "@serwist/turbopack/worker"; import type { PrecacheEntry, SerwistGlobalConfig } from "serwist"; -import { Serwist } from "serwist"; +import { Serwist, CacheFirst } from "serwist"; // This declares the value of `injectionPoint` to TypeScript. // `injectionPoint` is the string that will be replaced by the diff --git a/src/components/ChargedButton.tsx b/src/components/ChargedButton.tsx index ff2fb33..7263b22 100644 --- a/src/components/ChargedButton.tsx +++ b/src/components/ChargedButton.tsx @@ -1,28 +1,32 @@ "use client"; import { CSSProperties, ReactNode, useRef, useState } from "react"; +import styles from "@/css/ChargedButton.module.css"; interface ChargedButtonProps { children?: ReactNode; style?: CSSProperties; + className?: string; /** Time in milliseconds needed to fully charge by continuous hold. */ holdDuration?: number; /** Runs exactly once, when the button is fully charged at 100%. */ onAction?: () => void; + disabled?: boolean; } export default function ChargedButton({ children, style, + className, holdDuration = 1000, onAction, + disabled = false, }: ChargedButtonProps) { const [progress, setProgress] = useState(0); const [isCharging, setIsCharging] = useState(false); const [isDischarging, setIsDischarging] = useState(false); const rafRef = useRef(0); const startTimeRef = useRef(0); - const stateRef = useRef({ charging: false, discharging: false }); const dischargingRef = useRef(false); const cancelRaf = () => { @@ -33,7 +37,7 @@ export default function ChargedButton({ }; const onPointerDown = () => { - if (dischargingRef.current) return; + if (disabled || dischargingRef.current) return; cancelRaf(); startTimeRef.current = performance.now(); setIsCharging(true); @@ -43,7 +47,7 @@ export default function ChargedButton({ }; const onPointerUp = () => { - if (dischargingRef.current) return; + if (disabled || dischargingRef.current) return; cancelRaf(); setIsCharging(false); setProgress(0); @@ -65,7 +69,7 @@ export default function ChargedButton({ onAction?.(); } } else { - const fraction = Math.min(1, elapsed / (holdDuration * 0.1)); + const fraction = Math.min(1, elapsed / Math.max(holdDuration * 0.05, 150)); setProgress(1.0 - fraction); if (fraction >= 1) { setProgress(0); @@ -82,7 +86,7 @@ export default function ChargedButton({ return ( ); -} +} \ No newline at end of file diff --git a/src/components/PermissionModal.tsx b/src/components/PermissionModal.tsx index e69de29..a8e051a 100644 --- a/src/components/PermissionModal.tsx +++ b/src/components/PermissionModal.tsx @@ -0,0 +1,9 @@ + + +export default function PermissionModal() { + return ( +
+ +
+ ); +} \ No newline at end of file diff --git a/src/components/screens/WelcomeScreen.tsx b/src/components/screens/WelcomeScreen.tsx index 19794b5..cf207d2 100644 --- a/src/components/screens/WelcomeScreen.tsx +++ b/src/components/screens/WelcomeScreen.tsx @@ -1,10 +1,88 @@ +"use client"; + +import { ChangeEvent, SyntheticEvent, useEffect, useRef, useState } from "react"; import styles from "../../css/WelcomeScreen.module.css"; +import ChargedButton from "../ChargedButton"; + +const CODE_LENGTH = 9; +const COOLDOWN_MS = 3000; export default function WelcomeScreen() { - console.log(styles); - return( -
- -
- ) -} \ No newline at end of file + const [tourCode, setTourCode] = useState(""); + const [lastSubmitTs, setLastSubmitTs] = useState(0); + const [isCooldown, setIsCooldown] = useState(false); + const tourCodeRef = useRef(""); + const cooldownRef = useRef(-1); + + const checkCooldown = () => { + if (cooldownRef.current === -1) return false; + return Date.now() - cooldownRef.current <= COOLDOWN_MS + }; + + const isTourCodeValid = () => { + return tourCode.length === CODE_LENGTH; + }; + + useEffect(() => { + if (checkCooldown()) { + setIsCooldown(true); + const inputTimeout = setTimeout(() => { + console.log("Cooldown over"); + setIsCooldown(false); + }, 3000); + return () => clearTimeout(inputTimeout); + } else { + setIsCooldown(false); + } + }, [lastSubmitTs]); + + const submit = () => { + const value = tourCodeRef.current; + + if (!isTourCodeValid() && checkCooldown()) { + return; + } + + cooldownRef.current = Date.now(); + setLastSubmitTs(cooldownRef.current); + + console.log("submitted", value); + }; + + const handleChange = (event: ChangeEvent): boolean => { + const value = event.target.value; + + if (value.length > CODE_LENGTH) { + event.preventDefault(); + return false; + } + tourCodeRef.current = value; + setTourCode(value.toUpperCase().replaceAll(/\W/g, "")); + return true; + }; + + const buttonDisabled = isCooldown || !isTourCodeValid(); + + return ( +
+ + + {(!buttonDisabled) ? "Halten zum Spielen!" : "Halten zum Spielen."} + +
+ ); +} diff --git a/src/css/ChargedButton.module.css b/src/css/ChargedButton.module.css new file mode 100644 index 0000000..181008d --- /dev/null +++ b/src/css/ChargedButton.module.css @@ -0,0 +1,50 @@ +.charged-button { + position: relative; + display: inline-flex; + align-items: center; + justify-content: center; + padding: 0.5rem 1.25rem; + min-width: 8rem; + height: 2.75rem; + border: 2px solid white; + border-radius: 0.625rem; + overflow: hidden; + outline: none; + isolation: isolate; + cursor: pointer; + background: #000; + color: #FFF; + box-shadow: 0 0 0 1px hsl(0 0% 0% / 0.15); + transition: box-shadow 120ms ease, transform 120ms ease; + -webkit-tap-highlight-color: transparent; + user-select: none; + -webkit-user-select: none; + &.button-disabled { + color: lightslategray; + border-color: lightslategray; + } +} + +.charged-button:hover { + box-shadow: 0 0 0 1px hsl(0 0% 0% / 0.45); +} + +.charged-button:active { + transform: scale(0.97); +} + +.charged-button-label { + position: relative; + z-index: 1; + pointer-events: none; +} + +.charged-button-fill { + pointer-events: none; + position: absolute; + inset: 0; + border-radius: inherit; + opacity: 0.7; + background: linear-gradient(120deg, #1ea, #2af, #e1f); + transition: opacity 120ms ease; +} \ No newline at end of file diff --git a/src/css/PermissionModal.module.css b/src/css/PermissionModal.module.css new file mode 100644 index 0000000..e69de29 diff --git a/src/types/player.ts b/src/types/player.ts new file mode 100644 index 0000000..0cbf311 --- /dev/null +++ b/src/types/player.ts @@ -0,0 +1,7 @@ +export type Gender = 'male' | 'female' | 'other'; + +export interface Player { + id: number; + name: string; + gender: Gender; +} \ No newline at end of file diff --git a/src/utils/const.ts b/src/utils/const.ts new file mode 100644 index 0000000..dd7e22d --- /dev/null +++ b/src/utils/const.ts @@ -0,0 +1,7 @@ +export enum PREF { + code = "PREF_TOUR_CODE", + points = "PREF_POINTS", + players = "PREF_PLAYERS", + completed_riddles = "PREF_COMPLETED_RIDDLES", + step = "PREF_APP_SCREEN_STEP", +}; \ No newline at end of file diff --git a/src/utils/dataparser.ts b/src/utils/dataparser.ts new file mode 100644 index 0000000..dc3584f --- /dev/null +++ b/src/utils/dataparser.ts @@ -0,0 +1,9 @@ +import { Player } from "@/types/player"; + +export function parsePlayerData(raw: string): Array { + return []; +} + +export function formatPlayerData(arr: Array): string { + return ""; +} \ No newline at end of file