From 381a4fefd9818aad1ceffedc5ce24545b2b269dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tr=C3=A8sAbhi?= <43380238+tresabhi@users.noreply.github.com> Date: Fri, 3 May 2024 15:30:17 -0500 Subject: [PATCH] feat: exit fullscreen --- .../tankopedia/[id]/components/Control.tsx | 19 +++++++++++++++++-- .../[id]/components/Model/HeroSection.tsx | 9 +++++++-- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/app/tools/tankopedia/[id]/components/Control.tsx b/src/app/tools/tankopedia/[id]/components/Control.tsx index e530d2a12..96b5d91f4 100644 --- a/src/app/tools/tankopedia/[id]/components/Control.tsx +++ b/src/app/tools/tankopedia/[id]/components/Control.tsx @@ -1,6 +1,6 @@ import { OrbitControls } from '@react-three/drei'; import { useThree } from '@react-three/fiber'; -import { useEffect, useRef } from 'react'; +import { useEffect, useRef, useState } from 'react'; import { Vector3 } from 'three'; import { OrbitControls as OrbitControlsClass } from 'three-stdlib'; import { applyPitchYawLimits } from '../../../../../core/blitz/applyPitchYawLimits'; @@ -19,6 +19,7 @@ const poseDistances: Record = { export function Controls() { const camera = useThree((state) => state.camera); + const canvas = useThree((state) => state.gl.domElement); const orbitControls = useRef(null); const awaitedModelDefinitions = useAwait(modelDefinitions); const protagonist = useDuel((state) => state.protagonist!); @@ -53,7 +54,7 @@ export function Controls() { protagonistTrackModelDefinition.origin[1] + antagonistModelDefinition.turretOrigin[1] + antagonistTurretModelDefinition.gunOrigin[1]; - // const hasSetInitialPose = useRef(false); + const [autoRotate, setAutoRotate] = useState(true); useEffect(() => { camera.position.set(-4, 4, -16); @@ -162,6 +163,18 @@ export function Controls() { }; }, [camera, protagonist.tank.id, antagonist.tank.id]); + useEffect(() => { + function handleClick() { + setAutoRotate(false); + } + + canvas.addEventListener('click', handleClick); + + return () => { + canvas.removeEventListener('click', handleClick); + }; + }, []); + return ( ); } diff --git a/src/app/tools/tankopedia/[id]/components/Model/HeroSection.tsx b/src/app/tools/tankopedia/[id]/components/Model/HeroSection.tsx index 50f3ba234..ee854c87f 100644 --- a/src/app/tools/tankopedia/[id]/components/Model/HeroSection.tsx +++ b/src/app/tools/tankopedia/[id]/components/Model/HeroSection.tsx @@ -33,11 +33,12 @@ export function HeroSection() { - {tank.name} + {tank.name} Tier {TIER_ROMAN_NUMERALS[tank.tier]}{' '} {(strings.common.nations as Record)[tank.nation]}{' '} @@ -93,7 +94,11 @@ export function HeroSection() { right: 16, }} onClick={() => { - document.body.requestFullscreen(); + if (isFullScreen) { + document.exitFullscreen(); + } else { + document.body.requestFullscreen(); + } }} > {isFullScreen ? : }