import React, { useState } from 'react'; import { Container, Typography, Box, Paper, Divider } from '@mui/material'; import ReviewInput from '../components/ReviewInput'; import SentimentResult from '../components/SentimentResult'; import PreviousAnalyses from '../components/PreviousAnalysis'; import AboutSection from '../components/AboutSection'; export default function Home() { const [currentReview, setCurrentReview] = useState(''); const [isLoading, setIsLoading] = useState(false); const [hasError, setHasError] = useState(false); const [errorMessage, setErrorMessage] = useState(''); const [analysisResult, setAnalysisResult] = useState(null); const [previousAnalyses, setPreviousAnalyses] = useState([]); const handleViewPreviousAnalysis = (analysis) => { setAnalysisResult(null); setCurrentReview(analysis); }; const addToPreviousAnalyses = (analysis) => { // Add unique ID if it doesn't exist const analysisWithId = analysis.id ? analysis : { ...analysis, id: Date.now(), createdAt: new Date() }; // Add to the beginning of the array to show newest first setPreviousAnalyses(prev => [analysisWithId, ...prev]); }; return ( Movie Review Sentiment Analysis Enter a movie review to analyze its sentiment using AI {!analysisResult ? ( ) : ( setAnalysisResult(null)} currentReview={currentReview} /> )} {hasError && ( {errorMessage || 'An error occurred while analyzing the review. Please try again.'} )} Previous Analyses ); }