diff --git a/README.md b/README.md index 68bfbf8..b967cbe 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ Open http://localhost:3000. ## Routes - `/` - search for a handle, DID, or `at://` URI -- `/?mode=artist` - the same search, stripped to the player it finds +- `/?faaah` - the same search, stripped to the player it finds - `/player/[actor]` - one player: avatar, name, badges, nothing technical - `/at/[actor]` - repo overview - `/at/[actor]/[collection]` - records in a collection diff --git a/src/app/page.tsx b/src/app/page.tsx index dcea7d7..0b3e34b 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -12,7 +12,7 @@ import { Wordmark } from "@/components/wordmark"; import { actorId, normalizeActor, parseAtUri } from "@/lib/atproto/uri"; import { getFolkLexicons, getFolkRepos, summarize } from "@/lib/folk"; import { hrefForAtUri, playerHref, repoHref } from "@/lib/links"; -import { parseMode } from "@/lib/mode"; +import { ARTIST_PARAM, parseMode } from "@/lib/mode"; import { listPlayers } from "@/lib/player"; import { SITE_DESCRIPTION, @@ -24,7 +24,7 @@ import { import styles from "./page.module.css"; export const metadata: Metadata = { - // `?invalid=` is a rendering detail of the search form and `?mode=` is a + // `?invalid=` is a rendering detail of the search form and `?faaah` is a // choice of view, never a distinct page. alternates: { canonical: "/" }, openGraph: { @@ -62,12 +62,13 @@ async function findPlayer(formData: FormData) { const actor = normalizeActor(input); if (actor) redirect(playerHref(actorId(actor))); - redirect(`/?mode=artist&invalid=${encodeURIComponent(input)}`); + redirect(`/?${ARTIST_PARAM}&invalid=${encodeURIComponent(input)}`); } export default async function Home({ searchParams }: PageProps<"/">) { - const { invalid, mode: modeParam } = await searchParams; - const mode = parseMode(modeParam); + const params = await searchParams; + const { invalid } = params; + const mode = parseMode(params); const header = (
diff --git a/src/components/mode-switch.tsx b/src/components/mode-switch.tsx index b859a4b..6655422 100644 --- a/src/components/mode-switch.tsx +++ b/src/components/mode-switch.tsx @@ -1,6 +1,6 @@ import Image from "next/image"; import Link from "next/link"; -import type { Mode } from "@/lib/mode"; +import { homeHref, type Mode } from "@/lib/mode"; import styles from "./mode-switch.module.css"; const ICON = 22; @@ -21,7 +21,7 @@ const OPTIONS = [ export function ModeSwitch({ mode, nerdHref = "/", - artistHref = "/?mode=artist", + artistHref = homeHref("artist"), }: { mode: Mode; nerdHref?: string; diff --git a/src/lib/mode.ts b/src/lib/mode.ts index 1cdc41a..4fc9ef4 100644 --- a/src/lib/mode.ts +++ b/src/lib/mode.ts @@ -3,10 +3,15 @@ export type Mode = "nerd" | "artist"; export const DEFAULT_MODE: Mode = "nerd"; -export function parseMode(value: string | string[] | undefined): Mode { - return value === "artist" ? "artist" : DEFAULT_MODE; +/** Valueless flag, so the artist view is just `/?faaah`. */ +export const ARTIST_PARAM = "faaah"; + +export function parseMode( + params: Record, +): Mode { + return ARTIST_PARAM in params ? "artist" : DEFAULT_MODE; } export function homeHref(mode: Mode): string { - return mode === "artist" ? "/?mode=artist" : "/"; + return mode === "artist" ? `/?${ARTIST_PARAM}` : "/"; }