Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat [ui]: ensure chat tab index ordering #364

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions ui/desktop/src/components/Tabs.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { useEffect, useState, useRef } from 'react';
import { useNavigate } from 'react-router-dom'
import { Chat } from '../ChatWindow';

import Plus from './ui/Plus';
import X from './ui/X';
Expand Down Expand Up @@ -129,10 +130,10 @@ export default function Tabs({ chats, selectedChatId, setSelectedChatId, setChat

// Tab management functions
const addChat = () => {
const newChatId = chats[chats.length-1].id + 1;
const newChatId = chats.length > 0 ? Math.max(...chats.map(chat => chat.id)) + 1 : 1;
const newChat = {
id: newChatId,
title: `Chat ${newChatId}`,
title: `Chat ${chats.length + 1}`,
messages: [],
};
setChats([...chats, newChat]);
Expand All @@ -141,8 +142,19 @@ export default function Tabs({ chats, selectedChatId, setSelectedChatId, setChat

const removeChat = (chatId: number) => {
const updatedChats = chats.filter((chat: any) => chat.id !== chatId);
setChats(updatedChats);
navigateChat(updatedChats[0].id);
// Reassign titles based on the new order
const reorderedChats = updatedChats.map((chat: Chat, index: number) => ({
...chat,
title: `Chat ${index + 1}`,
}));

// Update the chats state
setChats(reorderedChats);

// Navigate to the first remaining chat (if any)
if (reorderedChats.length > 0) {
navigateChat(reorderedChats[0].id);
}
};

return (
Expand Down
Loading