import { useState, useCallback, useEffect } from 'react'; import { Send, Loader2, Trash2, Sparkles } from 'lucide-react'; import { useSentimentAnalysis } from '../hooks/useSentimentAnalysis'; import { validateText, MAX_TEXT_LENGTH } from '../utils/validators'; import ResultCard from './ResultCard'; const SAMPLE_TEXTS = { positive: "I absolutely love this product! It exceeded all my expectations and the customer service was fantastic. Highly recommend to everyone!", negative: "This is terrible. I'm extremely disappointed with the quality and service. Complete waste of money and time. Do not buy!", }; interface SentimentAnalyzerProps { onAnalysisComplete?: () => void; } const SentimentAnalyzer = ({ onAnalysisComplete }: SentimentAnalyzerProps) => { const [text, setText] = useState(''); const [validationError, setValidationError] = useState(null); const { result, isLoading, error, analyze, reset } = useSentimentAnalysis(); const handleTextChange = (e: React.ChangeEvent) => { const newText = e.target.value; setText(newText); if (newText.trim()) { const validation = validateText(newText); setValidationError(validation.error); } else { setValidationError(null); } }; const handleSubmit = useCallback(async (e?: React.FormEvent) => { e?.preventDefault(); const validation = validateText(text); if (!validation.isValid) { setValidationError(validation.error); return; } await analyze(text.trim()); onAnalysisComplete?.(); }, [text, analyze, onAnalysisComplete]); const handleKeyDown = (e: React.KeyboardEvent) => { if ((e.metaKey || e.ctrlKey) && e.key === 'Enter') { handleSubmit(); } }; const handleClear = () => { setText(''); setValidationError(null); reset(); }; const handleSampleText = (type: 'positive' | 'negative') => { setText(SAMPLE_TEXTS[type]); setValidationError(null); reset(); }; // Scroll to result when analysis completes useEffect(() => { if (result) { document.getElementById('result-section')?.scrollIntoView({ behavior: 'smooth' }); } }, [result]); const isValid = text.trim().length > 0 && !validationError; const charCount = text.length; const charCountClass = charCount > MAX_TEXT_LENGTH ? 'text-red-500' : charCount > MAX_TEXT_LENGTH * 0.9 ? 'text-yellow-500' : 'text-gray-400'; return (
{/* Hero Section */}

Analyze Text Sentiment in Real-Time

Powered by DistilBERT transformer model with 99%+ accuracy. Experience lightning-fast results with Redis caching.

{/* Input Section */}