@capytale/meta-player 0.7.0 → 0.7.2
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 +305 -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 +154 -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 +32 -32
- package/src/features/activitySettings/store.ts +108 -105
- package/src/features/activitySettings/style.module.scss +5 -5
- package/src/features/activitySettings/types.ts +138 -138
- package/src/features/activitySettings/ui.tsx +295 -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 +272 -272
- package/src/features/navbar/capytale-menu/CountdownAndSaveButton.tsx +115 -115
- package/src/features/navbar/capytale-menu/index.tsx +256 -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 +124 -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 +350 -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,23 +1,23 @@
|
|
|
1
|
-
import { FC, useEffect } from "react";
|
|
2
|
-
import {
|
|
3
|
-
SaveCallback,
|
|
4
|
-
addAfterSave,
|
|
5
|
-
removeAfterSave,
|
|
6
|
-
} from "./saverSlice";
|
|
7
|
-
import { useAppDispatch } from "../../app/hooks";
|
|
8
|
-
|
|
9
|
-
type AfterSaveActionProps = SaveCallback;
|
|
10
|
-
|
|
11
|
-
const AfterSaveAction: FC<AfterSaveActionProps> = (props) => {
|
|
12
|
-
const dispatch = useAppDispatch();
|
|
13
|
-
useEffect(() => {
|
|
14
|
-
dispatch(addAfterSave(props));
|
|
15
|
-
return () => {
|
|
16
|
-
// Remove the callback when the component is unmounted
|
|
17
|
-
dispatch(removeAfterSave(props.name));
|
|
18
|
-
};
|
|
19
|
-
}, [props]);
|
|
20
|
-
return null;
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
export default AfterSaveAction;
|
|
1
|
+
import { FC, useEffect } from "react";
|
|
2
|
+
import {
|
|
3
|
+
SaveCallback,
|
|
4
|
+
addAfterSave,
|
|
5
|
+
removeAfterSave,
|
|
6
|
+
} from "./saverSlice";
|
|
7
|
+
import { useAppDispatch } from "../../app/hooks";
|
|
8
|
+
|
|
9
|
+
type AfterSaveActionProps = SaveCallback;
|
|
10
|
+
|
|
11
|
+
const AfterSaveAction: FC<AfterSaveActionProps> = (props) => {
|
|
12
|
+
const dispatch = useAppDispatch();
|
|
13
|
+
useEffect(() => {
|
|
14
|
+
dispatch(addAfterSave(props));
|
|
15
|
+
return () => {
|
|
16
|
+
// Remove the callback when the component is unmounted
|
|
17
|
+
dispatch(removeAfterSave(props.name));
|
|
18
|
+
};
|
|
19
|
+
}, [props]);
|
|
20
|
+
return null;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export default AfterSaveAction;
|
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
import { FC, useEffect } from "react";
|
|
2
|
-
import {
|
|
3
|
-
SaveCallback,
|
|
4
|
-
addBeforeReset,
|
|
5
|
-
removeBeforeReset,
|
|
6
|
-
} from "./saverSlice";
|
|
7
|
-
import { useAppDispatch } from "../../app/hooks";
|
|
8
|
-
|
|
9
|
-
type BeforeResetActionProps = SaveCallback;
|
|
10
|
-
|
|
11
|
-
const BeforeResetAction: FC<BeforeResetActionProps> = (props) => {
|
|
12
|
-
const dispatch = useAppDispatch();
|
|
13
|
-
useEffect(() => {
|
|
14
|
-
dispatch(addBeforeReset(props));
|
|
15
|
-
return () => {
|
|
16
|
-
// Remove the callback when the component is unmounted
|
|
17
|
-
dispatch(removeBeforeReset(props.name));
|
|
18
|
-
};
|
|
19
|
-
}, [props]);
|
|
20
|
-
return null;
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
export default BeforeResetAction;
|
|
1
|
+
import { FC, useEffect } from "react";
|
|
2
|
+
import {
|
|
3
|
+
SaveCallback,
|
|
4
|
+
addBeforeReset,
|
|
5
|
+
removeBeforeReset,
|
|
6
|
+
} from "./saverSlice";
|
|
7
|
+
import { useAppDispatch } from "../../app/hooks";
|
|
8
|
+
|
|
9
|
+
type BeforeResetActionProps = SaveCallback;
|
|
10
|
+
|
|
11
|
+
const BeforeResetAction: FC<BeforeResetActionProps> = (props) => {
|
|
12
|
+
const dispatch = useAppDispatch();
|
|
13
|
+
useEffect(() => {
|
|
14
|
+
dispatch(addBeforeReset(props));
|
|
15
|
+
return () => {
|
|
16
|
+
// Remove the callback when the component is unmounted
|
|
17
|
+
dispatch(removeBeforeReset(props.name));
|
|
18
|
+
};
|
|
19
|
+
}, [props]);
|
|
20
|
+
return null;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export default BeforeResetAction;
|
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
import { FC, useEffect } from "react";
|
|
2
|
-
import {
|
|
3
|
-
SaveCallback,
|
|
4
|
-
addBeforeSave,
|
|
5
|
-
removeBeforeSave,
|
|
6
|
-
} from "./saverSlice";
|
|
7
|
-
import { useAppDispatch } from "../../app/hooks";
|
|
8
|
-
|
|
9
|
-
type BeforeSaveActionProps = SaveCallback;
|
|
10
|
-
|
|
11
|
-
const BeforeSaveAction: FC<BeforeSaveActionProps> = (props) => {
|
|
12
|
-
const dispatch = useAppDispatch();
|
|
13
|
-
useEffect(() => {
|
|
14
|
-
dispatch(addBeforeSave(props));
|
|
15
|
-
return () => {
|
|
16
|
-
// Remove the callback when the component is unmounted
|
|
17
|
-
dispatch(removeBeforeSave(props.name));
|
|
18
|
-
};
|
|
19
|
-
}, [props]);
|
|
20
|
-
return null;
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
export default BeforeSaveAction;
|
|
1
|
+
import { FC, useEffect } from "react";
|
|
2
|
+
import {
|
|
3
|
+
SaveCallback,
|
|
4
|
+
addBeforeSave,
|
|
5
|
+
removeBeforeSave,
|
|
6
|
+
} from "./saverSlice";
|
|
7
|
+
import { useAppDispatch } from "../../app/hooks";
|
|
8
|
+
|
|
9
|
+
type BeforeSaveActionProps = SaveCallback;
|
|
10
|
+
|
|
11
|
+
const BeforeSaveAction: FC<BeforeSaveActionProps> = (props) => {
|
|
12
|
+
const dispatch = useAppDispatch();
|
|
13
|
+
useEffect(() => {
|
|
14
|
+
dispatch(addBeforeSave(props));
|
|
15
|
+
return () => {
|
|
16
|
+
// Remove the callback when the component is unmounted
|
|
17
|
+
dispatch(removeBeforeSave(props.name));
|
|
18
|
+
};
|
|
19
|
+
}, [props]);
|
|
20
|
+
return null;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export default BeforeSaveAction;
|
|
@@ -1,154 +1,154 @@
|
|
|
1
|
-
import { FC, useEffect } from "react";
|
|
2
|
-
import { useAppDispatch, useAppSelector } from "../../app/hooks";
|
|
3
|
-
import {
|
|
4
|
-
selectSharedNotesContent,
|
|
5
|
-
selectComments,
|
|
6
|
-
selectGrading,
|
|
7
|
-
selectInstructions,
|
|
8
|
-
selectSaveState,
|
|
9
|
-
setIsMPDirty,
|
|
10
|
-
setIsPlayerDirty,
|
|
11
|
-
setSaveState,
|
|
12
|
-
setWorkflow,
|
|
13
|
-
selectSharedNotesType,
|
|
14
|
-
selectInstructionsType,
|
|
15
|
-
} from "../activityData/activityDataSlice";
|
|
16
|
-
import { useActivityJS } from "./ActivityJSProvider";
|
|
17
|
-
import { selectBeforeSave, selectAfterSave } from "./saverSlice";
|
|
18
|
-
import { useToast } from "../toast";
|
|
19
|
-
|
|
20
|
-
const Saver: FC<{}> = () => {
|
|
21
|
-
const dispatch = useAppDispatch();
|
|
22
|
-
const activityJs = useActivityJS();
|
|
23
|
-
const instructions = useAppSelector(selectInstructions);
|
|
24
|
-
const instructionsType = useAppSelector(selectInstructionsType);
|
|
25
|
-
const sharedNotesContent = useAppSelector(selectSharedNotesContent);
|
|
26
|
-
const sharedNotesType = useAppSelector(selectSharedNotesType);
|
|
27
|
-
const comments = useAppSelector(selectComments);
|
|
28
|
-
const grading = useAppSelector(selectGrading);
|
|
29
|
-
const beforeSave = useAppSelector(selectBeforeSave);
|
|
30
|
-
const afterSave = useAppSelector(selectAfterSave);
|
|
31
|
-
|
|
32
|
-
const toast = useToast();
|
|
33
|
-
|
|
34
|
-
const executePrepareSave = () => {};
|
|
35
|
-
const save = async () => {
|
|
36
|
-
if (!activityJs.activitySession) {
|
|
37
|
-
throw new Error("No activity session to save");
|
|
38
|
-
}
|
|
39
|
-
for (const callback of Object.values(beforeSave)) {
|
|
40
|
-
try {
|
|
41
|
-
const v = callback();
|
|
42
|
-
if (v instanceof Promise) {
|
|
43
|
-
await v;
|
|
44
|
-
}
|
|
45
|
-
} catch (e) {
|
|
46
|
-
console.error("Error in beforeSave callback", e);
|
|
47
|
-
dispatch(setSaveState("idle"));
|
|
48
|
-
toast.show({
|
|
49
|
-
summary: "Erreur : enregistrement annulé",
|
|
50
|
-
detail: (e as any).toString(),
|
|
51
|
-
severity: "error",
|
|
52
|
-
life: 10000,
|
|
53
|
-
});
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
const ab = activityJs.activitySession.activityBunch;
|
|
58
|
-
if (activityJs.activitySession.mode === "create") {
|
|
59
|
-
if (instructionsType === "rich") {
|
|
60
|
-
ab.instructions.value = {
|
|
61
|
-
lexical:
|
|
62
|
-
instructions?.format === "lexical"
|
|
63
|
-
? typeof instructions.value === "string"
|
|
64
|
-
? instructions.value
|
|
65
|
-
: JSON.stringify(instructions.value)
|
|
66
|
-
: null,
|
|
67
|
-
html:
|
|
68
|
-
instructions?.format === "lexical"
|
|
69
|
-
? instructions.htmlValue
|
|
70
|
-
: (instructions?.value as string),
|
|
71
|
-
};
|
|
72
|
-
} else {
|
|
73
|
-
ab.instructions.value = {
|
|
74
|
-
lexical: null,
|
|
75
|
-
html: null,
|
|
76
|
-
};
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
if (activityJs.activitySession.mode === "review") {
|
|
80
|
-
ab.assignmentNode!.comments.value = comments || "";
|
|
81
|
-
ab.assignmentNode!.grading.value = grading || "";
|
|
82
|
-
}
|
|
83
|
-
if (
|
|
84
|
-
activityJs.activitySession.mode === "create" ||
|
|
85
|
-
activityJs.activitySession.mode === "review" ||
|
|
86
|
-
activityJs.activitySession.mode === "assignment"
|
|
87
|
-
) {
|
|
88
|
-
if (sharedNotesContent && sharedNotesType === "rich") {
|
|
89
|
-
ab.shared_notes.value =
|
|
90
|
-
typeof sharedNotesContent === "string"
|
|
91
|
-
? sharedNotesContent
|
|
92
|
-
: JSON.stringify(sharedNotesContent);
|
|
93
|
-
} else {
|
|
94
|
-
ab.shared_notes.value = null;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
try {
|
|
98
|
-
await ab.save();
|
|
99
|
-
dispatch(setSaveState("idle"));
|
|
100
|
-
if (
|
|
101
|
-
activityJs.activitySession.mode === "assignment" ||
|
|
102
|
-
activityJs.activitySession.mode === "review"
|
|
103
|
-
) {
|
|
104
|
-
dispatch(setWorkflow(ab.assignmentNode!.workflow));
|
|
105
|
-
}
|
|
106
|
-
dispatch(setIsPlayerDirty(false));
|
|
107
|
-
dispatch(setIsMPDirty(false));
|
|
108
|
-
toast.show({
|
|
109
|
-
summary: "Sauvegarde réussie",
|
|
110
|
-
detail: "L'activité a bien été enregistrée.",
|
|
111
|
-
severity: "success",
|
|
112
|
-
life: 2000,
|
|
113
|
-
});
|
|
114
|
-
for (const callback of Object.values(afterSave)) {
|
|
115
|
-
try {
|
|
116
|
-
const v = callback();
|
|
117
|
-
if (v instanceof Promise) {
|
|
118
|
-
await v;
|
|
119
|
-
}
|
|
120
|
-
} catch (e) {
|
|
121
|
-
console.error("Error in afterSave callback", e);
|
|
122
|
-
dispatch(setSaveState("idle"));
|
|
123
|
-
toast.show({
|
|
124
|
-
summary: "Erreur après sauvegarde",
|
|
125
|
-
detail: (e as any).toString(),
|
|
126
|
-
severity: "error",
|
|
127
|
-
life: 10000,
|
|
128
|
-
});
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
} catch (error: any) {
|
|
132
|
-
console.error("Error saving", error);
|
|
133
|
-
dispatch(setSaveState("idle"));
|
|
134
|
-
toast.show({
|
|
135
|
-
summary: "Erreur lors de l'enregistrement",
|
|
136
|
-
detail: error.toString(),
|
|
137
|
-
severity: "error",
|
|
138
|
-
life: 10000,
|
|
139
|
-
});
|
|
140
|
-
}
|
|
141
|
-
};
|
|
142
|
-
|
|
143
|
-
const saveState = useAppSelector(selectSaveState);
|
|
144
|
-
useEffect(() => {
|
|
145
|
-
if (saveState === "should-save") {
|
|
146
|
-
dispatch(setSaveState("saving"));
|
|
147
|
-
executePrepareSave();
|
|
148
|
-
save();
|
|
149
|
-
}
|
|
150
|
-
}, [saveState]);
|
|
151
|
-
return null;
|
|
152
|
-
};
|
|
153
|
-
|
|
154
|
-
export default Saver;
|
|
1
|
+
import { FC, useEffect } from "react";
|
|
2
|
+
import { useAppDispatch, useAppSelector } from "../../app/hooks";
|
|
3
|
+
import {
|
|
4
|
+
selectSharedNotesContent,
|
|
5
|
+
selectComments,
|
|
6
|
+
selectGrading,
|
|
7
|
+
selectInstructions,
|
|
8
|
+
selectSaveState,
|
|
9
|
+
setIsMPDirty,
|
|
10
|
+
setIsPlayerDirty,
|
|
11
|
+
setSaveState,
|
|
12
|
+
setWorkflow,
|
|
13
|
+
selectSharedNotesType,
|
|
14
|
+
selectInstructionsType,
|
|
15
|
+
} from "../activityData/activityDataSlice";
|
|
16
|
+
import { useActivityJS } from "./ActivityJSProvider";
|
|
17
|
+
import { selectBeforeSave, selectAfterSave } from "./saverSlice";
|
|
18
|
+
import { useToast } from "../toast";
|
|
19
|
+
|
|
20
|
+
const Saver: FC<{}> = () => {
|
|
21
|
+
const dispatch = useAppDispatch();
|
|
22
|
+
const activityJs = useActivityJS();
|
|
23
|
+
const instructions = useAppSelector(selectInstructions);
|
|
24
|
+
const instructionsType = useAppSelector(selectInstructionsType);
|
|
25
|
+
const sharedNotesContent = useAppSelector(selectSharedNotesContent);
|
|
26
|
+
const sharedNotesType = useAppSelector(selectSharedNotesType);
|
|
27
|
+
const comments = useAppSelector(selectComments);
|
|
28
|
+
const grading = useAppSelector(selectGrading);
|
|
29
|
+
const beforeSave = useAppSelector(selectBeforeSave);
|
|
30
|
+
const afterSave = useAppSelector(selectAfterSave);
|
|
31
|
+
|
|
32
|
+
const toast = useToast();
|
|
33
|
+
|
|
34
|
+
const executePrepareSave = () => {};
|
|
35
|
+
const save = async () => {
|
|
36
|
+
if (!activityJs.activitySession) {
|
|
37
|
+
throw new Error("No activity session to save");
|
|
38
|
+
}
|
|
39
|
+
for (const callback of Object.values(beforeSave)) {
|
|
40
|
+
try {
|
|
41
|
+
const v = callback();
|
|
42
|
+
if (v instanceof Promise) {
|
|
43
|
+
await v;
|
|
44
|
+
}
|
|
45
|
+
} catch (e) {
|
|
46
|
+
console.error("Error in beforeSave callback", e);
|
|
47
|
+
dispatch(setSaveState("idle"));
|
|
48
|
+
toast.show({
|
|
49
|
+
summary: "Erreur : enregistrement annulé",
|
|
50
|
+
detail: (e as any).toString(),
|
|
51
|
+
severity: "error",
|
|
52
|
+
life: 10000,
|
|
53
|
+
});
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
const ab = activityJs.activitySession.activityBunch;
|
|
58
|
+
if (activityJs.activitySession.mode === "create") {
|
|
59
|
+
if (instructionsType === "rich") {
|
|
60
|
+
ab.instructions.value = {
|
|
61
|
+
lexical:
|
|
62
|
+
instructions?.format === "lexical"
|
|
63
|
+
? typeof instructions.value === "string"
|
|
64
|
+
? instructions.value
|
|
65
|
+
: JSON.stringify(instructions.value)
|
|
66
|
+
: null,
|
|
67
|
+
html:
|
|
68
|
+
instructions?.format === "lexical"
|
|
69
|
+
? instructions.htmlValue
|
|
70
|
+
: (instructions?.value as string),
|
|
71
|
+
};
|
|
72
|
+
} else {
|
|
73
|
+
ab.instructions.value = {
|
|
74
|
+
lexical: null,
|
|
75
|
+
html: null,
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
if (activityJs.activitySession.mode === "review") {
|
|
80
|
+
ab.assignmentNode!.comments.value = comments || "";
|
|
81
|
+
ab.assignmentNode!.grading.value = grading || "";
|
|
82
|
+
}
|
|
83
|
+
if (
|
|
84
|
+
activityJs.activitySession.mode === "create" ||
|
|
85
|
+
activityJs.activitySession.mode === "review" ||
|
|
86
|
+
activityJs.activitySession.mode === "assignment"
|
|
87
|
+
) {
|
|
88
|
+
if (sharedNotesContent && sharedNotesType === "rich") {
|
|
89
|
+
ab.shared_notes.value =
|
|
90
|
+
typeof sharedNotesContent === "string"
|
|
91
|
+
? sharedNotesContent
|
|
92
|
+
: JSON.stringify(sharedNotesContent);
|
|
93
|
+
} else {
|
|
94
|
+
ab.shared_notes.value = null;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
try {
|
|
98
|
+
await ab.save();
|
|
99
|
+
dispatch(setSaveState("idle"));
|
|
100
|
+
if (
|
|
101
|
+
activityJs.activitySession.mode === "assignment" ||
|
|
102
|
+
activityJs.activitySession.mode === "review"
|
|
103
|
+
) {
|
|
104
|
+
dispatch(setWorkflow(ab.assignmentNode!.workflow));
|
|
105
|
+
}
|
|
106
|
+
dispatch(setIsPlayerDirty(false));
|
|
107
|
+
dispatch(setIsMPDirty(false));
|
|
108
|
+
toast.show({
|
|
109
|
+
summary: "Sauvegarde réussie",
|
|
110
|
+
detail: "L'activité a bien été enregistrée.",
|
|
111
|
+
severity: "success",
|
|
112
|
+
life: 2000,
|
|
113
|
+
});
|
|
114
|
+
for (const callback of Object.values(afterSave)) {
|
|
115
|
+
try {
|
|
116
|
+
const v = callback();
|
|
117
|
+
if (v instanceof Promise) {
|
|
118
|
+
await v;
|
|
119
|
+
}
|
|
120
|
+
} catch (e) {
|
|
121
|
+
console.error("Error in afterSave callback", e);
|
|
122
|
+
dispatch(setSaveState("idle"));
|
|
123
|
+
toast.show({
|
|
124
|
+
summary: "Erreur après sauvegarde",
|
|
125
|
+
detail: (e as any).toString(),
|
|
126
|
+
severity: "error",
|
|
127
|
+
life: 10000,
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
} catch (error: any) {
|
|
132
|
+
console.error("Error saving", error);
|
|
133
|
+
dispatch(setSaveState("idle"));
|
|
134
|
+
toast.show({
|
|
135
|
+
summary: "Erreur lors de l'enregistrement",
|
|
136
|
+
detail: error.toString(),
|
|
137
|
+
severity: "error",
|
|
138
|
+
life: 10000,
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
const saveState = useAppSelector(selectSaveState);
|
|
144
|
+
useEffect(() => {
|
|
145
|
+
if (saveState === "should-save") {
|
|
146
|
+
dispatch(setSaveState("saving"));
|
|
147
|
+
executePrepareSave();
|
|
148
|
+
save();
|
|
149
|
+
}
|
|
150
|
+
}, [saveState]);
|
|
151
|
+
return null;
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
export default Saver;
|
|
@@ -1,85 +1,85 @@
|
|
|
1
|
-
import { useAppDispatch, useAppSelector } from "../../app/hooks";
|
|
2
|
-
import {
|
|
3
|
-
selectCanReset,
|
|
4
|
-
selectMode,
|
|
5
|
-
selectWorkflow,
|
|
6
|
-
setSaveState,
|
|
7
|
-
} from "../activityData/activityDataSlice";
|
|
8
|
-
import { useActivityJS } from "./ActivityJSProvider";
|
|
9
|
-
import { selectBeforeReset, selectAfterReset } from "./saverSlice";
|
|
10
|
-
|
|
11
|
-
type UseResetProps = {
|
|
12
|
-
onError: (errorMessage: string) => void;
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
export const useReset = (props: UseResetProps) => {
|
|
16
|
-
const dispatch = useAppDispatch();
|
|
17
|
-
const canReset = useAppSelector(selectCanReset);
|
|
18
|
-
const beforeReset = useAppSelector(selectBeforeReset);
|
|
19
|
-
const afterReset = useAppSelector(selectAfterReset);
|
|
20
|
-
const activityJs = useActivityJS();
|
|
21
|
-
const mode = useAppSelector(selectMode);
|
|
22
|
-
const workflow = useAppSelector(selectWorkflow);
|
|
23
|
-
if (mode !== "assignment" || workflow !== "current") {
|
|
24
|
-
return null;
|
|
25
|
-
}
|
|
26
|
-
if (!canReset) {
|
|
27
|
-
return null;
|
|
28
|
-
}
|
|
29
|
-
return async (reload: boolean = true) => {
|
|
30
|
-
if (activityJs.state !== "loaded") {
|
|
31
|
-
throw new Error("No activity session to reset");
|
|
32
|
-
}
|
|
33
|
-
for (const callback of Object.values(beforeReset)) {
|
|
34
|
-
try {
|
|
35
|
-
const v = callback();
|
|
36
|
-
if (v instanceof Promise) {
|
|
37
|
-
await v;
|
|
38
|
-
}
|
|
39
|
-
} catch (e) {
|
|
40
|
-
console.error("Error in beforeReset callback", e);
|
|
41
|
-
props.onError((e as any).toString());
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
dispatch(setSaveState("saving"));
|
|
46
|
-
try {
|
|
47
|
-
const ab = activityJs.activitySession.activityBunch;
|
|
48
|
-
if (!ab.assignmentNode) {
|
|
49
|
-
throw new Error("No assignment node");
|
|
50
|
-
}
|
|
51
|
-
if (ab.assignmentNode.content.value != null) {
|
|
52
|
-
ab.assignmentNode.content.value = null;
|
|
53
|
-
}
|
|
54
|
-
if (ab.assignmentNode.binaryData?.value != null) {
|
|
55
|
-
ab.assignmentNode.binaryData.value = null;
|
|
56
|
-
}
|
|
57
|
-
try {
|
|
58
|
-
await ab.save();
|
|
59
|
-
|
|
60
|
-
for (const callback of Object.values(afterReset)) {
|
|
61
|
-
try {
|
|
62
|
-
const v = callback();
|
|
63
|
-
if (v instanceof Promise) {
|
|
64
|
-
await v;
|
|
65
|
-
}
|
|
66
|
-
} catch (e) {
|
|
67
|
-
console.error("Error in afterReset callback", e);
|
|
68
|
-
props.onError((e as any).toString());
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
if (reload) {
|
|
72
|
-
location.reload();
|
|
73
|
-
}
|
|
74
|
-
} catch (e) {
|
|
75
|
-
console.error("Error in reset", e);
|
|
76
|
-
props.onError((e as any).toString());
|
|
77
|
-
return;
|
|
78
|
-
}
|
|
79
|
-
} catch (e) {
|
|
80
|
-
console.error("Error in reset process", e);
|
|
81
|
-
props.onError((e as any).toString());
|
|
82
|
-
}
|
|
83
|
-
dispatch(setSaveState("idle"));
|
|
84
|
-
};
|
|
85
|
-
};
|
|
1
|
+
import { useAppDispatch, useAppSelector } from "../../app/hooks";
|
|
2
|
+
import {
|
|
3
|
+
selectCanReset,
|
|
4
|
+
selectMode,
|
|
5
|
+
selectWorkflow,
|
|
6
|
+
setSaveState,
|
|
7
|
+
} from "../activityData/activityDataSlice";
|
|
8
|
+
import { useActivityJS } from "./ActivityJSProvider";
|
|
9
|
+
import { selectBeforeReset, selectAfterReset } from "./saverSlice";
|
|
10
|
+
|
|
11
|
+
type UseResetProps = {
|
|
12
|
+
onError: (errorMessage: string) => void;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export const useReset = (props: UseResetProps) => {
|
|
16
|
+
const dispatch = useAppDispatch();
|
|
17
|
+
const canReset = useAppSelector(selectCanReset);
|
|
18
|
+
const beforeReset = useAppSelector(selectBeforeReset);
|
|
19
|
+
const afterReset = useAppSelector(selectAfterReset);
|
|
20
|
+
const activityJs = useActivityJS();
|
|
21
|
+
const mode = useAppSelector(selectMode);
|
|
22
|
+
const workflow = useAppSelector(selectWorkflow);
|
|
23
|
+
if (mode !== "assignment" || workflow !== "current") {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
if (!canReset) {
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
return async (reload: boolean = true) => {
|
|
30
|
+
if (activityJs.state !== "loaded") {
|
|
31
|
+
throw new Error("No activity session to reset");
|
|
32
|
+
}
|
|
33
|
+
for (const callback of Object.values(beforeReset)) {
|
|
34
|
+
try {
|
|
35
|
+
const v = callback();
|
|
36
|
+
if (v instanceof Promise) {
|
|
37
|
+
await v;
|
|
38
|
+
}
|
|
39
|
+
} catch (e) {
|
|
40
|
+
console.error("Error in beforeReset callback", e);
|
|
41
|
+
props.onError((e as any).toString());
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
dispatch(setSaveState("saving"));
|
|
46
|
+
try {
|
|
47
|
+
const ab = activityJs.activitySession.activityBunch;
|
|
48
|
+
if (!ab.assignmentNode) {
|
|
49
|
+
throw new Error("No assignment node");
|
|
50
|
+
}
|
|
51
|
+
if (ab.assignmentNode.content.value != null) {
|
|
52
|
+
ab.assignmentNode.content.value = null;
|
|
53
|
+
}
|
|
54
|
+
if (ab.assignmentNode.binaryData?.value != null) {
|
|
55
|
+
ab.assignmentNode.binaryData.value = null;
|
|
56
|
+
}
|
|
57
|
+
try {
|
|
58
|
+
await ab.save();
|
|
59
|
+
|
|
60
|
+
for (const callback of Object.values(afterReset)) {
|
|
61
|
+
try {
|
|
62
|
+
const v = callback();
|
|
63
|
+
if (v instanceof Promise) {
|
|
64
|
+
await v;
|
|
65
|
+
}
|
|
66
|
+
} catch (e) {
|
|
67
|
+
console.error("Error in afterReset callback", e);
|
|
68
|
+
props.onError((e as any).toString());
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
if (reload) {
|
|
72
|
+
location.reload();
|
|
73
|
+
}
|
|
74
|
+
} catch (e) {
|
|
75
|
+
console.error("Error in reset", e);
|
|
76
|
+
props.onError((e as any).toString());
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
} catch (e) {
|
|
80
|
+
console.error("Error in reset process", e);
|
|
81
|
+
props.onError((e as any).toString());
|
|
82
|
+
}
|
|
83
|
+
dispatch(setSaveState("idle"));
|
|
84
|
+
};
|
|
85
|
+
};
|