Skip to content

Commit a57be6e

Browse files
committed
feat: add dynamic page titles based on selected conversation
1 parent eee7607 commit a57be6e

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/pages/Index.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { type FC } from "react";
22
import { useState, useCallback, useEffect } from "react";
3+
import { setDocumentTitle } from "@/utils/title";
34
import { useQuery, useQueryClient } from "@tanstack/react-query";
45
import { MenuBar } from "@/components/MenuBar";
56
import { LeftSidebar } from "@/components/LeftSidebar";
@@ -101,6 +102,16 @@ const Index: FC<Props> = () => {
101102
(conv) => conv.name === selectedConversation
102103
) ?? allConversations[0]; // Fallback to first conversation if none selected
103104

105+
// Update document title when selected conversation changes
106+
useEffect(() => {
107+
if (conversation) {
108+
setDocumentTitle(conversation.name);
109+
} else {
110+
setDocumentTitle();
111+
}
112+
return () => setDocumentTitle(); // Reset title on unmount
113+
}, [conversation]);
114+
104115
return (
105116
<div className="h-screen flex flex-col">
106117
<MenuBar />

src/utils/title.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export function setDocumentTitle(title?: string) {
2+
document.title = title ? `gptme - ${title}` : 'gptme';
3+
}

0 commit comments

Comments
 (0)