Spaces:
Running
Running
File size: 5,161 Bytes
5470817 953a39e 5470817 953a39e 1254641 5470817 4a90775 5470817 953a39e 5470817 b4d058e 953a39e 5470817 953a39e 5470817 1254641 5470817 b4d058e 5470817 953a39e 5470817 1254641 5470817 953a39e 4a90775 953a39e 5470817 953a39e 5470817 1254641 953a39e 1254641 5470817 1254641 5470817 953a39e 5470817 |
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 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 |
import React, { useState, useEffect } from "react";
import {
Box,
CircularProgress,
Stack,
Button,
FormControlLabel,
Switch,
TextField,
InputAdornment,
Typography,
} from "@mui/material";
import SearchIcon from "@mui/icons-material/Search";
import SearchOffIcon from "@mui/icons-material/SearchOff";
import Logo from "../../components/Logo/Logo";
import PageTitle from "../../components/PageTitle/PageTitle";
import PageHeader from "../../components/PageHeader/PageHeader";
import LeaderboardSection from "../../components/LeaderboardSection";
import LeaderboardFilters from "../../components/LeaderboardFilters/LeaderboardFilters";
import { alpha } from "@mui/material/styles";
import API_URLS from "../../config/api";
import {
LeaderboardProvider,
useLeaderboard,
} from "../../context/LeaderboardContext";
const LeaderboardPageContent = () => {
const [loading, setLoading] = useState(true);
const {
setLeaderboards,
filterLeaderboards,
sections,
allSections,
searchQuery,
arenaOnly,
} = useLeaderboard();
useEffect(() => {
fetch(API_URLS.leaderboards)
.then((res) => res.json())
.then((data) => {
const leaderboardsArray = Array.isArray(data)
? data
: Object.values(data).filter((item) => Array.isArray(item))[0];
setLeaderboards(leaderboardsArray);
setLoading(false);
})
.catch((error) => {
console.error("Error fetching leaderboards:", error);
setLoading(false);
});
}, [setLeaderboards]);
// Check if any leaderboards are found after filtering
const totalFilteredLeaderboards = sections.reduce(
(total, { data }) => total + filterLeaderboards(data).length,
0
);
const hasLeaderboards = totalFilteredLeaderboards > 0;
const isFiltering = searchQuery || arenaOnly;
return (
<Box
sx={{
width: "100%",
ph: 2,
display: "flex",
flexDirection: "column",
}}
>
<Box
sx={{ display: "flex", justifyContent: "center", pt: 6, mb: -4, pb: 0 }}
>
<Logo />
</Box>
<Box
sx={{
display: "flex",
flexDirection: "column",
alignItems: "center",
textAlign: "center",
mb: 0,
mt: 6,
gap: 2,
}}
>
<PageTitle />
<Typography variant="h6" color="text.secondary">
<span style={{ fontWeight: 600 }}>Discover</span> and{" "}
<span style={{ fontWeight: 600 }}>explore</span> all leaderboards from
the <span style={{ fontWeight: 600 }}>Hugging Face community</span>
</Typography>
</Box>
{loading ? (
<Box sx={{ display: "flex", justifyContent: "center", mt: 4 }}>
<CircularProgress />
</Box>
) : (
<Box
sx={{
width: "100%",
maxWidth: "1200px",
mx: "auto",
mt: 4,
}}
>
<LeaderboardFilters allSections={allSections} />
{!hasLeaderboards && isFiltering && (
<Box
sx={{
display: "flex",
flexDirection: "column",
alignItems: "center",
gap: 2,
mt: 8,
py: 7,
}}
>
<SearchOffIcon
sx={{
fontSize: 64,
color: "text.secondary",
opacity: 0.5,
}}
/>
<Typography variant="h5" color="text.secondary" align="center">
{searchQuery ? (
<>
Oops! No leaderboard matches{" "}
<Box
component="span"
sx={{
bgcolor: "primary.main",
color: "primary.contrastText",
px: 1,
borderRadius: 1,
}}
>
{searchQuery}
</Box>
</>
) : (
"Oops! No leaderboard matches your criteria"
)}
</Typography>
<Typography variant="body1" color="text.secondary" align="center">
Try adjusting your search filters
</Typography>
</Box>
)}
{(hasLeaderboards || !isFiltering) &&
sections.map(({ id, title, data }) => {
const filteredLeaderboards = filterLeaderboards(data);
if (filteredLeaderboards.length === 0) return null;
return (
<Box key={id} id={id}>
<LeaderboardSection
title={title}
leaderboards={filteredLeaderboards}
/>
</Box>
);
})}
</Box>
)}
</Box>
);
};
const LeaderboardPage = () => {
return (
<LeaderboardProvider>
<LeaderboardPageContent />
</LeaderboardProvider>
);
};
export default LeaderboardPage;
|