diff --git a/index.html b/index.html index 6bd6be9..07ab6d8 100644 --- a/index.html +++ b/index.html @@ -4,7 +4,7 @@ - Vite + Preact + TS + atp.tools
diff --git a/src/hooks/useDocumentTitle.tsx b/src/hooks/useDocumentTitle.tsx new file mode 100644 index 0000000..2c0c171 --- /dev/null +++ b/src/hooks/useDocumentTitle.tsx @@ -0,0 +1,7 @@ +import { useEffect } from "react"; + +export function useDocumentTitle(title: string) { + useEffect(() => { + document.title = title; + }, [title]); +} diff --git a/src/routes/at:/$handle.$collection.$rkey.lazy.tsx b/src/routes/at:/$handle.$collection.$rkey.lazy.tsx index efd0384..ffa6e83 100644 --- a/src/routes/at:/$handle.$collection.$rkey.lazy.tsx +++ b/src/routes/at:/$handle.$collection.$rkey.lazy.tsx @@ -1,4 +1,5 @@ import { RenderJson } from "@/components/renderJson"; +import { useDocumentTitle } from "@/hooks/useDocumentTitle"; import { QtClient, useXrpc } from "@/providers/qtprovider"; import "@atcute/bluesky/lexicons"; import { @@ -97,6 +98,12 @@ function RouteComponent() { rkey, ); + useDocumentTitle( + repoInfo + ? `${repoInfo?.handle ? `${repoInfo.handle} | ` : ""}${collection} | atp.tools` + : "atp.tools", + ); + if (error) { return
Error: {error.message}
; } diff --git a/src/routes/at:/$handle.index.tsx b/src/routes/at:/$handle.index.tsx index ad6fa7c..d631d18 100644 --- a/src/routes/at:/$handle.index.tsx +++ b/src/routes/at:/$handle.index.tsx @@ -1,4 +1,5 @@ import RepoIcons from "@/components/repoIcons"; +import { useDocumentTitle } from "@/hooks/useDocumentTitle"; import { QtClient, useXrpc } from "@/providers/qtprovider"; import "@atcute/bluesky/lexicons"; import { @@ -29,6 +30,10 @@ function useRepoData(handle: string): RepoData { error: null, }); + useDocumentTitle( + state.data?.handle ? `${state.data.handle} | atp.tools` : "atp.tools", + ); + useEffect(() => { const abortController = new AbortController(); diff --git a/src/routes/at:/$handle/$collection.index.lazy.tsx b/src/routes/at:/$handle/$collection.index.lazy.tsx index cb2c4dc..b917a81 100644 --- a/src/routes/at:/$handle/$collection.index.lazy.tsx +++ b/src/routes/at:/$handle/$collection.index.lazy.tsx @@ -1,3 +1,4 @@ +import { useDocumentTitle } from "@/hooks/useDocumentTitle"; import { QtClient } from "@/providers/qtprovider"; import { ComAtprotoRepoListRecords } from "@atcute/client/lexicons"; import { @@ -89,6 +90,8 @@ function RouteComponent() { useCollectionRecords(handle, collection); const loaderRef = useRef(null); + useDocumentTitle(records ? `${collection} | atp.tools` : "atp.tools"); + useEffect(() => { if (!loaderRef.current) return;