@capytale/meta-player 0.9.11 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (110) hide show
  1. package/.prettierrc.json +4 -4
  2. package/LICENSE +674 -674
  3. package/README.md +12 -12
  4. package/eslint.config.js +28 -28
  5. package/index.html +15 -15
  6. package/package.json +60 -60
  7. package/public/themes/lara-dark-blue/theme.css +7015 -7015
  8. package/public/themes/lara-light-blue/theme.css +7005 -7005
  9. package/src/App.tsx +145 -140
  10. package/src/AppRedux.css +39 -39
  11. package/src/MetaPlayer.tsx +168 -168
  12. package/src/activityJs.ts +7 -7
  13. package/src/app/createAppSlice.ts +6 -6
  14. package/src/app/hooks.ts +12 -12
  15. package/src/app/store.ts +52 -52
  16. package/src/app.module.scss +80 -80
  17. package/src/demo.tsx +87 -87
  18. package/src/external/prime.ts +5 -5
  19. package/src/features/activityData/ExitWarning.ts +28 -28
  20. package/src/features/activityData/IsAntiCheatExitDetectionDisabledSetter.tsx +19 -19
  21. package/src/features/activityData/IsDirtySetter.tsx +17 -17
  22. package/src/features/activityData/MetaPlayerOptionsSetter.tsx +41 -41
  23. package/src/features/activityData/activityDataSlice.ts +255 -255
  24. package/src/features/activityData/activityJsData.ts +90 -90
  25. package/src/features/activityData/hooks.ts +39 -39
  26. package/src/features/activityData/metaPlayerOptions.ts +23 -23
  27. package/src/features/activityData/uiState.ts +20 -20
  28. package/src/features/activityJS/ActivityJSProvider.tsx +362 -350
  29. package/src/features/activityJS/AfterResetAction.tsx +23 -23
  30. package/src/features/activityJS/AfterSaveAction.tsx +23 -23
  31. package/src/features/activityJS/BeforeResetAction.tsx +23 -23
  32. package/src/features/activityJS/BeforeSaveAction.tsx +23 -23
  33. package/src/features/activityJS/Saver.tsx +167 -167
  34. package/src/features/activityJS/hooks.ts +85 -85
  35. package/src/features/activityJS/internal-hooks.ts +96 -96
  36. package/src/features/activityJS/saverSlice.ts +96 -96
  37. package/src/features/activitySettings/ActivitySettingsSetter.tsx +21 -21
  38. package/src/features/activitySettings/hooks.ts +12 -12
  39. package/src/features/activitySettings/index.tsx +43 -43
  40. package/src/features/activitySettings/store.ts +108 -108
  41. package/src/features/activitySettings/style.module.scss +8 -8
  42. package/src/features/activitySettings/types.ts +140 -140
  43. package/src/features/activitySettings/ui.tsx +299 -299
  44. package/src/features/functionalities/AttachedFilesFunctionality.ts +23 -23
  45. package/src/features/functionalities/PreviewDialog.tsx +83 -83
  46. package/src/features/functionalities/functionalitiesSlice.ts +98 -98
  47. package/src/features/functionalities/hooks.ts +70 -70
  48. package/src/features/layout/hooks.ts +7 -7
  49. package/src/features/layout/layoutSlice.ts +93 -93
  50. package/src/features/navbar/activity-info/index.tsx +54 -54
  51. package/src/features/navbar/activity-info/style.module.scss +38 -38
  52. package/src/features/navbar/activity-menu/ActivityQuickActions.tsx +89 -57
  53. package/src/features/navbar/activity-menu/index.tsx +154 -154
  54. package/src/features/navbar/activity-menu/style.module.scss +7 -7
  55. package/src/features/navbar/capytale-menu/CloneDialog.tsx +75 -75
  56. package/src/features/navbar/capytale-menu/Countdown.tsx +313 -313
  57. package/src/features/navbar/capytale-menu/CountdownAndSaveButton.tsx +129 -125
  58. package/src/features/navbar/capytale-menu/index.tsx +260 -260
  59. package/src/features/navbar/capytale-menu/style.module.scss +8 -8
  60. package/src/features/navbar/capytale-menu/useRemainingTimeMs.tsx +32 -32
  61. package/src/features/navbar/index.tsx +39 -39
  62. package/src/features/navbar/navbarSlice.ts +79 -79
  63. package/src/features/navbar/preview-navbar/index.tsx +18 -0
  64. package/src/features/navbar/preview-navbar/style.module.scss +17 -0
  65. package/src/features/navbar/review-navbar/GradingNav.tsx +128 -128
  66. package/src/features/navbar/review-navbar/index.tsx +18 -18
  67. package/src/features/navbar/review-navbar/style.module.scss +22 -22
  68. package/src/features/navbar/sidebars/ActivitySidebarActions.tsx +57 -57
  69. package/src/features/navbar/sidebars/AttachedFilesSidebarContent.module.scss +43 -43
  70. package/src/features/navbar/sidebars/AttachedFilesSidebarContent.tsx +181 -181
  71. package/src/features/navbar/sidebars/SettingsSidebarContent.tsx +192 -192
  72. package/src/features/navbar/sidebars/style.module.scss +15 -15
  73. package/src/features/navbar/student-utils.ts +11 -11
  74. package/src/features/navbar/style.module.scss +65 -65
  75. package/src/features/pedago/InstructionsEditor.tsx +104 -102
  76. package/src/features/pedago/PdfEditor.tsx +91 -91
  77. package/src/features/pedago/PedagoCommands.tsx +378 -378
  78. package/src/features/pedago/SharedNotesEditor.tsx +144 -144
  79. package/src/features/pedago/hooks.ts +108 -108
  80. package/src/features/pedago/index.tsx +205 -205
  81. package/src/features/pedago/style.module.scss +233 -233
  82. package/src/features/theming/ThemeSwitcher.tsx +51 -51
  83. package/src/features/theming/hooks.ts +6 -6
  84. package/src/features/theming/themingSlice.ts +93 -93
  85. package/src/features/toast.tsx +38 -38
  86. package/src/hooks/index.ts +55 -16
  87. package/src/index.css +132 -132
  88. package/src/index.ts +93 -92
  89. package/src/logo.svg +1 -1
  90. package/src/my_json_data.js +4146 -4146
  91. package/src/settings.ts +6 -6
  92. package/src/types.ts +8 -8
  93. package/src/utils/ButtonDoubleIcon.tsx +35 -35
  94. package/src/utils/CardSelector.tsx +41 -41
  95. package/src/utils/ErrorBoundary.tsx +41 -41
  96. package/src/utils/PopupButton.tsx +134 -134
  97. package/src/utils/activity.ts +8 -8
  98. package/src/utils/breakpoints.ts +4 -4
  99. package/src/utils/capytale.ts +10 -10
  100. package/src/utils/clipboard.ts +11 -11
  101. package/src/utils/download.ts +7 -7
  102. package/src/utils/equality.ts +32 -32
  103. package/src/utils/server-clock.ts +42 -42
  104. package/src/utils/style.module.scss +45 -45
  105. package/src/utils/useFullscreen.ts +65 -65
  106. package/src/vite-env.d.ts +1 -1
  107. package/src/zustandStore.ts +66 -0
  108. package/tsconfig.json +28 -28
  109. package/tsconfig.node.json +9 -9
  110. package/vite.config.ts +11 -11
@@ -1,313 +1,313 @@
1
- import {
2
- FC,
3
- ReactNode,
4
- useCallback,
5
- useEffect,
6
- useMemo,
7
- useRef,
8
- } from "react";
9
- import { Toast } from "primereact/toast";
10
- import { useActivityJS } from "../../activityJS/ActivityJSProvider";
11
- import { useAppSelector } from "../../../app/hooks";
12
- import {
13
- selectIsDirty,
14
- selectMode,
15
- } from "../../activityData/activityDataSlice";
16
- import { Button } from "primereact/button";
17
- import { useSave } from "../../activityData/hooks";
18
- import { selectShowSaveForStudents } from "../../layout/layoutSlice";
19
- import useRemainingTimeMs from "./useRemainingTimeMs";
20
-
21
- // TODO use https://capytale2.ac-paris.fr/vanilla/time-s.php
22
- // https://forge.apps.education.fr/capytale/activity-js/-/blob/main/src/backend/capytale/clock.ts?ref_type=heads
23
- // https://forge.apps.education.fr/capytale/activity-js/-/blob/main/src/api/time/clock.ts?ref_type=heads
24
-
25
- const MS_PER_MINUTE = 1000 * 60;
26
- const MS_PER_DAY = MS_PER_MINUTE * 60 * 24;
27
- const MS_PER_YEAR = MS_PER_DAY * 365;
28
-
29
- const Countdown: FC = () => {
30
- const toast = useRef<Toast>(null); // Using its own toast because it may clear it
31
- const mode = useAppSelector(selectMode);
32
- const isDirty = useAppSelector(selectIsDirty);
33
- const showSaveForStudents = useAppSelector(selectShowSaveForStudents);
34
- const showWarningsBecauseNoSave = useMemo(
35
- () => mode === "assignment" && !showSaveForStudents,
36
- [mode, showSaveForStudents],
37
- );
38
- const oneMinuteWarningShown = useRef(false);
39
- const fifteenSecondsWarningShown = useRef(false);
40
- const shouldSaveAt30s = useRef(true);
41
- const save30sAttempted = useRef(false);
42
- const zeroSecondsWarningShown = useRef(false);
43
- const save = useSave();
44
-
45
- const showOneMinuteWarning = useCallback(() => {
46
- oneMinuteWarningShown.current = true;
47
- toast.current?.show({
48
- severity: "warn",
49
- summary: showWarningsBecauseNoSave
50
- ? "Temps presque écoulé"
51
- : "Activité non sauvegardée",
52
- detail: (
53
- <>
54
- <div>
55
- {showWarningsBecauseNoSave ? (
56
- <>Il vous reste moins d'une minute pour vérifier vos réponses.</>
57
- ) : (
58
- <>
59
- Il vous reste moins d'une minute pour enregistrer votre
60
- activité. Elle sera sauvegardée automatiquement 30 secondes
61
- avant la fin.
62
- </>
63
- )}
64
- </div>
65
- {!showWarningsBecauseNoSave && (
66
- <div
67
- style={{
68
- display: "flex",
69
- flexDirection: "column",
70
- gap: "8px",
71
- marginTop: "8px",
72
- alignItems: "stretch",
73
- }}
74
- >
75
- <Button
76
- severity="danger"
77
- onClick={() => {
78
- shouldSaveAt30s.current = false;
79
- toast.current?.clear();
80
- }}
81
- >
82
- Ne pas sauvegarder (danger)
83
- </Button>
84
- <Button severity="success" onClick={save}>
85
- Sauvegarder maintenant
86
- </Button>
87
- </div>
88
- )}
89
- </>
90
- ),
91
- sticky: true,
92
- closable: false,
93
- });
94
- }, [save, showWarningsBecauseNoSave]);
95
-
96
- const showFifteenSecondsWarning = useCallback(() => {
97
- fifteenSecondsWarningShown.current = true;
98
- toast.current?.show({
99
- severity: "error",
100
- summary: showWarningsBecauseNoSave
101
- ? "Temps presque écoulé"
102
- : "Activité non sauvegardée",
103
- detail: (
104
- <>
105
- <div>
106
- {showWarningsBecauseNoSave ? (
107
- <>
108
- Il vous reste moins de 15 secondes pour vérifier vos réponses.
109
- </>
110
- ) : (
111
- <>
112
- Il vous reste moins de 15 secondes pour enregistrer votre
113
- activité.
114
- </>
115
- )}
116
- </div>
117
- {!showWarningsBecauseNoSave && (
118
- <div
119
- style={{
120
- display: "flex",
121
- flexDirection: "column",
122
- gap: "8px",
123
- marginTop: "8px",
124
- alignItems: "stretch",
125
- }}
126
- >
127
- <Button
128
- severity="danger"
129
- onClick={() => {
130
- save();
131
- toast.current?.clear();
132
- }}
133
- >
134
- Sauvegarder maintenant
135
- </Button>
136
- </div>
137
- )}
138
- </>
139
- ),
140
- sticky: true,
141
- });
142
- }, [save, showWarningsBecauseNoSave]);
143
-
144
- const activityJS = useActivityJS();
145
- const deadlineMode =
146
- activityJS.activitySession?.activityBunch.access_tr_mode.value;
147
- const deadline =
148
- !deadlineMode || deadlineMode === "none"
149
- ? null
150
- : activityJS.activitySession?.activityBunch.access_timerange.value?.end;
151
-
152
- const diffMs = useRemainingTimeMs();
153
-
154
- useEffect(() => {
155
- if (!diffMs || mode !== "assignment") {
156
- return;
157
- }
158
- if (
159
- diffMs != null &&
160
- diffMs < MS_PER_MINUTE &&
161
- diffMs > 35000 &&
162
- (isDirty || showWarningsBecauseNoSave) &&
163
- !oneMinuteWarningShown.current
164
- ) {
165
- showOneMinuteWarning();
166
- }
167
- if (
168
- diffMs != null &&
169
- diffMs < 30000 &&
170
- diffMs > 0 &&
171
- shouldSaveAt30s.current &&
172
- !save30sAttempted.current
173
- ) {
174
- if (isDirty) {
175
- save();
176
- }
177
- toast.current?.clear();
178
- save30sAttempted.current = true;
179
- }
180
- if (
181
- (isDirty || showWarningsBecauseNoSave) &&
182
- diffMs != null &&
183
- diffMs < 15000 &&
184
- diffMs > 0 &&
185
- !fifteenSecondsWarningShown.current
186
- ) {
187
- showFifteenSecondsWarning();
188
- }
189
- if (diffMs <= 0 && !zeroSecondsWarningShown.current) {
190
- zeroSecondsWarningShown.current = true;
191
- toast.current?.clear();
192
- setTimeout(() => {
193
- toast.current?.show({
194
- severity: "info",
195
- summary: "Temps écoulé",
196
- detail: "Le temps est écoulé, il n'est plus possible de sauvegarder.",
197
- sticky: true,
198
- });
199
- }, 500);
200
- }
201
- }, [diffMs, mode, isDirty, showWarningsBecauseNoSave]);
202
-
203
- const displayed = useMemo<ReactNode>(() => {
204
- if (!deadline || diffMs == null) {
205
- return null;
206
- }
207
- if (diffMs >= MS_PER_DAY) {
208
- return (
209
- <div
210
- aria-label="Deadline"
211
- style={{
212
- display: "flex",
213
- alignItems: "center",
214
- gap: "8px",
215
- marginRight: "8px",
216
- }}
217
- >
218
- <i className="pi pi-calendar-clock" />
219
- <div
220
- style={{
221
- display: "flex",
222
- flexDirection: "column",
223
- alignItems: "center",
224
- }}
225
- >
226
- {deadline
227
- .toLocaleString("fr-FR", {
228
- year: diffMs >= MS_PER_YEAR ? "numeric" : undefined,
229
- month: "short",
230
- day: "numeric",
231
- hour: "numeric",
232
- minute: "numeric",
233
- })
234
- .split(", ")
235
- .map((s, i) => (
236
- <div
237
- key={i}
238
- aria-label={i === 0 ? "Date limite" : "Heure limite"}
239
- >
240
- {s}
241
- </div>
242
- ))}
243
- </div>
244
- </div>
245
- );
246
- }
247
- if (diffMs <= 0) {
248
- return (
249
- <div
250
- aria-label="Temps écoulé"
251
- style={{
252
- display: "flex",
253
- alignItems: "center",
254
- gap: "8px",
255
- marginRight: "8px",
256
- background: "#ef4444",
257
- borderRadius: "100px",
258
- padding: "5px 10px",
259
- fontWeight: "bold",
260
- }}
261
- >
262
- <i className="pi pi-calendar-times" />
263
- <span>Temps écoulé</span>
264
- </div>
265
- );
266
- }
267
- const diffSeconds = Math.floor(diffMs / 1000);
268
- const seconds = diffSeconds % 60;
269
- const minutes = Math.floor(diffSeconds / 60) % 60;
270
- const hours = Math.floor(diffSeconds / 3600) % 24;
271
- return (
272
- <div
273
- aria-label="Temps restant"
274
- style={{
275
- display: "flex",
276
- alignItems: "center",
277
- gap: "8px",
278
- marginRight: "8px",
279
- ...(hours === 0 && minutes < 5
280
- ? {
281
- background: "#ef4444",
282
- borderRadius: "100px",
283
- padding: "5px 10px",
284
- fontWeight: "bold",
285
- }
286
- : {}),
287
- }}
288
- >
289
- <i className="pi pi-hourglass" />
290
- {`${hours.toString().padStart(2, "0")}:${minutes
291
- .toString()
292
- .padStart(2, "0")}:${seconds.toString().padStart(2, "0")}`}
293
- </div>
294
- );
295
- }, [deadline, diffMs]);
296
-
297
- if (!deadline) {
298
- return null;
299
- }
300
-
301
- return (
302
- <div
303
- style={{
304
- userSelect: "none",
305
- }}
306
- >
307
- {displayed}
308
- <Toast position="bottom-right" ref={toast} />
309
- </div>
310
- );
311
- };
312
-
313
- export default Countdown;
1
+ import {
2
+ FC,
3
+ ReactNode,
4
+ useCallback,
5
+ useEffect,
6
+ useMemo,
7
+ useRef,
8
+ } from "react";
9
+ import { Toast } from "primereact/toast";
10
+ import { useActivityJS } from "../../activityJS/ActivityJSProvider";
11
+ import { useAppSelector } from "../../../app/hooks";
12
+ import {
13
+ selectIsDirty,
14
+ selectMode,
15
+ } from "../../activityData/activityDataSlice";
16
+ import { Button } from "primereact/button";
17
+ import { useSave } from "../../activityData/hooks";
18
+ import { selectShowSaveForStudents } from "../../layout/layoutSlice";
19
+ import useRemainingTimeMs from "./useRemainingTimeMs";
20
+
21
+ // TODO use https://capytale2.ac-paris.fr/vanilla/time-s.php
22
+ // https://forge.apps.education.fr/capytale/activity-js/-/blob/main/src/backend/capytale/clock.ts?ref_type=heads
23
+ // https://forge.apps.education.fr/capytale/activity-js/-/blob/main/src/api/time/clock.ts?ref_type=heads
24
+
25
+ const MS_PER_MINUTE = 1000 * 60;
26
+ const MS_PER_DAY = MS_PER_MINUTE * 60 * 24;
27
+ const MS_PER_YEAR = MS_PER_DAY * 365;
28
+
29
+ const Countdown: FC = () => {
30
+ const toast = useRef<Toast>(null); // Using its own toast because it may clear it
31
+ const mode = useAppSelector(selectMode);
32
+ const isDirty = useAppSelector(selectIsDirty);
33
+ const showSaveForStudents = useAppSelector(selectShowSaveForStudents);
34
+ const showWarningsBecauseNoSave = useMemo(
35
+ () => mode === "assignment" && !showSaveForStudents,
36
+ [mode, showSaveForStudents],
37
+ );
38
+ const oneMinuteWarningShown = useRef(false);
39
+ const fifteenSecondsWarningShown = useRef(false);
40
+ const shouldSaveAt30s = useRef(true);
41
+ const save30sAttempted = useRef(false);
42
+ const zeroSecondsWarningShown = useRef(false);
43
+ const save = useSave();
44
+
45
+ const showOneMinuteWarning = useCallback(() => {
46
+ oneMinuteWarningShown.current = true;
47
+ toast.current?.show({
48
+ severity: "warn",
49
+ summary: showWarningsBecauseNoSave
50
+ ? "Temps presque écoulé"
51
+ : "Activité non sauvegardée",
52
+ detail: (
53
+ <>
54
+ <div>
55
+ {showWarningsBecauseNoSave ? (
56
+ <>Il vous reste moins d'une minute pour vérifier vos réponses.</>
57
+ ) : (
58
+ <>
59
+ Il vous reste moins d'une minute pour enregistrer votre
60
+ activité. Elle sera sauvegardée automatiquement 30 secondes
61
+ avant la fin.
62
+ </>
63
+ )}
64
+ </div>
65
+ {!showWarningsBecauseNoSave && (
66
+ <div
67
+ style={{
68
+ display: "flex",
69
+ flexDirection: "column",
70
+ gap: "8px",
71
+ marginTop: "8px",
72
+ alignItems: "stretch",
73
+ }}
74
+ >
75
+ <Button
76
+ severity="danger"
77
+ onClick={() => {
78
+ shouldSaveAt30s.current = false;
79
+ toast.current?.clear();
80
+ }}
81
+ >
82
+ Ne pas sauvegarder (danger)
83
+ </Button>
84
+ <Button severity="success" onClick={save}>
85
+ Sauvegarder maintenant
86
+ </Button>
87
+ </div>
88
+ )}
89
+ </>
90
+ ),
91
+ sticky: true,
92
+ closable: false,
93
+ });
94
+ }, [save, showWarningsBecauseNoSave]);
95
+
96
+ const showFifteenSecondsWarning = useCallback(() => {
97
+ fifteenSecondsWarningShown.current = true;
98
+ toast.current?.show({
99
+ severity: "error",
100
+ summary: showWarningsBecauseNoSave
101
+ ? "Temps presque écoulé"
102
+ : "Activité non sauvegardée",
103
+ detail: (
104
+ <>
105
+ <div>
106
+ {showWarningsBecauseNoSave ? (
107
+ <>
108
+ Il vous reste moins de 15 secondes pour vérifier vos réponses.
109
+ </>
110
+ ) : (
111
+ <>
112
+ Il vous reste moins de 15 secondes pour enregistrer votre
113
+ activité.
114
+ </>
115
+ )}
116
+ </div>
117
+ {!showWarningsBecauseNoSave && (
118
+ <div
119
+ style={{
120
+ display: "flex",
121
+ flexDirection: "column",
122
+ gap: "8px",
123
+ marginTop: "8px",
124
+ alignItems: "stretch",
125
+ }}
126
+ >
127
+ <Button
128
+ severity="danger"
129
+ onClick={() => {
130
+ save();
131
+ toast.current?.clear();
132
+ }}
133
+ >
134
+ Sauvegarder maintenant
135
+ </Button>
136
+ </div>
137
+ )}
138
+ </>
139
+ ),
140
+ sticky: true,
141
+ });
142
+ }, [save, showWarningsBecauseNoSave]);
143
+
144
+ const activityJS = useActivityJS();
145
+ const deadlineMode =
146
+ activityJS.activitySession?.activityBunch.access_tr_mode.value;
147
+ const deadline =
148
+ !deadlineMode || deadlineMode === "none"
149
+ ? null
150
+ : activityJS.activitySession?.activityBunch.access_timerange.value?.end;
151
+
152
+ const diffMs = useRemainingTimeMs();
153
+
154
+ useEffect(() => {
155
+ if (!diffMs || mode !== "assignment") {
156
+ return;
157
+ }
158
+ if (
159
+ diffMs != null &&
160
+ diffMs < MS_PER_MINUTE &&
161
+ diffMs > 35000 &&
162
+ (isDirty || showWarningsBecauseNoSave) &&
163
+ !oneMinuteWarningShown.current
164
+ ) {
165
+ showOneMinuteWarning();
166
+ }
167
+ if (
168
+ diffMs != null &&
169
+ diffMs < 30000 &&
170
+ diffMs > 0 &&
171
+ shouldSaveAt30s.current &&
172
+ !save30sAttempted.current
173
+ ) {
174
+ if (isDirty) {
175
+ save();
176
+ }
177
+ toast.current?.clear();
178
+ save30sAttempted.current = true;
179
+ }
180
+ if (
181
+ (isDirty || showWarningsBecauseNoSave) &&
182
+ diffMs != null &&
183
+ diffMs < 15000 &&
184
+ diffMs > 0 &&
185
+ !fifteenSecondsWarningShown.current
186
+ ) {
187
+ showFifteenSecondsWarning();
188
+ }
189
+ if (diffMs <= 0 && !zeroSecondsWarningShown.current) {
190
+ zeroSecondsWarningShown.current = true;
191
+ toast.current?.clear();
192
+ setTimeout(() => {
193
+ toast.current?.show({
194
+ severity: "info",
195
+ summary: "Temps écoulé",
196
+ detail: "Le temps est écoulé, il n'est plus possible de sauvegarder.",
197
+ sticky: true,
198
+ });
199
+ }, 500);
200
+ }
201
+ }, [diffMs, mode, isDirty, showWarningsBecauseNoSave]);
202
+
203
+ const displayed = useMemo<ReactNode>(() => {
204
+ if (!deadline || diffMs == null) {
205
+ return null;
206
+ }
207
+ if (diffMs >= MS_PER_DAY) {
208
+ return (
209
+ <div
210
+ aria-label="Deadline"
211
+ style={{
212
+ display: "flex",
213
+ alignItems: "center",
214
+ gap: "8px",
215
+ marginRight: "8px",
216
+ }}
217
+ >
218
+ <i className="pi pi-calendar-clock" />
219
+ <div
220
+ style={{
221
+ display: "flex",
222
+ flexDirection: "column",
223
+ alignItems: "center",
224
+ }}
225
+ >
226
+ {deadline
227
+ .toLocaleString("fr-FR", {
228
+ year: diffMs >= MS_PER_YEAR ? "numeric" : undefined,
229
+ month: "short",
230
+ day: "numeric",
231
+ hour: "numeric",
232
+ minute: "numeric",
233
+ })
234
+ .split(", ")
235
+ .map((s, i) => (
236
+ <div
237
+ key={i}
238
+ aria-label={i === 0 ? "Date limite" : "Heure limite"}
239
+ >
240
+ {s}
241
+ </div>
242
+ ))}
243
+ </div>
244
+ </div>
245
+ );
246
+ }
247
+ if (diffMs <= 0) {
248
+ return (
249
+ <div
250
+ aria-label="Temps écoulé"
251
+ style={{
252
+ display: "flex",
253
+ alignItems: "center",
254
+ gap: "8px",
255
+ marginRight: "8px",
256
+ background: "#ef4444",
257
+ borderRadius: "100px",
258
+ padding: "5px 10px",
259
+ fontWeight: "bold",
260
+ }}
261
+ >
262
+ <i className="pi pi-calendar-times" />
263
+ <span>Temps écoulé</span>
264
+ </div>
265
+ );
266
+ }
267
+ const diffSeconds = Math.floor(diffMs / 1000);
268
+ const seconds = diffSeconds % 60;
269
+ const minutes = Math.floor(diffSeconds / 60) % 60;
270
+ const hours = Math.floor(diffSeconds / 3600) % 24;
271
+ return (
272
+ <div
273
+ aria-label="Temps restant"
274
+ style={{
275
+ display: "flex",
276
+ alignItems: "center",
277
+ gap: "8px",
278
+ marginRight: "8px",
279
+ ...(hours === 0 && minutes < 5
280
+ ? {
281
+ background: "#ef4444",
282
+ borderRadius: "100px",
283
+ padding: "5px 10px",
284
+ fontWeight: "bold",
285
+ }
286
+ : {}),
287
+ }}
288
+ >
289
+ <i className="pi pi-hourglass" />
290
+ {`${hours.toString().padStart(2, "0")}:${minutes
291
+ .toString()
292
+ .padStart(2, "0")}:${seconds.toString().padStart(2, "0")}`}
293
+ </div>
294
+ );
295
+ }, [deadline, diffMs]);
296
+
297
+ if (!deadline) {
298
+ return null;
299
+ }
300
+
301
+ return (
302
+ <div
303
+ style={{
304
+ userSelect: "none",
305
+ }}
306
+ >
307
+ {displayed}
308
+ <Toast position="bottom-right" ref={toast} />
309
+ </div>
310
+ );
311
+ };
312
+
313
+ export default Countdown;