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

fix: auto-focus current conversation in ChatListDropdown #141

Merged
merged 1 commit into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
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
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 @@

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,10 +129,13 @@

useEffect(() => {
if (open) {
setFocusedIndex(0)
const currentIndex = chatList.findIndex(
(chat) => chat.id === currentConversationId,
)
setFocusedIndex(currentIndex === -1 ? 0 : currentIndex)
setEditingId(null)
}
}, [open])

Check warning on line 138 in src/components/chat-view/ChatListDropdown.tsx

View workflow job for this annotation

GitHub Actions / check

React Hook useEffect has missing dependencies: 'chatList' and 'currentConversationId'. Either include them or remove the dependency array

useEffect(() => {
const handleKeyDown = (e: KeyboardEvent) => {
Expand Down Expand Up @@ -171,8 +176,8 @@
setFocusedIndex(index)
}}
onSelect={async () => {
setEditingId(null)
await onSelect(chat.id)
setOpen(false)
}}
onDelete={async () => {
await onDelete(chat.id)
Expand Down