Skip to content

Commit

Permalink
fix: auto-focus current conversation in ChatListDropdown (#141)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevin-on authored Nov 27, 2024
1 parent 2b6ab4d commit edcc7a3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/components/chat-view/Chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,7 @@ const Chat = forwardRef<ChatRef, ChatProps>((props, ref) => {
</button>
<ChatListDropdown
chatList={chatList}
currentConversationId={currentConversationId}
onSelect={async (conversationId) => {
if (conversationId === currentConversationId) return
await handleLoadConversation(conversationId)
Expand Down
9 changes: 7 additions & 2 deletions src/components/chat-view/ChatListDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,15 @@ function ChatListItem({

export function ChatListDropdown({
chatList,
currentConversationId,
onSelect,
onDelete,
onUpdateTitle,
className,
children,
}: {
chatList: ChatConversationMeta[]
currentConversationId: string
onSelect: (conversationId: string) => Promise<void>
onDelete: (conversationId: string) => Promise<void>
onUpdateTitle: (conversationId: string, newTitle: string) => Promise<void>
Expand All @@ -127,7 +129,10 @@ export function ChatListDropdown({

useEffect(() => {
if (open) {
setFocusedIndex(0)
const currentIndex = chatList.findIndex(
(chat) => chat.id === currentConversationId,
)
setFocusedIndex(currentIndex === -1 ? 0 : currentIndex)
setEditingId(null)
}
}, [open])
Expand Down Expand Up @@ -171,8 +176,8 @@ export function ChatListDropdown({
setFocusedIndex(index)
}}
onSelect={async () => {
setEditingId(null)
await onSelect(chat.id)
setOpen(false)
}}
onDelete={async () => {
await onDelete(chat.id)
Expand Down

0 comments on commit edcc7a3

Please sign in to comment.