diff --git a/web/e2e/navigation.e2e.ts b/web/e2e/navigation.e2e.ts index de5a413..362d495 100644 --- a/web/e2e/navigation.e2e.ts +++ b/web/e2e/navigation.e2e.ts @@ -7,8 +7,8 @@ test("following a link doesn't reload the page", async ({ page }) => { (window as { stillHere?: boolean }).stillHere = true; }); await page - .getByRole("main") - .getByRole("link", { name: "Browse maps" }) + .getByRole("banner") + .getByRole("link", { name: "Maps", exact: true }) .click(); await expect(page).toHaveURL(/\/maps$/); await expect(page.getByRole("heading", { level: 1 })).toHaveText("Maps"); diff --git a/web/src/features/home/HomeHeader.tsx b/web/src/features/home/HomeHeader.tsx index 6aefef4..7fc85a0 100644 --- a/web/src/features/home/HomeHeader.tsx +++ b/web/src/features/home/HomeHeader.tsx @@ -1,77 +1,88 @@ -// The home page's header: the site's picture with its name over it, and the way in. -import Image from "next/image"; -import type { CSSProperties } from "react"; -import { ButtonLink } from "@/ui/Button"; -import { HeaderDepth } from "./HeaderDepth"; -import header from "./header.png"; -import headerDepth from "./header-depth.webp"; +import { ArrowUpRight } from "lucide-react"; +import { Dot } from "@/ui/Dot"; +import { formatDate } from "@/features/runs/time"; +import { latestUpload, youtubeChannel } from "./latestUpload"; +import { UploadPlayer } from "./UploadPlayer"; -// Wider than a phone, the picture is shown at its own size, centered and cropped: shrinking it to fit averages -// away its fine grain, which is what makes it look sharp. Centered by position rather than a transform, which -// the browser snaps to whole pixels; a half-pixel offset would blur the picture again. -const nativeSize = - "sm:absolute sm:top-(--top) sm:left-(--left) sm:h-(--height) sm:w-(--width) sm:max-w-none"; -const nativePlacement = { - "--width": `${header.width}px`, - "--height": `${header.height}px`, - "--left": `calc(50% - ${header.width / 2}px)`, - "--top": `calc(50% - ${header.height / 2}px)`, -} as CSSProperties; +const views = new Intl.NumberFormat("en", { + notation: "compact", + maximumFractionDigits: 1, +}); + +export async function HomeHeader() { + const upload = await latestUpload().catch(() => null); + const hasRun = upload?.map && upload.player && upload.time; -/** A static import, so Next.js knows the size, serves modern formats at the screen's width, and blurs in. */ -export function HomeHeader() { return ( -
- {/* On a phone the text takes the lower half, so the picture fills only the top two thirds and fades out - there: the jumper then sits between the top edge and the text instead of behind it. The settle zoom is - on this box so the depth canvas moves with the picture. */} -
- -
+ {upload ? ( +
+ +
+
+

+ {hasRun ? upload.title.split(/\s+in\s+\d/)[0] : upload.title} +

+ {hasRun && ( +

+ + {upload.time} + + + by {upload.player} + +

+ )} +
+
+

+ {upload.views !== undefined && ( + <> + {views.format(upload.views)} views + + + )} + +

+
+
+
+ ) : ( +

+ The latest upload couldn't be loaded. You can still watch it on + the channel. +

+ )} + ); } - -function delay(ms: number): CSSProperties { - return { "--motion-delay": `${ms}ms` } as CSSProperties; -} diff --git a/web/src/features/home/UploadPlayer.tsx b/web/src/features/home/UploadPlayer.tsx new file mode 100644 index 0000000..a8bb4c3 --- /dev/null +++ b/web/src/features/home/UploadPlayer.tsx @@ -0,0 +1,53 @@ +"use client"; + +import { Play } from "lucide-react"; +import { useState } from "react"; + +export function UploadPlayer({ + id, + title, + thumbnail, +}: { + id: string; + title: string; + thumbnail: string; +}) { + const [playing, setPlaying] = useState(false); + + return ( +
+ {playing ? ( +