import React, { useState, useEffect } from 'react';
import Header from './components/Header';
import JobForm from './components/JobForm';
import JobStatusCard from './components/JobStatusCard';
import ResultsDisplay from './components/ResultsDisplay';
import LoadingSkeleton from './components/LoadingSkeleton';
import HistoryPanel from './components/HistoryPanel';
import { createJob, getJob } from './services/api';
import { XCircle } from 'lucide-react';
function App() {
const [job, setJob] = useState(null);
const [isLoading, setIsLoading] = useState(false);
const [isPolling, setIsPolling] = useState(false);
const [error, setError] = useState(null);
const handleAnalysisRequest = async (ticker) => {
setIsLoading(true);
setIsPolling(true);
setError(null);
setJob(null);
try {
const response = await createJob(ticker);
setJob(response.data);
} catch (err) {
setError('Failed to create job. Please check the API server and try again.');
setIsLoading(false);
setIsPolling(false);
}
};
const handleSelectHistoryJob = (historyJob) => {
setIsLoading(false);
setIsPolling(false);
setError(null);
setJob(historyJob);
}
useEffect(() => {
if (!job?.id || !isPolling) return;
if (job.status !== 'PENDING') {
setIsLoading(false);
}
const intervalId = setInterval(async () => {
try {
const response = await getJob(job.id);
const updatedJob = response.data;
setJob(updatedJob);
if (updatedJob.status === 'SUCCESS' || updatedJob.status === 'FAILED') {
clearInterval(intervalId);
setIsPolling(false);
}
} catch (err) {
setError('Failed to poll job status.');
clearInterval(intervalId);
setIsPolling(false);
}
}, 3000);
return () => clearInterval(intervalId);
}, [job, isPolling]);
return (
Enter an Indian stock ticker to receive a comprehensive, AI-powered analysis.
{error &&
{error}
}
{isLoading && !job &&
}
{job && !isLoading &&
}
{job?.status === 'SUCCESS' && job.result && (
)}
{job?.status === 'FAILED' && job.result?.error && (
Analysis Failed
We couldn't complete the analysis for {job.ticker}.
This usually means the stock symbol is incorrect or not listed.
Please double-check the ticker (e.g., RELIANCE.NS) and try again.
Show technical details
{job.result.error}
)}
);
}
export default App;