@nualang/nualang-ui-components 0.1.1225 → 0.1.1227

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.
@@ -6,27 +6,37 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.default = AssignmentCard;
7
7
  var _react = _interopRequireWildcard(require("react"));
8
8
  var _Typography = _interopRequireDefault(require("@mui/material/Typography"));
9
- var _Avatar = _interopRequireDefault(require("@mui/material/Avatar"));
10
9
  var _ExpandMore = _interopRequireDefault(require("@mui/icons-material/ExpandMore"));
11
10
  var _ExpandLess = _interopRequireDefault(require("@mui/icons-material/ExpandLess"));
12
11
  var _material = require("@mui/material");
13
12
  var _propTypes = _interopRequireDefault(require("prop-types"));
14
- var _AssignmentExerciseSelector = _interopRequireDefault(require("../../Misc/AssignmentExerciseSelector/AssignmentExerciseSelector"));
13
+ var _AssignmentExerciseSelector = _interopRequireDefault(require("../AssignmentExerciseSelector/AssignmentExerciseSelector"));
14
+ var _Queries = require("@nualang/nualang-api-and-queries/Queries");
15
+ var _useConfirm = _interopRequireDefault(require("../../hooks/useConfirm"));
15
16
  var _jsxRuntime = require("react/jsx-runtime");
16
17
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
17
18
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
18
19
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
19
20
  function AssignmentCard({
20
- t,
21
+ t = text => text,
21
22
  assignment,
22
23
  handleStartExercise,
23
24
  username,
24
25
  getCourseSections,
25
26
  getRoleplays,
26
- isCreator
27
+ isCreator,
28
+ getCourses,
29
+ deleteAssignment,
30
+ handleEditAssignment
27
31
  }) {
28
- t = text => text;
29
32
  const [expanded, setExpanded] = (0, _react.useState)(false);
33
+ const [confirm] = (0, _useConfirm.default)(t);
34
+ const handleDeleteAssignment = async (classroomId, assignmentId) => {
35
+ const confirmed = await confirm(t('delete_assignment'), t('delete_assignment_confirmation'));
36
+ if (confirmed) {
37
+ await deleteAssignment(classroomId, assignmentId);
38
+ }
39
+ };
30
40
  const calculateDaysUntilDue = dueDate => {
31
41
  const now = new Date();
32
42
  const due = new Date(dueDate);
@@ -46,6 +56,38 @@ function AssignmentCard({
46
56
  event.stopPropagation();
47
57
  setExpanded(prev => !prev);
48
58
  };
59
+ const {
60
+ uniqueCourses
61
+ } = (0, _react.useMemo)(() => {
62
+ const courses = new Set();
63
+ assignment?.exercises?.forEach(({
64
+ courseSectionTopicId,
65
+ name
66
+ }) => {
67
+ if (courseSectionTopicId) {
68
+ const [courseId, sectionId, topicId] = courseSectionTopicId.split("|");
69
+ courses.add(courseId);
70
+ }
71
+ });
72
+ return {
73
+ uniqueCourses: [...courses]
74
+ };
75
+ }, [assignment?.exercises]);
76
+ const coursesQuery = _Queries.courses.useCourses(async filters => {
77
+ const response = await getCourses(filters);
78
+ return response;
79
+ }, {
80
+ filters: {
81
+ courseIds: uniqueCourses?.toString()
82
+ }
83
+ }, {
84
+ enabled: !!uniqueCourses?.length
85
+ });
86
+ const courses = (0, _react.useMemo)(() => coursesQuery.isSuccess && Array.isArray(coursesQuery.data.Items) && coursesQuery.data.Items.length ? coursesQuery.data.Items : [], [coursesQuery.data, coursesQuery.isSuccess]);
87
+ assignment = {
88
+ ...assignment,
89
+ courses
90
+ };
49
91
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Card, {
50
92
  sx: {
51
93
  display: "flex",
@@ -60,16 +102,7 @@ function AssignmentCard({
60
102
  container: true,
61
103
  spacing: 2,
62
104
  alignItems: "center",
63
- children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Grid, {
64
- item: true,
65
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Avatar.default, {
66
- sx: {
67
- width: 50,
68
- height: 50
69
- },
70
- src: assignment.image
71
- })
72
- }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_material.Grid, {
105
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(_material.Grid, {
73
106
  item: true,
74
107
  xs: true,
75
108
  flexDirection: "column",
@@ -85,7 +118,7 @@ function AssignmentCard({
85
118
  },
86
119
  children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_material.LinearProgress, {
87
120
  variant: "determinate",
88
- value: assignment.completed / assignment.assigned * 100 //change this to the actual value of student completed
121
+ value: assignment.completed / assignment.assignedStudents.length * 100 //change this to the actual value of student completed
89
122
  ,
90
123
  sx: {
91
124
  height: 10,
@@ -99,17 +132,21 @@ function AssignmentCard({
99
132
  color: "text.secondary",
100
133
  marginLeft: 1
101
134
  },
102
- children: `${Math.round(assignment.completed / assignment.assigned * 100)}%`
135
+ children: `${Math.round(assignment.completed / assignment.assignedStudents.length * 100)}%`
103
136
  })]
104
137
  })]
105
138
  }), isCreator && /*#__PURE__*/(0, _jsxRuntime.jsxs)(_material.Grid, {
106
139
  item: true,
107
140
  children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Button, {
141
+ onClick: () => handleEditAssignment(assignment),
108
142
  color: "primary",
109
143
  children: t("edit")
110
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Button, {
144
+ }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_material.Button, {
111
145
  color: "primary",
112
- children: t("delete")
146
+ onClick: () => {
147
+ handleDeleteAssignment(assignment.classroomId, assignment.assignmentId);
148
+ },
149
+ children: [t("delete"), " "]
113
150
  })]
114
151
  }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Grid, {
115
152
  item: true,
@@ -140,7 +177,7 @@ function AssignmentCard({
140
177
  md: 9.5,
141
178
  children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_Typography.default, {
142
179
  variant: "body2",
143
- children: assignment.description
180
+ children: assignment.instructions
144
181
  }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Box, {
145
182
  mt: 2,
146
183
  width: "80%",
@@ -151,8 +188,9 @@ function AssignmentCard({
151
188
  username: username,
152
189
  getCourseSections: getCourseSections,
153
190
  getRoleplays: getRoleplays,
154
- isAssignment: true,
155
- isCreator: isCreator
191
+ isCreator: isCreator,
192
+ viewOnly: true,
193
+ useCase: isCreator ? "assignment-view" : "assignment-start"
156
194
  })
157
195
  })]
158
196
  }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_material.Grid, {
@@ -169,7 +207,7 @@ function AssignmentCard({
169
207
  children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(_material.Box, {
170
208
  children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_Typography.default, {
171
209
  variant: "h4",
172
- children: assignment.completed
210
+ children: "2"
173
211
  }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_Typography.default, {
174
212
  variant: "body2",
175
213
  color: "text.secondary",
@@ -186,7 +224,7 @@ function AssignmentCard({
186
224
  }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_material.Box, {
187
225
  children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_Typography.default, {
188
226
  variant: "h4",
189
- children: assignment.assigned
227
+ children: assignment.assignedStudents.length
190
228
  }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_Typography.default, {
191
229
  variant: "body2",
192
230
  color: "text.secondary",
@@ -215,6 +253,7 @@ AssignmentCard.propTypes = {
215
253
  dueDate: _propTypes.default.string.isRequired,
216
254
  completed: _propTypes.default.number,
217
255
  assigned: _propTypes.default.number,
256
+ assignedStudents: _propTypes.default.array,
218
257
  t: _propTypes.default.func
219
258
  }).isRequired
220
259
  };
@@ -17,8 +17,13 @@ const AssignmentCardsList = ({
17
17
  t = text => text,
18
18
  assignments = [],
19
19
  isCreator,
20
- onRefresh,
21
- handleCreateAssignment
20
+ handleCreateAssignment,
21
+ getCourses,
22
+ getCourseSections,
23
+ getRoleplays,
24
+ deleteAssignment,
25
+ handleEditAssignment,
26
+ refreshAssignments
22
27
  }) => {
23
28
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Box, {
24
29
  mt: 3,
@@ -95,7 +100,7 @@ const AssignmentCardsList = ({
95
100
  placement: "left",
96
101
  title: t("refresh_assignments"),
97
102
  children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.IconButton, {
98
- onClick: onRefresh,
103
+ onClick: refreshAssignments,
99
104
  "aria-label": "refresh",
100
105
  size: "large",
101
106
  children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Refresh.default, {})
@@ -104,7 +109,12 @@ const AssignmentCardsList = ({
104
109
  }), assignments.map(assignment => /*#__PURE__*/(0, _jsxRuntime.jsx)(_AssignmentCard.default, {
105
110
  assignment: assignment,
106
111
  t: t,
107
- isCreator: isCreator
112
+ isCreator: isCreator,
113
+ getCourses: getCourses,
114
+ getCourseSections: getCourseSections,
115
+ getRoleplays: getRoleplays,
116
+ deleteAssignment: deleteAssignment,
117
+ handleEditAssignment: handleEditAssignment
108
118
  }, assignment.id))]
109
119
  })
110
120
  });
@@ -18,8 +18,7 @@ function Course({
18
18
  getCourseSections,
19
19
  getRoleplays,
20
20
  username,
21
- handleCreateGame,
22
- t,
21
+ t = text => text,
23
22
  isExerciseSelected,
24
23
  setIsExerciseSelected,
25
24
  isDialogOpen,
@@ -28,10 +27,12 @@ function Course({
28
27
  useCase,
29
28
  assignment,
30
29
  handleStartExercise,
31
- isAssignment,
32
- isCreator
30
+ isCreator,
31
+ viewOnly
33
32
  }) {
34
33
  const [open, setOpen] = (0, _react.useState)(false);
34
+ const [selectedSectionIds, setSelectedSectionIds] = (0, _react.useState)([]);
35
+ const [filteredSections, setFilteredSections] = (0, _react.useState)([]);
35
36
  const sectionsQuery = _Queries.courses.useCourseSections(async (courseId, filters) => {
36
37
  const response = await getCourseSections(courseId, filters);
37
38
  return response;
@@ -44,8 +45,29 @@ function Course({
44
45
  }, {
45
46
  enabled: !!course.courseId && isDialogOpen
46
47
  });
48
+ (0, _react.useEffect)(() => {
49
+ assignment?.exercises?.forEach(exercise => {
50
+ if (exercise.courseSectionTopicId) {
51
+ const sectionId = exercise.courseSectionTopicId.split("|")[1];
52
+ setSelectedSectionIds(prev => [...prev, sectionId]);
53
+ }
54
+ });
55
+ }, [selectedExercises]);
56
+ (0, _react.useEffect)(() => {
57
+ selectedExercises?.forEach(exercise => {
58
+ if (exercise.courseSectionTopicId) {
59
+ const sectionId = exercise.courseSectionTopicId.split("|")[1];
60
+ setSelectedSectionIds(prev => [...prev, sectionId]);
61
+ }
62
+ });
63
+ }, [selectedExercises]);
47
64
  const courseSections = (0, _react.useMemo)(() => sectionsQuery.isSuccess && Array.isArray(sectionsQuery.data.Items) && sectionsQuery.data.Items.length ? sectionsQuery.data.Items : [], [sectionsQuery.data, sectionsQuery.isSuccess]);
48
65
  const isCourseEmpty = courseSections.length === 0 && !sectionsQuery.isLoading ? true : false;
66
+ (0, _react.useEffect)(() => {
67
+ if (viewOnly) {
68
+ setFilteredSections(courseSections.filter(section => selectedSectionIds.includes(section.sectionId)));
69
+ }
70
+ }, [courseSections, selectedSectionIds, viewOnly]);
49
71
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_material.List, {
50
72
  disablePadding: true,
51
73
  children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Tooltip, {
@@ -93,9 +115,8 @@ function Course({
93
115
  ml: 3.5,
94
116
  children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_AssignmentExerciseSelection.default, {
95
117
  t: t,
96
- sections: courseSections,
118
+ sections: viewOnly ? filteredSections : courseSections,
97
119
  isLoading: sectionsQuery.isLoading,
98
- handleCreateGame: handleCreateGame,
99
120
  courseId: course.courseId,
100
121
  isExerciseSelected: isExerciseSelected,
101
122
  setIsExerciseSelected: setIsExerciseSelected,
@@ -105,8 +126,8 @@ function Course({
105
126
  useCase: useCase,
106
127
  assignment: assignment,
107
128
  handleStartExercise: handleStartExercise,
108
- isAssignment: isAssignment,
109
- isCreator: isCreator
129
+ isCreator: isCreator,
130
+ viewOnly: viewOnly
110
131
  })
111
132
  })
112
133
  })]
@@ -117,8 +138,7 @@ function AssignmentCourseSelection({
117
138
  getCourseSections,
118
139
  getRoleplays,
119
140
  username,
120
- handleCreateGame,
121
- t,
141
+ t = text => text,
122
142
  isExerciseSelected,
123
143
  setIsExerciseSelected,
124
144
  handleSelectExercise,
@@ -126,8 +146,8 @@ function AssignmentCourseSelection({
126
146
  useCase,
127
147
  assignment,
128
148
  handleStartExercise,
129
- isAssignment,
130
149
  isCreator,
150
+ viewOnly,
131
151
  ...otherProps
132
152
  }) {
133
153
  return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
@@ -137,17 +157,16 @@ function AssignmentCourseSelection({
137
157
  getCourseSections: getCourseSections,
138
158
  getRoleplays: getRoleplays,
139
159
  username: username,
140
- handleCreateGame: handleCreateGame,
141
160
  t: t,
142
161
  isExerciseSelected: isExerciseSelected,
143
162
  setIsExerciseSelected: setIsExerciseSelected,
144
163
  handleSelectExercise: handleSelectExercise,
145
- selectedExercises: selectedExercises,
164
+ selectedExercises: assignment ? assignment.exercises?.filter(exercise => exercise?.roleplayId || exercise?.courseSectionTopicId?.split("|")[0] === course?.courseId) : selectedExercises?.filter(exercise => exercise?.roleplayId || exercise?.courseSectionTopicId?.split("|")[0] === course?.courseId),
146
165
  useCase: useCase,
147
166
  assignment: assignment,
148
167
  handleStartExercise: handleStartExercise,
149
- isAssignment: isAssignment,
150
- isCreator: isCreator
168
+ isCreator: isCreator,
169
+ viewOnly: viewOnly
151
170
  }))
152
171
  });
153
172
  }