Open History to see the last commit
1import { useLocation, useParams } from "@tanstack/react-router";
2
3import { useFolderView, useNoteInFolder } from "@/db/queries";
4import { noteDisplayTitle } from "@/lib/notes/note-body";
5
6/** Title of the current Notes page, shown in the fake browser tab. Live: it follows edits. */
7export function usePageTitle(): string {
8 const { folderId, noteId } = useParams({ strict: false });
9 const pathname = useLocation({ select: (location) => location.pathname });
10 const { view: folder } = useFolderView(folderId ?? "");
11 const { note } = useNoteInFolder(folderId ?? "", noteId ?? "");
12
13 if (note) return noteDisplayTitle(note.title);
14 if (folder) return folder.name;
15 if (pathname === "/settings") return "Settings";
16 if (pathname === "/analytics") return "Analytics";
17 return "Notes";
18}