From d9387f464f811bda8307a84317c57e9a3b59283e Mon Sep 17 00:00:00 2001 From: LionTion Date: Fri, 11 Sep 2026 15:40:24 +0200 Subject: [PATCH] intro, map, layout, permissions --- public/{ => icons}/icon-192x192.png | Bin public/{ => icons}/icon-512x512.png | Bin public/icons/pause.svg | 1 + public/res/{ => intro}/testvid.webm | Bin src/app/globals.css | 2 +- src/app/manifest.ts | 12 ++--- src/app/page.module.css | 75 ++-------------------------- src/app/page.tsx | 4 +- src/components/MapView.tsx | 20 ++++---- src/components/PermissionCheck.tsx | 48 ++++++++++++++++++ src/components/PermissionModal.tsx | 9 ---- src/components/screens/Intro.tsx | 45 ++++++++--------- src/components/screens/Tour.tsx | 62 ++++++++++++++++++++--- src/css/Intro.module.css | 16 ++++++ src/css/MapView.module.css | 8 +++ src/css/Tour.module.css | 33 +++++++++++- 16 files changed, 204 insertions(+), 131 deletions(-) rename public/{ => icons}/icon-192x192.png (100%) rename public/{ => icons}/icon-512x512.png (100%) create mode 100644 public/icons/pause.svg rename public/res/{ => intro}/testvid.webm (100%) create mode 100644 src/components/PermissionCheck.tsx delete mode 100644 src/components/PermissionModal.tsx diff --git a/public/icon-192x192.png b/public/icons/icon-192x192.png similarity index 100% rename from public/icon-192x192.png rename to public/icons/icon-192x192.png diff --git a/public/icon-512x512.png b/public/icons/icon-512x512.png similarity index 100% rename from public/icon-512x512.png rename to public/icons/icon-512x512.png diff --git a/public/icons/pause.svg b/public/icons/pause.svg new file mode 100644 index 0000000..59231a6 --- /dev/null +++ b/public/icons/pause.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/public/res/testvid.webm b/public/res/intro/testvid.webm similarity index 100% rename from public/res/testvid.webm rename to public/res/intro/testvid.webm diff --git a/src/app/globals.css b/src/app/globals.css index e9cebb9..61eb324 100644 --- a/src/app/globals.css +++ b/src/app/globals.css @@ -50,5 +50,5 @@ a { .screen-container { width: 100%; - height: 100%; + height: 100dvh; } diff --git a/src/app/manifest.ts b/src/app/manifest.ts index 20a8e86..921b0c1 100644 --- a/src/app/manifest.ts +++ b/src/app/manifest.ts @@ -7,19 +7,19 @@ export default function manifest(): MetadataRoute.Manifest { name: 'Next.js PWA', short_name: 'NextPWA', description: 'A Progressive Web App built with Next.js', - start_url: '/', - display: 'standalone', + //start_url: '/', Disables the default website install popup + display: 'fullscreen', orientation: "portrait-primary", - background_color: '#ffffff', - theme_color: '#000000', + background_color: '#000000', + theme_color: '#ffffff', icons: [ { - src: '/icon-192x192.png', + src: '/icons/icon-192x192.png', sizes: '192x192', type: 'image/png', }, { - src: '/icon-512x512.png', + src: '/icons/icon-512x512.png', sizes: '512x512', type: 'image/png', }, diff --git a/src/app/page.module.css b/src/app/page.module.css index 90fe305..a286f78 100644 --- a/src/app/page.module.css +++ b/src/app/page.module.css @@ -16,6 +16,10 @@ justify-content: center; font-family: var(--font-geist-sans); background-color: var(--background); + + &.pad { + padding: 48px 24px; + } } .main { @@ -27,61 +31,6 @@ align-items: flex-start; justify-content: space-between; background-color: var(--foreground); - padding: 120px 60px; -} - -.intro { - display: flex; - flex-direction: column; - align-items: flex-start; - text-align: left; - gap: 24px; -} - -.intro h1 { - max-width: 320px; - font-size: 40px; - font-weight: 600; - line-height: 48px; - letter-spacing: -2.4px; - text-wrap: balance; - color: var(--text-primary); -} - -.intro p { - max-width: 440px; - font-size: 18px; - line-height: 32px; - text-wrap: balance; - color: var(--text-secondary); -} - -.intro a { - font-weight: 500; - color: var(--text-primary); -} - -.ctas { - display: flex; - flex-direction: row; - width: 100%; - max-width: 440px; - gap: 16px; - font-size: 14px; -} - -.ctas a { - display: flex; - justify-content: center; - align-items: center; - height: 40px; - padding: 0 16px; - border-radius: 128px; - border: 1px solid transparent; - transition: 0.2s; - cursor: pointer; - width: fit-content; - font-weight: 500; } a.primary { @@ -107,22 +56,6 @@ a.secondary { } } -@media (max-width: 600px) { - .main { - padding: 48px 24px; - } - - .intro { - gap: 16px; - } - - .intro h1 { - font-size: 32px; - line-height: 40px; - letter-spacing: -1.92px; - } -} - @media (prefers-color-scheme: dark) { .logo { filter: invert(); diff --git a/src/app/page.tsx b/src/app/page.tsx index 4d2b39d..d0550f9 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -82,8 +82,10 @@ export default function Main() { () ]; + console.log(styles); + return ( -
+
{content[step]}
diff --git a/src/components/MapView.tsx b/src/components/MapView.tsx index 2236626..7584a4a 100644 --- a/src/components/MapView.tsx +++ b/src/components/MapView.tsx @@ -3,7 +3,7 @@ import React, { useEffect, useRef, useState, useCallback } from 'react'; import * as maplibregl from 'maplibre-gl'; import 'maplibre-gl/dist/maplibre-gl.css'; -import styles from '../css/MapView.module.css'; +import styles from '@/css/MapView.module.css'; export interface PlaceMarker { id: string; @@ -11,7 +11,6 @@ export interface PlaceMarker { lng: number; title: string; description?: string; - category?: string; } export interface MapViewProps { @@ -48,16 +47,15 @@ export default function MapView({ const mapContainerRef = useRef(null); const mapRef = useRef(null); const activeMarkersRef = useRef>(new Map()); + const [ mapReady, setMapReady ] = useState(false); const [isCaching, setIsCaching] = useState(false); const [cacheProgress, setCacheProgress] = useState<{ loaded: number; total: number } | null>(null); - // 1. Initialize Map instance useEffect(() => { if (!mapContainerRef.current) return; if (mapRef.current) return; - // Standard OpenStreetMap raster style (can be swapped for MapTiler / custom PBF vector style) const mapStyle: maplibregl.StyleSpecification = { version: 8, sources: { @@ -101,6 +99,7 @@ export default function MapView({ map.addControl(new maplibregl.ScaleControl({ unit: 'metric' }), 'bottom-left'); map.on('load', async () => { + setMapReady(true); navigator.geolocation.getCurrentPosition((pos) => { map.setCenter([pos.coords.longitude, pos.coords.latitude]); geolocate.trigger(); @@ -114,18 +113,19 @@ export default function MapView({ return () => { map.remove(); mapRef.current = null; + setMapReady(false); }; }, [/*initialCenter, initialZoom, tileUrlTemplate Create your own listeners*/]); - // 2. Manage Markers Sync useEffect(() => { const map = mapRef.current; - if (!map) return; + if (!map || !mapReady) return; const currentMarkers = activeMarkersRef.current; const incomingMarkerIds = new Set(markers.map((m) => m.id)); - // Remove obsolete markers + console.log(incomingMarkerIds); + currentMarkers.forEach((markerInstance, id) => { if (!incomingMarkerIds.has(id)) { markerInstance.remove(); @@ -133,10 +133,9 @@ export default function MapView({ } }); - // Add / Update markers markers.forEach((markerData) => { if (!currentMarkers.has(markerData.id)) { - const popup = new maplibregl.Popup({ offset: 25 }).setHTML( + const popup = new maplibregl.Popup({ offset: 25, className: styles["marker"] }).setHTML( `${markerData.title}${ markerData.description ? `

${markerData.description}

` : '' }` @@ -154,9 +153,8 @@ export default function MapView({ currentMarkers.set(markerData.id, newMarker); } }); - }, [markers, onMarkerClick]); + }, [mapReady, markers, onMarkerClick]); - // 3. Region Precaching Logic for Offline Woods Usage const precacheCurrentRegion = useCallback(async () => { const map = mapRef.current; if (!map) return; diff --git a/src/components/PermissionCheck.tsx b/src/components/PermissionCheck.tsx new file mode 100644 index 0000000..33dd739 --- /dev/null +++ b/src/components/PermissionCheck.tsx @@ -0,0 +1,48 @@ +"use client"; + +import { usePermissions } from "@/hooks/usePermission"; +import { PermissionStateResult } from "@/utils/permissions"; +import { useEffect } from "react"; + +export interface PermissionCheckProps { + onRefresh?: (gps: PermissionStateResult, camera: PermissionStateResult) => void; +} + +export default function PermissionCheck({ + onRefresh +}: PermissionCheckProps) { + const { gpsStatus, cameraStatus, refresh } = usePermissions(); + + useEffect(() => { + if (onRefresh) { + onRefresh(gpsStatus, cameraStatus); + } + }, [onRefresh, gpsStatus, cameraStatus]); + + const requestGPSPermission = () => { + navigator.geolocation.getCurrentPosition(() => refresh, () => refresh); + } + + const requestCamPermission = () => { + navigator.mediaDevices.getUserMedia({ + "video": { facingMode: { ideal: "environment" } }, + "audio": false, + }).then((stream) => { + refresh(); + stream.getTracks().forEach(track => track.stop()); + alert("Keine Sorge! Die Kamera ist wieder ausgeschalten. Der Gerät zeigt Ihnen nur, dass darauf kurz zugegriffen wurde."); + }).catch((e) => refresh); + } + + return ( +
+

Für diese Tour werden extra Berechtigungen gebraucht.

+

Kamera: {cameraStatus}

+

GPS: {gpsStatus}

+

+ + + +
+ ) +} \ No newline at end of file diff --git a/src/components/PermissionModal.tsx b/src/components/PermissionModal.tsx deleted file mode 100644 index a8e051a..0000000 --- a/src/components/PermissionModal.tsx +++ /dev/null @@ -1,9 +0,0 @@ - - -export default function PermissionModal() { - return ( -
- -
- ); -} \ No newline at end of file diff --git a/src/components/screens/Intro.tsx b/src/components/screens/Intro.tsx index 74ec743..aeb6829 100644 --- a/src/components/screens/Intro.tsx +++ b/src/components/screens/Intro.tsx @@ -4,50 +4,38 @@ 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 Image from "next/image"; +import PermissionCheck from "../PermissionCheck"; +import { PermissionStateResult } from "@/utils/permissions"; export default function Intro() { const [ stepStr, setStep ] = useLocalStorage(PREF.step, "0"); - const { gpsStatus, cameraStatus, refresh } = usePermissions(); const [ rewatchScreen, setRewatchScreen ] = useState(false); const [ videoEnded, setVideoEnded ] = useState(false); + const [ videoPaused, setVideoPaused ] = useState(false); const introVideoRef = useRef(null); - - const requestGPSPermission = () => { - navigator.geolocation.getCurrentPosition(() => refresh, () => refresh); - } - const requestCamPermission = () => { - navigator.mediaDevices.getUserMedia({ - "video": { facingMode: { ideal: "environment" } }, - "audio": false, - }).then((stream) => { - refresh(); - stream.getTracks().forEach(track => track.stop()); - alert("Keine Sorge! Die Kamera ist wieder ausgeschalten. Der Gerät zeigt Ihnen nur, dass darauf kurz zugegriffen wurde."); - }).catch((e) => refresh); - } + const [ granted, setGranted ] = useState(false); const handleVideoClick = (e: PointerEvent): boolean => { e.currentTarget.play(); return true; }; + const handlePermissions = (gps: PermissionStateResult, cam: PermissionStateResult) => { + setGranted(gps === "granted" && cam === "granted"); + }; + return (
{ !rewatchScreen ?

CODE EINGELÖST

TON AN

-

Für diese Tour werden extra Berechtigungen gebraucht.

-

Kamera: {cameraStatus}

-

GPS: {gpsStatus}

-

- - - +

{ setRewatchScreen(true); - }} holdDuration={500} disabled={gpsStatus !== "granted" || cameraStatus !== "granted"}> + }} holdDuration={500} disabled={!granted}> Video ansehen
@@ -66,14 +54,23 @@ export default function Intro() { onEnded={() => setVideoEnded(true)} onAbort={() => setVideoEnded(true)} onError={() => setVideoEnded(true)} + onPause={() => setVideoPaused(true)} + onPlay={() => setVideoPaused(false)} onClick={handleVideoClick} onContextMenu={(e) => { e.preventDefault(); return false; }} > - + + { !videoEnded && videoPaused ? +
+ Pause Icon +
+ : + null + } { videoEnded ?
{ if (introVideoRef.current) { diff --git a/src/components/screens/Tour.tsx b/src/components/screens/Tour.tsx index b598ad0..d8bedf4 100644 --- a/src/components/screens/Tour.tsx +++ b/src/components/screens/Tour.tsx @@ -1,9 +1,14 @@ +"use client"; + import { useLocalStorage } from "@/hooks/useLocalStorage" import { PREF } from "@/utils/const" import { parsePlayerData } from "@/utils/dataparser"; import ChargedButton from "../ChargedButton"; import styles from "@/css/Tour.module.css"; -import MapView from "../MapView"; +import MapView, { PlaceMarker } from "../MapView"; +import { useEffect, useState } from "react"; +import { usePermissions } from "@/hooks/usePermission"; +import PermissionCheck from "../PermissionCheck"; export default function Tour() { const [ stepStr, setStep ] = useLocalStorage(PREF.step, "0"); @@ -11,13 +16,46 @@ export default function Tour() { const [ completedRiddlesStr, setCompletedRiddles ] = useLocalStorage(PREF.completed_riddles, ""); const [ playersStr, setPlayers ] = useLocalStorage(PREF.players, ""); const [ pointsStr, setPoints ] = useLocalStorage(PREF.points, "0"); + const [ markers, setMarkers ] = useState([]); + const { gpsStatus, cameraStatus } = usePermissions(); const step = Number.parseInt(stepStr) || 0; const points = Number.parseInt(pointsStr) || 0; const players = parsePlayerData(playersStr); + const permissionsGranted = gpsStatus === "granted" && cameraStatus === "granted"; + + const [ test, setTest ] = useState(false); + + useEffect(() => { + let timerId: string | number | NodeJS.Timeout | undefined; + + const requestPosition = () => { + timerId = setTimeout(() => { + navigator.geolocation.getCurrentPosition( + (position) => { + setMarkers([{ + id: "riddle_one", + title: "Erstes Rätsel", + description: "Test Punkt verschoben vom Standort", + lng: position.coords.longitude + 0.002, + lat: position.coords.latitude, + }]); + }, + (error) => { + requestPosition(); + } + ); + }, 500); + }; + + requestPosition(); + + return () => clearTimeout(timerId); +}, []); + return ( -
-
+
+

{"Ruf: " + points}

{"Players: " + playersStr}



@@ -34,11 +72,23 @@ export default function Tour() {
- + { + if (marker.id === "riddle_one") { + setTest(true); + } + }}>
-
- Riddle Overlay +
setTest(false)}> +

Riddle Overlay

+

Idealer weise dann mit Popup Animation (Slide In oder Fade In)

+

Klicken um zu schließen

+ { !permissionsGranted ? +
+ +
+ : null + }
) diff --git a/src/css/Intro.module.css b/src/css/Intro.module.css index b9697d2..adde40d 100644 --- a/src/css/Intro.module.css +++ b/src/css/Intro.module.css @@ -34,4 +34,20 @@ height: 100%; background-color: rgba(0, 0, 0, 0.75); animation: fadeIn 0.5s ease-out 0s 1 normal forwards; +} + +.pause-screen { + position: absolute; + top: 0; + left: 0; + display: flex; + flex-direction: column; + row-gap: 3rem; + align-items: center; + justify-content: center; + width: 100%; + height: 100%; + background-color: rgba(0, 0, 0, 0.25); + animation: fadeIn 200ms ease-out 0s 1 normal forwards; + pointer-events: none; } \ No newline at end of file diff --git a/src/css/MapView.module.css b/src/css/MapView.module.css index 090500a..6d33963 100644 --- a/src/css/MapView.module.css +++ b/src/css/MapView.module.css @@ -70,4 +70,12 @@ height: 100%; background: #10b981; transition: width 0.2s ease; +} + +.marker { + color: black; + + button { + color: black; + } } \ No newline at end of file diff --git a/src/css/Tour.module.css b/src/css/Tour.module.css index 53130e4..25386cc 100644 --- a/src/css/Tour.module.css +++ b/src/css/Tour.module.css @@ -1,7 +1,22 @@ -.main-content { - position: relative; +.screen-container { display: flex; flex-direction: column; + height: 100dvh; + width: 100%; + overflow: hidden; +} + +.top-bar { + padding: 8px; + flex-shrink: 0; +} + +.main-content { + position: relative; + flex: 1; + display: flex; + flex-direction: column; + min-height: 0; } .map { @@ -13,6 +28,20 @@ position: absolute; top: 0; left: 0; + width: 100%; + /*height: 100%; TODO: fullsize when doing this*/ padding: 1rem; background-color: #000000AA; + z-index: 10; +} + +.permissions-overlay { + position: absolute; + top: 0; + left: 0; + width: 100%; + height: 100%; + padding: 1rem; + background-color: #000000AA; + z-index: 10; } \ No newline at end of file