Skip to content
Source
Sign inSign up
fuko/trytanstackdb-v2
Open History to see the last commit

use-page-title.ts

17 lines685 Bytes

1import { useLocation, useParams } from "@tanstack/react-router";
2​
3import { useFolderView, useNoteInFolder } from "@/data/notes-data";
4​
5/** Title of the current Notes page, shown in the fake browser tab. */
6export function usePageTitle(): string {
7 const { folderId, noteId } = useParams({ strict: false });
8 const pathname = useLocation({ select: (location) => location.pathname });
9 const folder = useFolderView(folderId ?? "");
10 const note = useNoteInFolder(folderId ?? "", noteId ?? "");
11​
12 if (note) return note.title;
13 if (folder) return folder.name;
14 if (pathname === "/settings") return "Settings";
15 if (pathname === "/analytics") return "Analytics";
16 return "Notes";