Files
autocoder/ui/src/hooks/useConversations.ts
liri c229e2b39b fix: address CodeRabbitAI review comments for conversation history
- Fix duplicate onConversationCreated callbacks by tracking activeConversationId
- Fix history loss when switching conversations with Map-based deduplication
- Disable input while conversation is loading to prevent message routing issues
- Gate WebSocket debug logs behind DEV flag (import.meta.env.DEV)
- Downgrade server logging from info to debug level for reduced noise
- Fix .gitignore prefixes for playwright paths (ui/playwright-report/, ui/test-results/)
- Remove debug console.log from ConversationHistory.tsx
- Add staleTime (30s) to single conversation query for better caching
- Increase history message cap from 20 to 35 for better context
- Replace fixed timeouts with condition-based waits in e2e tests
2026-01-16 22:43:15 +00:00

49 lines
1.5 KiB
TypeScript

/**
* React Query hooks for assistant conversation management
*/
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query'
import * as api from '../lib/api'
/**
* List all conversations for a project
*/
export function useConversations(projectName: string | null) {
return useQuery({
queryKey: ['conversations', projectName],
queryFn: () => api.listAssistantConversations(projectName!),
enabled: !!projectName,
staleTime: 30000, // Cache for 30 seconds
})
}
/**
* Get a single conversation with all its messages
*/
export function useConversation(projectName: string | null, conversationId: number | null) {
return useQuery({
queryKey: ['conversation', projectName, conversationId],
queryFn: () => api.getAssistantConversation(projectName!, conversationId!),
enabled: !!projectName && !!conversationId,
staleTime: 30_000, // Cache for 30 seconds
})
}
/**
* Delete a conversation
*/
export function useDeleteConversation(projectName: string) {
const queryClient = useQueryClient()
return useMutation({
mutationFn: (conversationId: number) =>
api.deleteAssistantConversation(projectName, conversationId),
onSuccess: (_, deletedId) => {
// Invalidate conversations list
queryClient.invalidateQueries({ queryKey: ['conversations', projectName] })
// Remove the specific conversation from cache
queryClient.removeQueries({ queryKey: ['conversation', projectName, deletedId] })
},
})
}