import { useMemo } from 'react'; import { Link, useParams } from 'react-router-dom'; import { buildTree, collectRefs } from '@tts/extract'; import { useModStore } from '../stores/modStore'; import { useSearchStore } from '../stores/searchStore'; import { modFileUrl } from '../api'; /** * Replaces the global site header on the mod page: thumbnail, game name, and * a subheader with the mod id and stats, plus download/setup links styled like * the Search/BGM nav. */ export default function ModHeader() { const { id } = useParams<{ id: string }>(); const { mod } = useModStore(); const item = useSearchStore((s) => s.items.find((i) => i.id === id)); const tree = useMemo(() => (mod ? buildTree(mod.mod) : []), [mod]); const refs = useMemo(() => (mod ? collectRefs(mod.mod) : []), [mod]); // Prefer the metadata fetched with the save (survives a refresh); fall back // to the search result for the brief moment before the save loads. const title = mod?.title ?? item?.title; const previewImageUrl = mod?.previewImageUrl ?? item?.previewImageUrl; return (
{id} · {mod.mod.GameMode} ·{' '} {mod.mod.Date} · {tree.length} objects · {refs.length} asset refs
)}