Spaces:
Running
Running
fix empty state
Browse files
client/src/components/LeaderboardSection/components/EmptyState.jsx
CHANGED
@@ -1,8 +1,63 @@
|
|
1 |
import React from "react";
|
2 |
import { Box, Typography } from "@mui/material";
|
3 |
import SearchOffIcon from "@mui/icons-material/SearchOff";
|
|
|
4 |
|
5 |
const EmptyState = ({ title, searchQuery }) => {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
return (
|
7 |
<Box
|
8 |
sx={{
|
@@ -26,24 +81,7 @@ const EmptyState = ({ title, searchQuery }) => {
|
|
26 |
}}
|
27 |
/>
|
28 |
<Typography variant="h5" color="text.secondary" align="center">
|
29 |
-
{
|
30 |
-
<>
|
31 |
-
No {title.toLowerCase()} leaderboard matches{" "}
|
32 |
-
<Box
|
33 |
-
component="span"
|
34 |
-
sx={{
|
35 |
-
bgcolor: "primary.main",
|
36 |
-
color: "primary.contrastText",
|
37 |
-
px: 1,
|
38 |
-
borderRadius: 1,
|
39 |
-
}}
|
40 |
-
>
|
41 |
-
{searchQuery}
|
42 |
-
</Box>
|
43 |
-
</>
|
44 |
-
) : (
|
45 |
-
`No ${title.toLowerCase()} leaderboard matches your criteria`
|
46 |
-
)}
|
47 |
</Typography>
|
48 |
<Typography variant="body1" color="text.secondary" align="center">
|
49 |
Try adjusting your search filters
|
|
|
1 |
import React from "react";
|
2 |
import { Box, Typography } from "@mui/material";
|
3 |
import SearchOffIcon from "@mui/icons-material/SearchOff";
|
4 |
+
import { useLeaderboard } from "../../../context/LeaderboardContext";
|
5 |
|
6 |
const EmptyState = ({ title, searchQuery }) => {
|
7 |
+
const { selectedCategories, selectedLanguage, arenaOnly } = useLeaderboard();
|
8 |
+
|
9 |
+
// Construire un message plus explicite
|
10 |
+
const getDetailedMessage = () => {
|
11 |
+
const filters = [];
|
12 |
+
|
13 |
+
// Vérifier si le titre contient déjà le terme de recherche
|
14 |
+
let cleanTitle = title;
|
15 |
+
let searchTermInTitle = false;
|
16 |
+
|
17 |
+
if (title && searchQuery) {
|
18 |
+
// Vérifier si le titre contient déjà "matching"
|
19 |
+
if (
|
20 |
+
title.toLowerCase().includes(`matching "${searchQuery.toLowerCase()}"`)
|
21 |
+
) {
|
22 |
+
searchTermInTitle = true;
|
23 |
+
}
|
24 |
+
}
|
25 |
+
|
26 |
+
// Ajouter le titre de la section (catégorie)
|
27 |
+
if (title) {
|
28 |
+
// Si le titre contient déjà le terme de recherche, on l'utilise tel quel
|
29 |
+
if (searchTermInTitle) {
|
30 |
+
filters.push(title.toLowerCase());
|
31 |
+
// On ne rajoute pas searchQuery plus tard
|
32 |
+
} else {
|
33 |
+
// Sinon on ajoute le titre sans "matching"
|
34 |
+
filters.push(title.toLowerCase());
|
35 |
+
}
|
36 |
+
}
|
37 |
+
|
38 |
+
// Ajouter les langues sélectionnées
|
39 |
+
if (selectedLanguage && selectedLanguage.size > 0) {
|
40 |
+
const languages = Array.from(selectedLanguage).join(", ");
|
41 |
+
filters.push(`language: ${languages}`);
|
42 |
+
}
|
43 |
+
|
44 |
+
// Ajouter le filtre Arena
|
45 |
+
if (arenaOnly) {
|
46 |
+
filters.push("arena only");
|
47 |
+
}
|
48 |
+
|
49 |
+
// Ajouter le terme de recherche seulement s'il n'est pas déjà dans le titre
|
50 |
+
if (searchQuery && !searchTermInTitle) {
|
51 |
+
filters.push(`matching "${searchQuery}"`);
|
52 |
+
}
|
53 |
+
|
54 |
+
if (filters.length === 0) {
|
55 |
+
return "No results found";
|
56 |
+
}
|
57 |
+
|
58 |
+
return `No ${filters.join(" + ")} leaderboards found`;
|
59 |
+
};
|
60 |
+
|
61 |
return (
|
62 |
<Box
|
63 |
sx={{
|
|
|
81 |
}}
|
82 |
/>
|
83 |
<Typography variant="h5" color="text.secondary" align="center">
|
84 |
+
{getDetailedMessage()}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
85 |
</Typography>
|
86 |
<Typography variant="body1" color="text.secondary" align="center">
|
87 |
Try adjusting your search filters
|
client/src/components/LeaderboardSection/index.jsx
CHANGED
@@ -14,6 +14,7 @@ const LeaderboardSection = ({
|
|
14 |
leaderboards,
|
15 |
filteredLeaderboards,
|
16 |
id,
|
|
|
17 |
}) => {
|
18 |
const {
|
19 |
expandedSections,
|
@@ -107,7 +108,10 @@ const LeaderboardSection = ({
|
|
107 |
)}
|
108 |
|
109 |
{approvedLeaderboards.length === 0 ? (
|
110 |
-
|
|
|
|
|
|
|
111 |
) : (
|
112 |
<LeaderboardGrid
|
113 |
displayedLeaderboards={displayedLeaderboards}
|
|
|
14 |
leaderboards,
|
15 |
filteredLeaderboards,
|
16 |
id,
|
17 |
+
showEmptyState = false,
|
18 |
}) => {
|
19 |
const {
|
20 |
expandedSections,
|
|
|
108 |
)}
|
109 |
|
110 |
{approvedLeaderboards.length === 0 ? (
|
111 |
+
// Afficher EmptyState uniquement si showEmptyState est true
|
112 |
+
showEmptyState ? (
|
113 |
+
<EmptyState title={title} searchQuery={searchQuery} />
|
114 |
+
) : null
|
115 |
) : (
|
116 |
<LeaderboardGrid
|
117 |
displayedLeaderboards={displayedLeaderboards}
|
client/src/pages/LeaderboardPage/LeaderboardPage.jsx
CHANGED
@@ -122,61 +122,85 @@ const LeaderboardPageContent = () => {
|
|
122 |
>
|
123 |
<LeaderboardFilters allSections={allSections} />
|
124 |
|
125 |
-
{/* Message global "No results" seulement si on n'a pas de
|
126 |
-
{!hasLeaderboards &&
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
alignItems: "center",
|
132 |
-
gap: 2,
|
133 |
-
mt: 8,
|
134 |
-
py: 7,
|
135 |
-
}}
|
136 |
-
>
|
137 |
-
<SearchOffIcon
|
138 |
sx={{
|
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 |
-
<Typography variant="body1" color="text.secondary" align="center">
|
165 |
-
Try adjusting your search filters
|
166 |
-
</Typography>
|
167 |
-
</Box>
|
168 |
-
)}
|
169 |
|
170 |
{isOnlyTextSearch ? (
|
171 |
// Vue spéciale pour la recherche textuelle
|
172 |
-
|
173 |
-
<
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
180 |
) : selectedCategories.size > 0 ? (
|
181 |
// Si des catégories sont sélectionnées
|
182 |
selectedCategories.size === 1 ? (
|
@@ -185,10 +209,13 @@ const LeaderboardPageContent = () => {
|
|
185 |
.filter(({ id }) => selectedCategories.has(id))
|
186 |
.map(({ id, title, data }) => {
|
187 |
const filteredLeaderboards = filterLeaderboards(data);
|
|
|
188 |
// Ajouter le terme de recherche au titre si présent
|
189 |
const sectionTitle = searchQuery
|
190 |
? `${title} matching "${searchQuery}"`
|
191 |
: title;
|
|
|
|
|
192 |
return (
|
193 |
<Box key={id} id={id}>
|
194 |
<LeaderboardSection
|
@@ -196,6 +223,7 @@ const LeaderboardPageContent = () => {
|
|
196 |
title={sectionTitle}
|
197 |
leaderboards={data}
|
198 |
filteredLeaderboards={filteredLeaderboards}
|
|
|
199 |
/>
|
200 |
</Box>
|
201 |
);
|
@@ -236,6 +264,7 @@ const LeaderboardPageContent = () => {
|
|
236 |
title={finalTitle}
|
237 |
leaderboards={uniqueData}
|
238 |
filteredLeaderboards={filteredLeaderboards}
|
|
|
239 |
/>
|
240 |
</Box>
|
241 |
);
|
|
|
122 |
>
|
123 |
<LeaderboardFilters allSections={allSections} />
|
124 |
|
125 |
+
{/* Message global "No results" seulement si on n'a pas de résultats, pas de section de recherche, et pas de catégories sélectionnées */}
|
126 |
+
{!hasLeaderboards &&
|
127 |
+
isFiltering &&
|
128 |
+
!isOnlyTextSearch &&
|
129 |
+
selectedCategories.size === 0 && (
|
130 |
+
<Box
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
131 |
sx={{
|
132 |
+
display: "flex",
|
133 |
+
flexDirection: "column",
|
134 |
+
alignItems: "center",
|
135 |
+
gap: 2,
|
136 |
+
mt: 8,
|
137 |
+
py: 7,
|
138 |
}}
|
139 |
+
>
|
140 |
+
<SearchOffIcon
|
141 |
+
sx={{
|
142 |
+
fontSize: 64,
|
143 |
+
color: "text.secondary",
|
144 |
+
opacity: 0.5,
|
145 |
+
}}
|
146 |
+
/>
|
147 |
+
<Typography variant="h5" color="text.secondary" align="center">
|
148 |
+
No results found
|
149 |
+
{searchQuery ? ` matching "${searchQuery}"` : ""}
|
150 |
+
</Typography>
|
151 |
+
<Typography
|
152 |
+
variant="body1"
|
153 |
+
color="text.secondary"
|
154 |
+
align="center"
|
155 |
+
>
|
156 |
+
Try adjusting your filters
|
157 |
+
</Typography>
|
158 |
+
</Box>
|
159 |
+
)}
|
|
|
|
|
|
|
|
|
|
|
160 |
|
161 |
{isOnlyTextSearch ? (
|
162 |
// Vue spéciale pour la recherche textuelle
|
163 |
+
searchResults.length > 0 ? (
|
164 |
+
<Box key="search-results">
|
165 |
+
<LeaderboardSection
|
166 |
+
id="search-results"
|
167 |
+
title={`All leaderboards matching "${searchQuery}"`}
|
168 |
+
leaderboards={allUniqueLeaderboards}
|
169 |
+
filteredLeaderboards={searchResults}
|
170 |
+
/>
|
171 |
+
</Box>
|
172 |
+
) : (
|
173 |
+
// Message d'erreur pour la recherche textuelle sans résultats
|
174 |
+
<Box
|
175 |
+
sx={{
|
176 |
+
display: "flex",
|
177 |
+
flexDirection: "column",
|
178 |
+
alignItems: "center",
|
179 |
+
gap: 2,
|
180 |
+
mt: 8,
|
181 |
+
py: 7,
|
182 |
+
}}
|
183 |
+
>
|
184 |
+
<SearchOffIcon
|
185 |
+
sx={{
|
186 |
+
fontSize: 64,
|
187 |
+
color: "text.secondary",
|
188 |
+
opacity: 0.5,
|
189 |
+
}}
|
190 |
+
/>
|
191 |
+
<Typography variant="h5" color="text.secondary" align="center">
|
192 |
+
No results found
|
193 |
+
{searchQuery ? ` matching "${searchQuery}"` : ""}
|
194 |
+
</Typography>
|
195 |
+
<Typography
|
196 |
+
variant="body1"
|
197 |
+
color="text.secondary"
|
198 |
+
align="center"
|
199 |
+
>
|
200 |
+
Try adjusting your filters
|
201 |
+
</Typography>
|
202 |
+
</Box>
|
203 |
+
)
|
204 |
) : selectedCategories.size > 0 ? (
|
205 |
// Si des catégories sont sélectionnées
|
206 |
selectedCategories.size === 1 ? (
|
|
|
209 |
.filter(({ id }) => selectedCategories.has(id))
|
210 |
.map(({ id, title, data }) => {
|
211 |
const filteredLeaderboards = filterLeaderboards(data);
|
212 |
+
|
213 |
// Ajouter le terme de recherche au titre si présent
|
214 |
const sectionTitle = searchQuery
|
215 |
? `${title} matching "${searchQuery}"`
|
216 |
: title;
|
217 |
+
|
218 |
+
// Toujours afficher la section, même si elle est vide
|
219 |
return (
|
220 |
<Box key={id} id={id}>
|
221 |
<LeaderboardSection
|
|
|
223 |
title={sectionTitle}
|
224 |
leaderboards={data}
|
225 |
filteredLeaderboards={filteredLeaderboards}
|
226 |
+
showEmptyState={true} // Toujours afficher l'état vide sous le header
|
227 |
/>
|
228 |
</Box>
|
229 |
);
|
|
|
264 |
title={finalTitle}
|
265 |
leaderboards={uniqueData}
|
266 |
filteredLeaderboards={filteredLeaderboards}
|
267 |
+
showEmptyState={true} // Toujours afficher l'état vide sous le header
|
268 |
/>
|
269 |
</Box>
|
270 |
);
|