import { useState } from 'react';
import { EXAMPLE_QUERIES } from '../constants';
interface QueryInputProps {
onSearch: (query: string, intent?: string) => void;
disabled: boolean;
}
export default function QueryInput({ onSearch, disabled }: QueryInputProps) {
const [query, setQuery] = useState('');
const [intent, setIntent] = useState('');
const [showIntent, setShowIntent] = useState(false);
function handleSubmit(e: React.FormEvent) {
e.preventDefault();
const trimmed = query.trim();
if (trimmed) onSearch(trimmed, intent.trim() || undefined);
}
function handleExample(q: string, exIntent?: string) {
setQuery(q);
if (exIntent) {
setIntent(exIntent);
setShowIntent(true);
} else {
setIntent('');
setShowIntent(false);
}
onSearch(q, exIntent);
}
return (
{!showIntent && (
)}
{showIntent && !intent.trim() && (
)}
Demo queries:
{EXAMPLE_QUERIES.map(ex => (
))}
);
}