Skip to content

Commit

Permalink
commit forgotten home changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Konzisam committed Dec 9, 2024
1 parent 2d2406a commit 670f5e2
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions frontend/src/components/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,22 @@ interface HomeProps {
const Home: React.FC<HomeProps> = ({ accessToken }) => {
const [prediction, setPrediction] = useState<number | null>(null);
const [errorMessage, setErrorMessage] = useState<string | null>(null);
const [loading, setLoading] = useState<boolean>(false);

const handleSubmit = async (values: InputData) => {
if (!accessToken) {
setErrorMessage("Access token is missing. Please log in again.");
setLoading(false);
return;
}

try {
const predictionValue = await fetchPrediction(values, accessToken);
setPrediction(predictionValue ?? null);
setErrorMessage(null);
console.log("Predicted value: ", predictionValue);
setLoading(false);
} catch (error) {
setErrorMessage("An error occurred while fetching the prediction.");
setLoading(false);
console.error(error);
}
};
Expand All @@ -35,7 +37,7 @@ const Home: React.FC<HomeProps> = ({ accessToken }) => {
<img src="logo.png" alt="logo" />
</div>
<h1>Car Price Estimator</h1>
<MyForm onSubmit={handleSubmit} prediction={prediction} />
<MyForm onSubmit={handleSubmit} prediction={prediction} loading={loading} />
{errorMessage && <div className="error-message">{errorMessage}</div>}
</div>
);
Expand Down

0 comments on commit 670f5e2

Please sign in to comment.