Spaces:
Running
Running
OpenEEGBench / frontend /src /pages /AddModelPage /components /SubmissionLimitChecker /SubmissionLimitChecker.js
Download frontend/src/pages/AddModelPage/components/SubmissionLimitChecker/SubmissionLimitChecker.js from braindecode/OpenEEGBench: direct link, hf CLI and curl.
- Browser
- Download file 2.1 kB
-
https://huggingface.co/spaces/braindecode/OpenEEGBench/resolve/main/frontend/src/pages/AddModelPage/components/SubmissionLimitChecker/SubmissionLimitChecker.js
- Command line
-
hf download hf://spaces/braindecode/OpenEEGBench/frontend/src/pages/AddModelPage/components/SubmissionLimitChecker/SubmissionLimitChecker.js
-
curl -L -o SubmissionLimitChecker.js https://huggingface.co/spaces/braindecode/OpenEEGBench/resolve/main/frontend/src/pages/AddModelPage/components/SubmissionLimitChecker/SubmissionLimitChecker.js
2.1 kB
| import React, { useState, useEffect } from "react"; | |
| import { Alert, Box, CircularProgress } from "@mui/material"; | |
| const MAX_SUBMISSIONS_PER_MONTH = 5; | |
| function SubmissionLimitChecker({ user, children }) { | |
| const [loading, setLoading] = useState(true); | |
| const [reachedLimit, setReachedLimit] = useState(false); | |
| const [error, setError] = useState(false); | |
| useEffect(() => { | |
| const checkSubmissionLimit = async () => { | |
| if (!user?.username) { | |
| setLoading(false); | |
| return; | |
| } | |
| try { | |
| const response = await fetch( | |
| `/api/models/organization/${user.username}/submissions?days=30` | |
| ); | |
| if (!response.ok) { | |
| throw new Error("Failed to fetch submission data"); | |
| } | |
| const submissions = await response.json(); | |
| console.log(`Recent submissions for ${user.username}:`, submissions); | |
| setReachedLimit(submissions.length >= MAX_SUBMISSIONS_PER_MONTH); | |
| setError(false); | |
| } catch (error) { | |
| console.error("Error checking submission limit:", error); | |
| setError(true); | |
| } finally { | |
| setLoading(false); | |
| } | |
| }; | |
| checkSubmissionLimit(); | |
| }, [user?.username]); | |
| if (loading) { | |
| return ( | |
| <Box sx={{ display: "flex", justifyContent: "center", py: 4 }}> | |
| <CircularProgress /> | |
| </Box> | |
| ); | |
| } | |
| if (error) { | |
| return ( | |
| <Alert | |
| severity="error" | |
| sx={{ | |
| mb: 3, | |
| "& .MuiAlert-message": { | |
| fontSize: "1rem", | |
| }, | |
| }} | |
| > | |
| Unable to verify submission limits. Please try again in a few minutes. | |
| </Alert> | |
| ); | |
| } | |
| if (reachedLimit) { | |
| return ( | |
| <Alert | |
| severity="warning" | |
| sx={{ | |
| mb: 3, | |
| "& .MuiAlert-message": { | |
| fontSize: "1rem", | |
| }, | |
| }} | |
| > | |
| For fairness reasons, you cannot submit more than{" "} | |
| {MAX_SUBMISSIONS_PER_MONTH} submissions per month. Please try again next | |
| month. | |
| </Alert> | |
| ); | |
| } | |
| return children; | |
| } | |
| export default SubmissionLimitChecker; | |