Skip to content

Commit 1e38465

Browse files
fix weekdays
1 parent 1a04684 commit 1e38465

File tree

1 file changed

+41
-7
lines changed

1 file changed

+41
-7
lines changed

packages/client/src/pages/DashboardPage.tsx

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,37 @@ import { weatherQueryOptions, roomQueryOptions } from "../api/queryOptions";
1313
const DashboardTestPage = () => {
1414
const navigate = useNavigate();
1515

16+
// Récupère les données météo via React Query
1617
const { data: weatherResponse } = useQuery(
1718
weatherQueryOptions.weeklyWeather()
1819
);
1920

21+
// Récupère les données des salles via React Query
2022
const { data: roomsResponse } = useQuery(roomQueryOptions.rooms());
2123

22-
console.log(roomsResponse);
23-
24+
// Prépare un tableau des 5 jours de la semaine avec les données météo
2425
const getWeekdayWeather = () => {
2526
if (!weatherResponse?.data) return [];
2627

2728
const today = new Date();
2829
const weekdays = [];
2930

31+
// Calcul du lundi de la semaine actuelle ou suivante si weekend
3032
const monday = new Date(today);
3133
const dayOfWeek = today.getDay();
32-
const daysToMonday = dayOfWeek === 0 ? -6 : 1 - dayOfWeek;
34+
35+
let daysToMonday;
36+
if (dayOfWeek === 0) {
37+
daysToMonday = 1;
38+
} else if (dayOfWeek === 6) {
39+
daysToMonday = 2;
40+
} else {
41+
daysToMonday = 1 - dayOfWeek;
42+
}
43+
3344
monday.setDate(today.getDate() + daysToMonday);
3445

46+
// Boucle pour récupérer les données météo de chaque jour
3547
for (let i = 0; i < 5; i++) {
3648
const currentDay = new Date(monday);
3749
currentDay.setDate(monday.getDate() + i);
@@ -43,6 +55,7 @@ const DashboardTestPage = () => {
4355
if (weatherData) {
4456
weekdays.push({
4557
...weatherData,
58+
// Génère le nom du jour en français, première lettre en majuscule
4659
dayName:
4760
currentDay
4861
.toLocaleDateString("fr-FR", { weekday: "short" })
@@ -62,6 +75,7 @@ const DashboardTestPage = () => {
6275

6376
return (
6477
<div className="flex flex-col p-8 max-w-7xl mx-auto">
78+
{/* Section Salles Actives & Température Moyenne */}
6579
<div className="flex gap-6 mb-8">
6680
<Card className="max-w-auto w-full flex items-center">
6781
<div className="flex justify-between items-center">
@@ -94,17 +108,18 @@ const DashboardTestPage = () => {
94108
<p className="text-2xl font-extrabold text-gray-800">
95109
{roomsResponse?.data
96110
? (() => {
111+
// Filtre les salles avec température valide
97112
const roomsWithTemp =
98113
roomsResponse.data.filter(
99114
(room) =>
100115
room.temperature !==
101116
null &&
102-
room.temperature !== 0 &&
103-
room.temperature > 0
117+
room.temperature !== 0
104118
);
105119
if (roomsWithTemp.length === 0) {
106120
return "--°C";
107121
}
122+
// Calcul de la moyenne
108123
const sum = roomsWithTemp.reduce(
109124
(acc, room) =>
110125
acc + room.temperature!,
@@ -122,11 +137,13 @@ const DashboardTestPage = () => {
122137
<img
123138
className="w-12 h-12"
124139
src={temp}
125-
alt="Icône salle active"
140+
alt="Icône température"
126141
/>
127142
</div>
128143
</Card>
129144
</div>
145+
146+
{/* Section Météo & Planning */}
130147
<div className="flex gap-6 mb-8 w-full">
131148
<Card className="w-[830px]" title="Météo de la semaine">
132149
{weatherResponse ? (
@@ -136,9 +153,11 @@ const DashboardTestPage = () => {
136153
key={weather.date}
137154
className="flex flex-col items-center flex-1 px-3 py-8 bg-gray-50 rounded-lg"
138155
>
156+
{/* Jour */}
139157
<div className="text-sm font-semibold text-gray-700 mb-2">
140158
{weather.dayName}
141159
</div>
160+
{/* Date */}
142161
<div className="text-xs text-gray-500 mb-2">
143162
{new Date(
144163
weather.date
@@ -147,6 +166,7 @@ const DashboardTestPage = () => {
147166
month: "short",
148167
})}
149168
</div>
169+
{/* Icône météo */}
150170
<div className="text-2xl mb-1">
151171
{weather.condition === "clear" && "☀️"}
152172
{weather.condition ===
@@ -162,6 +182,7 @@ const DashboardTestPage = () => {
162182
"snowy",
163183
].includes(weather.condition) && "🌤️"}
164184
</div>
185+
{/* Température Max/Min */}
165186
<div className="text-center">
166187
<div className="text-lg font-bold text-gray-800">
167188
{weather.temperatureMax}°
@@ -186,7 +207,10 @@ const DashboardTestPage = () => {
186207
</div>
187208
)}
188209
</Card>
210+
211+
{/* Carte Planning */}
189212
<Card className="flex-1" title="Planning">
213+
{/* Salles indisponibles */}
190214
<div className="bg-lightRed border-2 border-red flex flex-col justify-center items-center p-3 rounded-lg">
191215
<span className="text-sm font-semibold text-red">
192216
{roomsResponse?.data
@@ -209,16 +233,18 @@ const DashboardTestPage = () => {
209233

210234
<span className="text-xs text-red">9:00 - 17:00</span>
211235
</div>
236+
237+
{/* Salle disponible */}
212238
<div className="bg-lightGreen border-2 border-greenBorder flex flex-col justify-center items-center p-3 rounded-lg my-4">
213239
<span className="text-sm font-semibold text-greenText">
214240
Disponible
215241
</span>
216-
217242
<span className="text-xs text-greenText">
218243
9:00 - 17:00
219244
</span>
220245
</div>
221246

247+
{/* Bouton planning */}
222248
<Button
223249
className="w-full flex justify-center"
224250
onClick={() => navigate("/planning")}
@@ -228,11 +254,15 @@ const DashboardTestPage = () => {
228254
</Button>
229255
</Card>
230256
</div>
257+
258+
{/* Section Aperçu des salles & Actions rapides */}
231259
<div className="flex gap-6 mb-8">
260+
{/* Aperçu des salles */}
232261
<Card
233262
className="w-[830px] relative"
234263
title="Aperçu de l'état des classes"
235264
>
265+
{/* Bouton "Voir tout" */}
236266
<button
237267
onClick={() => {
238268
navigate("/salles");
@@ -252,6 +282,7 @@ const DashboardTestPage = () => {
252282
key={room.id}
253283
className="min-w-80 w-full bg-white border border-gray-200 rounded-lg p-6"
254284
>
285+
{/* En-tête salle */}
255286
<div className="flex justify-between items-start mb-4">
256287
<h3 className="text-lg font-semibold text-gray-800">
257288
{room.name}
@@ -274,6 +305,7 @@ const DashboardTestPage = () => {
274305
"Inactif"}
275306
</span>
276307
</div>
308+
{/* Infos salle */}
277309
<div className="space-y-3">
278310
<div className="flex justify-between items-center text-sm text-gray-600">
279311
<span>Température :</span>
@@ -311,6 +343,8 @@ const DashboardTestPage = () => {
311343
</div>
312344
)}
313345
</Card>
346+
347+
{/* Actions rapides */}
314348
<Card className="w-full max-w-96" title="Actions rapides">
315349
<div className="flex items-center gap-4 mb-6 mt-8">
316350
<img

0 commit comments

Comments
 (0)