feat: add immersive big screen mode
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { useMemo, useState } from "react";
|
||||
import { useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";
|
||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
import {
|
||||
abortReconstitute, fetchHealth, fetchOrbits, fetchSnapshots, pollReconstitute,
|
||||
@@ -34,6 +34,9 @@ function priority(orbit: Orbit) {
|
||||
}
|
||||
|
||||
export default function App() {
|
||||
const app = useRef<HTMLDivElement>(null);
|
||||
const workspaceScroll = useRef<number>(undefined);
|
||||
const [bigScreen, setBigScreen] = useState(false);
|
||||
const [mode, setMode] = useState<HUDMode>("scene");
|
||||
const [orbitId, setOrbitId] = useState<string>();
|
||||
const [snapshotId, setSnapshotId] = useState<string | null>(null);
|
||||
@@ -44,6 +47,48 @@ export default function App() {
|
||||
const reducedMotion = useReducedMotion();
|
||||
const qc = useQueryClient();
|
||||
|
||||
useEffect(() => {
|
||||
const root = app.current;
|
||||
if (!root) return;
|
||||
const syncFullscreen = () => setBigScreen(document.fullscreenElement === root);
|
||||
root.addEventListener("fullscreenchange", syncFullscreen);
|
||||
return () => root.removeEventListener("fullscreenchange", syncFullscreen);
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
if (!bigScreen || mode !== "scene") return;
|
||||
const exitOnEscape = (event: KeyboardEvent) => {
|
||||
if (event.key === "Escape" && !event.defaultPrevented && !document.fullscreenElement) {
|
||||
setBigScreen(false);
|
||||
}
|
||||
};
|
||||
window.addEventListener("keydown", exitOnEscape);
|
||||
return () => window.removeEventListener("keydown", exitOnEscape);
|
||||
}, [bigScreen, mode]);
|
||||
|
||||
useLayoutEffect(() => {
|
||||
if (bigScreen || workspaceScroll.current === undefined) return;
|
||||
window.scrollTo(0, workspaceScroll.current);
|
||||
workspaceScroll.current = undefined;
|
||||
}, [bigScreen]);
|
||||
|
||||
function toggleBigScreen() {
|
||||
const root = app.current;
|
||||
if (bigScreen) {
|
||||
if (document.fullscreenElement === root) {
|
||||
void document.exitFullscreen().catch(() => {});
|
||||
} else {
|
||||
setBigScreen(false);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
workspaceScroll.current = window.scrollY;
|
||||
setBigScreen(true);
|
||||
// The viewport layout also works when the browser declines native fullscreen.
|
||||
if (document.fullscreenEnabled) void root?.requestFullscreen?.().catch(() => {});
|
||||
}
|
||||
|
||||
const health = useQuery({ queryKey: ["health"], queryFn: fetchHealth, refetchInterval: 15_000, retry: 1 });
|
||||
const snaps = useQuery({ queryKey: ["snapshots"], queryFn: fetchSnapshots, refetchInterval: 8_000, retry: 1 });
|
||||
const orbits = useQuery({ queryKey: ["orbits"], queryFn: fetchOrbits, refetchInterval: 8_000, retry: 1 });
|
||||
@@ -114,7 +159,7 @@ export default function App() {
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="vault-app">
|
||||
<div ref={app} className={`vault-app${bigScreen ? " big-screen" : ""}`}>
|
||||
<header className="vault-topbar">
|
||||
<div className="vault-brand">
|
||||
<svg viewBox="0 0 38 38" width="34" height="34" aria-hidden="true">
|
||||
@@ -145,6 +190,7 @@ export default function App() {
|
||||
<VaultScene
|
||||
orbits={sceneOrbits} selectedOrbitId={selected?.id} recentSnapshots={history.slice(0, 3)}
|
||||
flowing={play && !reducedMotion} reducedMotion={reducedMotion} arrival={arrival}
|
||||
bigScreen={bigScreen} onToggleBigScreen={toggleBigScreen}
|
||||
onToggleFlow={() => setPlay((value) => !value)}
|
||||
onSelectOrbit={(id) => {
|
||||
selectOrbit(id);
|
||||
|
||||
@@ -4,7 +4,7 @@ import type { Orbit, Snapshot } from "../../api";
|
||||
|
||||
export function VaultScene({
|
||||
orbits, selectedOrbitId, recentSnapshots, flowing, reducedMotion, arrival,
|
||||
onToggleFlow, onSelectOrbit, onSelectSnapshot,
|
||||
bigScreen, onToggleBigScreen, onToggleFlow, onSelectOrbit, onSelectSnapshot,
|
||||
}: {
|
||||
orbits: Orbit[];
|
||||
selectedOrbitId?: string;
|
||||
@@ -12,11 +12,14 @@ export function VaultScene({
|
||||
flowing: boolean;
|
||||
reducedMotion: boolean;
|
||||
arrival?: CaptureArrival;
|
||||
bigScreen: boolean;
|
||||
onToggleBigScreen: () => void;
|
||||
onToggleFlow: () => void;
|
||||
onSelectOrbit: (id: string) => void;
|
||||
onSelectSnapshot: (id: string) => void;
|
||||
}) {
|
||||
const selected = orbits.find(({ id }) => id === selectedOrbitId);
|
||||
const screenLabel = bigScreen ? "Exit big screen" : "Big screen";
|
||||
return (
|
||||
<section className="vault-scene" aria-label="Orbital map">
|
||||
<SpaceBackdrop />
|
||||
@@ -29,14 +32,31 @@ export function VaultScene({
|
||||
{!flowing && selected && <span className="scene-focus" title={selected.name}>· {selected.name}</span>}
|
||||
</p>
|
||||
</div>
|
||||
<button className="console-control" onClick={onToggleFlow} disabled={reducedMotion} type="button">
|
||||
<svg viewBox="0 0 16 16" width="15" height="15" aria-hidden="true">
|
||||
{flowing
|
||||
? <path d="M6 3v10M10 3v10" stroke="currentColor" strokeWidth="1.5" />
|
||||
: <path d="m6 3 7 5-7 5Z" fill="none" stroke="currentColor" strokeLinejoin="round" />}
|
||||
</svg>
|
||||
{reducedMotion ? "Reduced motion" : flowing ? "Pause motion" : "Resume motion"}
|
||||
</button>
|
||||
<div className="scene-controls">
|
||||
<button className="console-control" onClick={onToggleFlow} disabled={reducedMotion} type="button">
|
||||
<svg viewBox="0 0 16 16" width="15" height="15" aria-hidden="true">
|
||||
{flowing
|
||||
? <path d="M6 3v10M10 3v10" stroke="currentColor" strokeWidth="1.5" />
|
||||
: <path d="m6 3 7 5-7 5Z" fill="none" stroke="currentColor" strokeLinejoin="round" />}
|
||||
</svg>
|
||||
{reducedMotion ? "Reduced motion" : flowing ? "Pause motion" : "Resume motion"}
|
||||
</button>
|
||||
<button
|
||||
className="console-control scene-screen-control"
|
||||
onClick={onToggleBigScreen}
|
||||
aria-label={screenLabel}
|
||||
title={screenLabel}
|
||||
type="button"
|
||||
>
|
||||
<svg viewBox="0 0 16 16" width="15" height="15" aria-hidden="true" fill="none"
|
||||
stroke="currentColor" strokeWidth="1.25" strokeLinecap="round" strokeLinejoin="round">
|
||||
{bigScreen
|
||||
? <path d="M2 5h3V2m9 3h-3V2M2 11h3v3m9-3h-3v3" />
|
||||
: <path d="M5 2H2v3m9-3h3v3M5 14H2v-3m9 3h3v-3" />}
|
||||
</svg>
|
||||
<span>{screenLabel}</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<BlackholeGalaxy
|
||||
orbits={orbits}
|
||||
|
||||
@@ -187,6 +187,7 @@ button:disabled { cursor: default; }
|
||||
.scene-toolbar, .scene-footer { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 14px; }
|
||||
.scene-toolbar { z-index: 1; }
|
||||
.scene-toolbar > div { min-width: 0; }
|
||||
.scene-controls { display: flex; align-items: center; gap: 6px; }
|
||||
.scene-toolbar button { flex: none; }
|
||||
.scene-mode { display: flex; align-items: center; gap: 7px; margin-top: 3px; font-size: 13px; }
|
||||
.mode-signal { flex: none; width: 6px; height: 6px; background: var(--accent); transform: rotate(45deg); border-radius: 1px; }
|
||||
@@ -254,6 +255,74 @@ button:disabled { cursor: default; }
|
||||
.dialog-heading h2 + p { margin-top: 4px; color: var(--quiet); font-size: 13px; }
|
||||
.dialog-content { padding: 18px 20px; }
|
||||
|
||||
.big-screen {
|
||||
--screen-gutter: clamp(12px, 2vw, 30px);
|
||||
--screen-top: max(var(--screen-gutter), env(safe-area-inset-top));
|
||||
--screen-bottom: max(var(--screen-gutter), env(safe-area-inset-bottom));
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
overflow: hidden;
|
||||
background: #0a0c10;
|
||||
}
|
||||
|
||||
.big-screen .vault-topbar { display: contents; }
|
||||
.big-screen :is(.vault-brand, .hub-link, .vault-console, .vault-footer, .scene-footer) { display: none; }
|
||||
.big-screen .vault-main { padding: 0; }
|
||||
.big-screen .vault-workspace,
|
||||
.big-screen .vault-scene { position: absolute; inset: 0; display: grid; }
|
||||
.big-screen .vault-workspace { grid-template: 1fr / 1fr; height: auto; }
|
||||
.big-screen .vault-scene {
|
||||
grid-template-rows: minmax(0, 1fr);
|
||||
padding-block: 78px;
|
||||
border: 0;
|
||||
border-radius: 0;
|
||||
}
|
||||
.big-screen .galaxy-frame { max-width: calc((100dvh - 156px) * 1.375); }
|
||||
.big-screen .vault-scene > .scene-toolbar {
|
||||
position: absolute;
|
||||
inset: var(--screen-top) auto auto max(var(--screen-gutter), env(safe-area-inset-left));
|
||||
padding: 0;
|
||||
}
|
||||
.big-screen .scene-toolbar > div:first-child { max-width: 160px; margin-right: 8px; }
|
||||
.big-screen .scene-toolbar .instrument-label { display: none; }
|
||||
.big-screen .scene-mode { margin-top: 0; }
|
||||
.big-screen .vault-overview {
|
||||
position: absolute;
|
||||
z-index: 2;
|
||||
inset: var(--screen-top) max(var(--screen-gutter), env(safe-area-inset-right)) auto auto;
|
||||
margin: 0;
|
||||
}
|
||||
.big-screen .vault-overview > div:first-child {
|
||||
position: absolute;
|
||||
width: 1px;
|
||||
height: 1px;
|
||||
overflow: hidden;
|
||||
clip-path: inset(50%);
|
||||
white-space: nowrap;
|
||||
}
|
||||
.big-screen :is(.vault-nav, .vault-telemetry) {
|
||||
border: 1px solid #3a3d44;
|
||||
background: #111418d9;
|
||||
backdrop-filter: blur(14px);
|
||||
}
|
||||
.big-screen .vault-telemetry { border-radius: 8px; padding-block: 8px; }
|
||||
.big-screen .vault-nav {
|
||||
position: absolute;
|
||||
z-index: 2;
|
||||
bottom: var(--screen-bottom);
|
||||
left: 50%;
|
||||
transform: translateX(-50%);
|
||||
gap: 3px;
|
||||
max-width: calc(100% - 2 * var(--screen-gutter));
|
||||
margin: 0;
|
||||
padding: 4px;
|
||||
border-radius: 999px;
|
||||
box-shadow: 0 8px 30px #0006;
|
||||
}
|
||||
.big-screen .vault-nav button { border-radius: 999px; padding-inline: clamp(8px, 1.65vw, 23px); }
|
||||
.big-screen .vault-nav button[aria-current] { background: #30251f; color: #ffd0a9; }
|
||||
.big-screen .vault-nav button[aria-current]::after { display: none; }
|
||||
|
||||
@media (max-width: 1060px) {
|
||||
.vault-workspace { grid-template-areas: "map map" "register inspector"; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); height: auto; }
|
||||
.vault-console { min-height: 240px; max-height: 420px; }
|
||||
@@ -279,6 +348,32 @@ button:disabled { cursor: default; }
|
||||
.vault-footer > p:last-child { text-align: right; }
|
||||
}
|
||||
|
||||
@media (max-width: 740px) {
|
||||
.big-screen .vault-scene { padding-block: 120px 70px; }
|
||||
.big-screen .galaxy-frame { max-width: calc((100dvh - 190px) * 1.375); }
|
||||
.big-screen .vault-overview { top: calc(var(--screen-top) + 54px); }
|
||||
.big-screen .vault-telemetry { grid-template-columns: repeat(4, auto); }
|
||||
.big-screen .vault-telemetry dd { font-size: 14px; }
|
||||
.big-screen .scene-toolbar > div:first-child { display: none; }
|
||||
}
|
||||
|
||||
@media (max-height: 480px) and (orientation: landscape) and (min-width: 560px) {
|
||||
.big-screen .vault-scene { padding-block: 56px; }
|
||||
.big-screen .galaxy-frame { max-width: calc((100dvh - 112px) * 1.375); }
|
||||
.big-screen .vault-overview { top: var(--screen-top); }
|
||||
}
|
||||
|
||||
@media (max-width: 520px) {
|
||||
.vault-app:not(.big-screen) .scene-screen-control { min-width: 44px; justify-content: center; }
|
||||
.vault-app:not(.big-screen) .scene-screen-control span { display: none; }
|
||||
}
|
||||
|
||||
@media (max-width: 380px) {
|
||||
.big-screen .vault-nav { gap: 2px; }
|
||||
.big-screen .vault-nav button { padding-inline: 6px; }
|
||||
.big-screen .vault-telemetry > div { padding-inline: 7px; }
|
||||
}
|
||||
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
*, *::before, *::after {
|
||||
animation-duration: .01ms !important;
|
||||
|
||||
Reference in New Issue
Block a user