File size: 8,723 Bytes
08b0543 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | import { useState, useRef } from 'react';
import { Send, Upload, FileText, X, Loader2 } from 'lucide-react';
export default function QueryInput({ onQuery, onCsvUpload, loading, csvMode = false, selectedNeon = [], selectedComparison = [], comparisonProviders = [] }) {
const [query, setQuery] = useState('');
const [selectedFile, setSelectedFile] = useState(null);
const fileInputRef = useRef(null);
const handleSubmit = (e) => {
e.preventDefault();
if (csvMode && selectedFile) {
onCsvUpload(selectedFile);
} else if (!csvMode && query.trim()) {
onQuery(query.trim());
setQuery('');
}
};
const handleFileDrop = (e) => {
e.preventDefault();
const file = e.dataTransfer?.files?.[0];
if (file && file.name.endsWith('.csv')) {
setSelectedFile(file);
}
};
const handleFileSelect = (e) => {
const file = e.target.files?.[0];
if (file) setSelectedFile(file);
};
const handleKeyDown = (e) => {
if (e.key === 'Enter' && !e.shiftKey && !csvMode) {
e.preventDefault();
handleSubmit(e);
}
};
const neonDisplayName = (sel) => {
const name = sel.model_id.split('@')[0].split('/').pop();
return `${name} - ${sel.persona_name}`;
};
const comparisonDisplayName = (modelId) => {
for (const provider of comparisonProviders) {
const model = provider.models.find(m => m.id === modelId);
if (model) return model.name;
}
return modelId.split('/').pop();
};
return (
<div className="query-input-container">
<form onSubmit={handleSubmit} className="query-form">
{csvMode ? (
<div
className={`csv-drop-zone ${selectedFile ? 'has-file' : ''}`}
onDragOver={e => e.preventDefault()}
onDrop={handleFileDrop}
onClick={() => fileInputRef.current?.click()}
>
<input
ref={fileInputRef}
type="file"
accept=".csv"
onChange={handleFileSelect}
style={{ display: 'none' }}
/>
{selectedFile ? (
<div className="csv-file-info">
<FileText size={20} />
<span>{selectedFile.name}</span>
<button
type="button"
className="csv-clear"
onClick={(e) => { e.stopPropagation(); setSelectedFile(null); }}
>
<X size={14} />
</button>
</div>
) : (
<div className="csv-placeholder">
<Upload size={24} />
<span>Drop a CSV file here or click to browse</span>
<span className="csv-hint">Single column of questions</span>
</div>
)}
</div>
) : (
<textarea
className="query-textarea"
value={query}
onChange={e => setQuery(e.target.value)}
onKeyDown={handleKeyDown}
placeholder="Ask a question to compare across models..."
rows={2}
disabled={loading}
/>
)}
<div className="query-submit-row">
<button
type="submit"
className="query-submit"
disabled={loading || (csvMode ? !selectedFile : !query.trim())}
>
{loading ? <Loader2 size={18} className="spin" /> : <Send size={18} />}
{csvMode ? 'Run Batch' : 'Compare'}
</button>
{(selectedNeon.length > 0 || selectedComparison.length > 0) && (
<div className="selection-summary">
{selectedNeon.length > 0 && (
<div className="selection-line">
<span className="selection-label">Neon.ai Models Selected:</span>{' '}
{selectedNeon.map(s => neonDisplayName(s)).join(', ')} <span className="selection-count">({selectedNeon.length})</span>
</div>
)}
{selectedComparison.length > 0 && (
<div className="selection-line">
<span className="selection-label">Comparison Models Selected:</span>{' '}
{selectedComparison.map(id => comparisonDisplayName(id)).join(', ')} <span className="selection-count">({selectedComparison.length})</span>
</div>
)}
</div>
)}
</div>
</form>
<style>{`
.query-input-container {
display: flex;
flex-direction: column;
gap: 8px;
}
.query-form {
display: flex;
flex-direction: column;
gap: 8px;
}
.query-textarea {
flex: 1;
padding: 10px 14px;
border: 2px solid var(--query-accent);
border-radius: 10px;
background: var(--card-bg);
color: var(--text-primary);
font-family: inherit;
font-size: 14px;
resize: vertical;
min-height: 44px;
outline: none;
transition: border-color 0.15s;
}
.query-textarea:focus {
border-color: var(--query-accent);
}
.query-textarea::placeholder {
color: var(--text-muted);
}
.csv-drop-zone {
flex: 1;
border: 2px dashed var(--border-primary);
border-radius: 10px;
padding: 20px;
text-align: center;
cursor: pointer;
transition: border-color 0.15s, background 0.15s;
background: var(--card-bg);
}
.csv-drop-zone:hover {
border-color: var(--accent-primary);
background: var(--accent-light);
}
.csv-drop-zone.has-file {
border-style: solid;
border-color: var(--neon-accent);
}
.csv-placeholder {
display: flex;
flex-direction: column;
align-items: center;
gap: 6px;
color: var(--text-tertiary);
font-size: 13px;
}
.csv-hint {
font-size: 11px;
color: var(--text-muted);
}
.csv-file-info {
display: flex;
align-items: center;
gap: 8px;
color: var(--neon-accent);
font-size: 14px;
font-weight: 500;
justify-content: center;
}
.csv-clear {
display: flex;
align-items: center;
justify-content: center;
width: 22px;
height: 22px;
border: none;
border-radius: 50%;
background: var(--bg-tertiary);
color: var(--text-muted);
}
.csv-clear:hover {
background: #FEE2E2;
color: #EF4444;
}
.query-submit-row {
display: flex;
align-items: flex-end;
gap: 16px;
}
.query-submit {
display: flex;
align-items: center;
gap: 6px;
padding: 10px 20px;
border: none;
border-radius: 10px;
background: var(--accent-gradient);
color: #FFFFFF;
font-size: 14px;
font-weight: 600;
white-space: nowrap;
transition: opacity 0.15s, transform 0.1s;
flex-shrink: 0;
}
.selection-summary {
display: flex;
flex-direction: column;
gap: 2px;
padding-top: 2px;
min-width: 0;
}
.selection-line {
font-size: 14px;
font-family: inherit;
color: var(--text-muted);
line-height: 1.5;
word-break: break-word;
}
.selection-label {
font-weight: 600;
color: var(--text-secondary);
}
.selection-count {
font-weight: 600;
color: var(--text-secondary);
}
.query-submit:hover:not(:disabled) {
opacity: 0.9;
transform: translateY(-1px);
}
.query-submit:disabled {
opacity: 0.5;
cursor: not-allowed;
}
@media (max-width: 480px) {
.query-textarea {
min-height: 48px;
font-size: 16px;
}
.query-submit-row {
flex-direction: column;
gap: 8px;
}
.query-submit {
align-self: stretch;
justify-content: center;
padding: 12px 20px;
font-size: 15px;
}
.selection-line {
font-size: 13px;
}
.csv-drop-zone {
padding: 16px;
}
}
`}</style>
</div>
);
}
|