An AI-powered search engine with a generative UI
TypeScript generative-aigenerative-uinextjsollamareactsearxngshadcn-uitailwindcsstavilytypescriptupstashvercel-ai-sdk
fix: address PR review comments
Yoshiki Miurac3a340f65bef
diff --git a/components/action-buttons.tsx b/components/action-buttons.tsxindex 8111a3cf..4a96fa50 100644--- a/components/action-buttons.tsx+++ b/components/action-buttons.tsx@@ -15,6 +15,9 @@ import { cn } from '@/lib/utils'import { Button } from './ui/button'+// Constants for timing delays+const FOCUS_OUT_DELAY_MS = 100 // Delay to ensure focus has actually moved+interface ActionCategory {icon: LucideIconlabel: string@@ -85,12 +88,14 @@ const promptSamples: Record<string, string[]> = {interface ActionButtonsProps {onSelectPrompt: (prompt: string) => voidonCategoryClick: (category: string) => void+ inputRef?: React.RefObject<HTMLTextAreaElement>className?: string}export function ActionButtons({onSelectPrompt,onCategoryClick,+ inputRef,className}: ActionButtonsProps) {const [activeCategory, setActiveCategory] = useState<string | null>(null)@@ -125,8 +130,7 @@ export function ActionButtons({) {if (activeCategory) {// Check if click is not on the input field- const input = document.querySelector('textarea[name="input"]')- if (!input?.contains(e.target as Node)) {+ if (!inputRef?.current?.contains(e.target as Node)) {resetToButtons()}}@@ -137,15 +141,14 @@ export function ActionButtons({// Check if focus is moving outside both the container and inputsetTimeout(() => {const activeElement = document.activeElement- const input = document.querySelector('textarea[name="input"]')if (activeCategory &&!containerRef.current?.contains(activeElement) &&- activeElement !== input+ activeElement !== inputRef?.current) {resetToButtons()}- }, 100) // Small delay to ensure focus has actually moved+ }, FOCUS_OUT_DELAY_MS)}document.addEventListener('keydown', handleEscape)@@ -157,7 +160,7 @@ export function ActionButtons({document.removeEventListener('mousedown', handleClickOutside)document.removeEventListener('focusout', handleFocusOut)}- }, [activeCategory])+ }, [activeCategory, inputRef])// Calculate max height needed for samples (4 items * ~40px + padding)const containerHeight = 'h-[180px]'diff --git a/components/chat-panel.tsx b/components/chat-panel.tsxindex 3d0fad32..6de624fa 100644--- a/components/chat-panel.tsx+++ b/components/chat-panel.tsx@@ -21,6 +21,9 @@ import { FileUploadButton } from './file-upload-button'import { ModelSelector } from './model-selector'import { UploadedFileList } from './uploaded-file-list'+// Constants for timing delays+const INPUT_UPDATE_DELAY_MS = 10 // Delay to ensure input value is updated before form submission+interface ChatPanelProps {chatId: stringinput: string@@ -292,7 +295,7 @@ export function ChatPanel({// Submit the form after a small delay to ensure the input is updatedsetTimeout(() => {inputRef.current?.form?.requestSubmit()- }, 10)+ }, INPUT_UPDATE_DELAY_MS)}}onCategoryClick={category => {// Set the category in the input@@ -302,6 +305,7 @@ export function ChatPanel({// Focus the inputinputRef.current?.focus()}}+ inputRef={inputRef}className="mt-2"/>)}