Skip to content

Commit

Permalink
feat: add dynamic page titles based on selected conversation
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikBjare committed Jan 30, 2025
1 parent eee7607 commit a57be6e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/pages/Index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { type FC } from "react";
import { useState, useCallback, useEffect } from "react";
import { setDocumentTitle } from "@/utils/title";
import { useQuery, useQueryClient } from "@tanstack/react-query";
import { MenuBar } from "@/components/MenuBar";
import { LeftSidebar } from "@/components/LeftSidebar";
Expand Down Expand Up @@ -101,6 +102,16 @@ const Index: FC<Props> = () => {
(conv) => conv.name === selectedConversation
) ?? allConversations[0]; // Fallback to first conversation if none selected

// Update document title when selected conversation changes
useEffect(() => {
if (conversation) {
setDocumentTitle(conversation.name);
} else {
setDocumentTitle();
}
return () => setDocumentTitle(); // Reset title on unmount
}, [conversation]);

return (
<div className="h-screen flex flex-col">
<MenuBar />
Expand Down
3 changes: 3 additions & 0 deletions src/utils/title.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function setDocumentTitle(title?: string) {
document.title = title ? `gptme - ${title}` : 'gptme';
}

0 comments on commit a57be6e

Please sign in to comment.