Update chat session title in side pane to new title after rename

Previously the rename wasn't updating the chat session title. We'd
have to refresh the page or side pane to get latest chat session names
after rename action.
This commit is contained in:
Debanjum Singh Solanky
2024-08-04 04:03:52 +05:30
parent 2f7a8698a0
commit f38c072f07

View File

@@ -369,6 +369,7 @@ function SessionsAndFiles(props: SessionsAndFilesProps) {
interface ChatSessionActionMenuProps { interface ChatSessionActionMenuProps {
conversationId: string; conversationId: string;
setTitle: (title: string) => void;
} }
function ChatSessionActionMenu(props: ChatSessionActionMenuProps) { function ChatSessionActionMenu(props: ChatSessionActionMenuProps) {
@@ -409,6 +410,7 @@ function ChatSessionActionMenu(props: ChatSessionActionMenuProps) {
<Button <Button
onClick={() => { onClick={() => {
renameConversation(props.conversationId, renamedTitle); renameConversation(props.conversationId, renamedTitle);
props.setTitle(renamedTitle);
setIsRenaming(false); setIsRenaming(false);
}} }}
type="submit">Rename</Button> type="submit">Rename</Button>
@@ -529,6 +531,7 @@ function ChatSessionActionMenu(props: ChatSessionActionMenuProps) {
function ChatSession(props: ChatHistory) { function ChatSession(props: ChatHistory) {
const [isHovered, setIsHovered] = useState(false); const [isHovered, setIsHovered] = useState(false);
const [title, setTitle] = useState(props.slug || "New Conversation 🌱");
var currConversationId = parseInt(new URLSearchParams(window.location.search).get('conversationId') || "-1"); var currConversationId = parseInt(new URLSearchParams(window.location.search).get('conversationId') || "-1");
return ( return (
<div <div
@@ -537,9 +540,9 @@ function ChatSession(props: ChatHistory) {
key={props.conversation_id} key={props.conversation_id}
className={`${styles.session} ${props.compressed ? styles.compressed : '!max-w-full'} ${isHovered ? `${styles.sessionHover}` : ''} ${currConversationId === parseInt(props.conversation_id) && currConversationId != -1 ? "dark:bg-neutral-800 bg-white" : ""}`}> className={`${styles.session} ${props.compressed ? styles.compressed : '!max-w-full'} ${isHovered ? `${styles.sessionHover}` : ''} ${currConversationId === parseInt(props.conversation_id) && currConversationId != -1 ? "dark:bg-neutral-800 bg-white" : ""}`}>
<Link href={`/chat?conversationId=${props.conversation_id}`} onClick={() => props.showSidePanel(false)}> <Link href={`/chat?conversationId=${props.conversation_id}`} onClick={() => props.showSidePanel(false)}>
<p className={styles.session}>{props.slug || "New Conversation 🌱"}</p> <p className={styles.session}>{title}</p>
</Link> </Link>
<ChatSessionActionMenu conversationId={props.conversation_id} /> <ChatSessionActionMenu conversationId={props.conversation_id} setTitle={setTitle} />
</div> </div>
); );
} }