import { useState } from 'react'; import { runQuery } from '../api/client'; import ResultCard from './ResultCard'; export default function QueryPanel({ accessToken }) { const [query, setQuery] = useState(''); const [result, setResult] = useState(null); const [loading, setLoading] = useState(false); const [error, setError] = useState(null); const [showDebug, setShowDebug] = useState(false); const handleSubmit = async (e) => { e.preventDefault(); if (!query.trim()) return; if (!accessToken) { setError('Please connect to Dropbox first to enable zero-storage queries.'); return; } setLoading(true); setError(null); try { const data = await runQuery(query, accessToken); setResult(data); if (data.error) { setError(data.error); } } catch (err) { setError(err.message); } setLoading(false); }; const handleClear = () => { setQuery(''); setResult(null); setError(null); setShowDebug(false); }; return (
{/* Query Form */}
setQuery(e.target.value)} placeholder="What would you like to know?" className="flex-1 px-4 py-3 border border-slate-600 rounded-lg bg-slate-800 text-slate-100 placeholder-slate-500 shadow-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-1 focus:ring-offset-slate-900 focus:border-blue-500 transition-all duration-200" />
{/* Error Message */} {error && (
{error}
)} {/* Results */} {result && !error && (
{/* Results Header with Clear Button */}

Answer

{/* Answer Card */}

{result.answer || 'No answer generated.'}

{/* Citations */} {result.citations?.length > 0 && (

Citations ({result.citations.length})

{result.citations.map((citation, idx) => ( ))}
)} {/* Debug Toggle */}
{showDebug && (
                {JSON.stringify(result, null, 2)}
              
)}
)} {/* Empty State - No query yet */} {!result && !error && !loading && (

Ask a Question

{accessToken ? 'Enter a question above to search your indexed documents. Results will include relevant citations from your files.' : 'Connect to Dropbox and index your files first, then ask questions here. Your documents are re-fetched at query time for true zero-storage privacy.' }

)}
); }