Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
File size: 2,440 Bytes
ebdfd67 973863f ebdfd67 ffa4ae8 ebdfd67 d6f0b38 ebdfd67 d6f0b38 ffa4ae8 ebdfd67 973863f ebdfd67 d6f0b38 ebdfd67 d6f0b38 ebdfd67 ffa4ae8 ebdfd67 d6f0b38 ebdfd67 ffa4ae8 ebdfd67 |
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 |
import React, { useState, useEffect } from "react";
import { Box, CircularProgress } from "@mui/material";
import { useNavigate, useSearchParams, Navigate } from "react-router-dom";
import Intro from "../components/Intro";
import BenchmarkEvaluation from "../components/BenchmarkEvaluation";
import API_CONFIG from "../config/api";
function BenchmarkEvaluationPage() {
const navigate = useNavigate();
const [searchParams] = useSearchParams();
const sessionId = searchParams.get("session");
const isDefaultFromUrl = searchParams.get("isDefault") === "true";
const isDefault =
isDefaultFromUrl ||
["the-bitter-lesson", "hurricane-faq", "pokemon-guide"].includes(sessionId);
const [isValidSession, setIsValidSession] = useState(true);
const [isLoading, setIsLoading] = useState(true);
useEffect(() => {
if (!sessionId) {
console.log("Missing session ID for evaluation, redirecting to home");
setIsValidSession(false);
return;
}
// If it's a precalculated document, consider it valid directly
if (isDefault) {
setIsLoading(false);
return;
}
const checkSession = async () => {
try {
const response = await fetch(
`${API_CONFIG.BASE_URL}/benchmark-questions/${sessionId}`
);
if (!response.ok) {
console.error(`Invalid session or server error: ${response.status}`);
setIsValidSession(false);
}
} catch (error) {
console.error("Error checking session:", error);
setIsValidSession(false);
} finally {
setIsLoading(false);
}
};
checkSession();
}, [sessionId, isDefault]);
const handleEvaluationComplete = (result) => {
console.log("Evaluation completed:", result);
// Redirection is handled by the BenchmarkEvaluation component
};
if (!isValidSession) {
return <Navigate to="/" />;
}
return (
<>
<Intro />
{isLoading ? (
<Box
sx={{
display: "flex",
justifyContent: "center",
alignItems: "center",
mt: 8,
mb: 8,
}}
>
<CircularProgress size={60} />
</Box>
) : (
<BenchmarkEvaluation
sessionId={sessionId}
isDefaultDocument={isDefault}
onComplete={handleEvaluationComplete}
/>
)}
</>
);
}
export default BenchmarkEvaluationPage;
|