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