@nualang/nualang-ui-components 0.1.1217 → 0.1.1219

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.
@@ -12,6 +12,7 @@ var _ExpandLess = _interopRequireDefault(require("@mui/icons-material/ExpandLess
12
12
  var _material = require("@mui/material");
13
13
  var _propTypes = _interopRequireDefault(require("prop-types"));
14
14
  var _AssignmentExerciseSelector = _interopRequireDefault(require("../../Misc/AssignmentExerciseSelector/AssignmentExerciseSelector"));
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); }
@@ -23,10 +24,11 @@ function Assignment({
23
24
  username,
24
25
  getCourseSections,
25
26
  getRoleplays,
26
- isCreator
27
+ isCreator,
28
+ deleteAssignment
27
29
  }) {
28
- t = text => text;
29
30
  const [expanded, setExpanded] = (0, _react.useState)(false);
31
+ const [confirm] = (0, _useConfirm.default)(t);
30
32
  const calculateDaysUntilDue = dueDate => {
31
33
  const now = new Date();
32
34
  const due = new Date(dueDate);
@@ -46,6 +48,12 @@ function Assignment({
46
48
  event.stopPropagation();
47
49
  setExpanded(prev => !prev);
48
50
  };
51
+ const handleDeleteAssignment = async (classroomId, assignmentId) => {
52
+ const confirmed = await confirm(t('delete_assignment'), t('delete_assignment_confirmation'));
53
+ if (confirmed) {
54
+ await deleteAssignment(classroomId, assignmentId);
55
+ }
56
+ };
49
57
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Card, {
50
58
  sx: {
51
59
  display: "flex",
@@ -109,6 +117,9 @@ function Assignment({
109
117
  children: t("edit")
110
118
  }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Button, {
111
119
  color: "primary",
120
+ onClick: () => {
121
+ handleDeleteAssignment(assignment.classroomId, assignment.assignmentId);
122
+ },
112
123
  children: t("delete")
113
124
  })]
114
125
  }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Grid, {
@@ -156,8 +156,8 @@ function CreateAssignmentScreen({
156
156
  };
157
157
  });
158
158
  };
159
- const handleCreateAssignment = () => {
160
- createAssignment(assignment);
159
+ const handleCreateAssignment = async () => {
160
+ await createAssignment(assignment);
161
161
  handleClose();
162
162
  };
163
163
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_material.Dialog, {
@@ -18,7 +18,8 @@ const AssignmentCardsList = ({
18
18
  assignments = [],
19
19
  isCreator,
20
20
  onRefresh,
21
- handleCreateAssignment
21
+ handleCreateAssignment,
22
+ deleteAssignment
22
23
  }) => {
23
24
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Box, {
24
25
  mt: 3,
@@ -104,7 +105,8 @@ const AssignmentCardsList = ({
104
105
  }), assignments.map(assignment => /*#__PURE__*/(0, _jsxRuntime.jsx)(_Assignment.default, {
105
106
  assignment: assignment,
106
107
  t: t,
107
- isCreator: isCreator
108
+ isCreator: isCreator,
109
+ deleteAssignment: deleteAssignment
108
110
  }, assignment.id))]
109
111
  })
110
112
  });
@@ -390,6 +390,7 @@ function Classroom({
390
390
  featureFlags,
391
391
  assignments,
392
392
  handleCreateAssignment,
393
+ deleteAssignment,
393
394
  ...otherProps
394
395
  }) {
395
396
  const {
@@ -865,7 +866,8 @@ function Classroom({
865
866
  memberId: !isCreator && username,
866
867
  username: username,
867
868
  getCourseSections: getCourseSections,
868
- handleCreateAssignment: handleCreateAssignment
869
+ handleCreateAssignment: handleCreateAssignment,
870
+ deleteAssignment: deleteAssignment
869
871
  })
870
872
  }, `tab-content-assignments`)
871
873
  }] : []), ...(isVideoChatEnabled && isNualangLiveEnabled && (isMember && isVideoChatEnabledInSettings || isCreator) ? [{
@@ -691,7 +691,6 @@ function useExerciseState({
691
691
  setTimeout(() => {
692
692
  // Check if transcript has been reset
693
693
  if (interimTranscript || finalTranscript) {
694
- console.log("Transcript not reset, resetting now.");
695
694
  resetTranscript();
696
695
  }
697
696
  }, 800);
@@ -154,22 +154,12 @@ function useRecognition(props = {}) {
154
154
  */
155
155
  const initRecording = async (gcloudParams, onData, onError) => {
156
156
  try {
157
- const {
158
- mediaDevices
159
- } = navigator;
160
- const [availableMicrophones, activeMicrophone, sampleRate] = await (0, _index.getMicrophoneInfo)(mediaDevices);
161
157
  await setupAudioContext();
162
- let sampleRateToUse = sampleRate;
163
- if (sampleRate && sampleRate < 8000) {
164
- sampleRateToUse = 8000;
165
- } else if (sampleRate && sampleRate > 48000) {
166
- sampleRateToUse = 48000;
167
- }
168
158
  const handleSuccess = function (stream) {
169
159
  const gcloudConfig = {
170
160
  config: {
171
161
  encoding: "LINEAR16",
172
- sampleRateHertz: sampleRateToUse || 16000,
162
+ sampleRateHertz: 16000,
173
163
  languageCode: gcloudParams.languageCode || "en-US",
174
164
  profanityFilter: true,
175
165
  enableWordTimeOffsets: false,
@@ -182,6 +172,7 @@ function useRecognition(props = {}) {
182
172
  interimResults: gcloudParams.interimResults // If you want interim results, set this to true
183
173
  };
184
174
  socket.emit("startGoogleCloudStream", gcloudConfig, version); // init socket Google Speech Connection
175
+
185
176
  streamRef.current = stream;
186
177
  audioInputRef.current = audioContextRef.current.createMediaStreamSource(stream);
187
178
  serverErrorRef.current = null;
@@ -193,6 +184,15 @@ function useRecognition(props = {}) {
193
184
  const audioData = event.data;
194
185
  socket.emit("binaryData", audioData, version);
195
186
  };
187
+ processorRef.current.port.onmessage = event => {
188
+ const audioData = event.data;
189
+ let sampleRate = 44100; // Default sample rate
190
+ if (audioContextRef?.current?.sampleRate && audioContextRef?.current?.sampleRate !== 44100) {
191
+ sampleRate = audioContextRef.current.sampleRate;
192
+ }
193
+ const result = (0, _index.downsampleBuffer)(audioData, sampleRate, 16000);
194
+ socket.emit("binaryData", result, version);
195
+ };
196
196
  if (window.MediaRecorder) {
197
197
  mediaRecorderRef.current = new MediaRecorder(stream);
198
198
  mediaRecorderRef.current.ondataavailable = e => {
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.formatCourseMemberCompletions = exports.domainPattern = exports.convertToAlphanumeric = exports.containsInvalidSymbols = exports.checkIsGeneratedEmail = exports.capitalize = exports.calcPercentageCompletion = exports.calcCompletions = void 0;
6
+ exports.formatCourseMemberCompletions = exports.downsampleBuffer = exports.domainPattern = exports.convertToAlphanumeric = exports.containsInvalidSymbols = exports.checkIsGeneratedEmail = exports.capitalize = exports.calcPercentageCompletion = exports.calcCompletions = void 0;
7
7
  exports.formatCurrency = formatCurrency;
8
8
  exports.formatNumberTotal = exports.formatMarkdownNewlines = exports.formatFileSize = void 0;
9
9
  exports.getBase64ImageFromUrl = getBase64ImageFromUrl;
@@ -454,14 +454,36 @@ const getMicrophoneInfo = async mediaDevices => {
454
454
  const availableMicrophoneNames = microphones?.filter(device => device.deviceId !== "default").map(device => device.label).join(", ") || "No available microphones detected";
455
455
  const activeMicrophone = microphones?.length > 0 ? microphones.find(mic => mic.deviceId === "default") || microphones[0] : null;
456
456
  const activeMicrophoneName = activeMicrophone?.label.split("Default - ").pop() || "No active microphone detected";
457
-
458
- // Create an AudioContext with the stream from the active microphone
459
-
460
- const capabilities = activeMicrophone.getCapabilities();
461
- let sampleRate = capabilities?.sampleRate?.max || capabilities?.sampleRate?.exact;
462
- return [availableMicrophoneNames, activeMicrophoneName, sampleRate];
457
+ return [availableMicrophoneNames, activeMicrophoneName];
463
458
  } catch (error) {
464
459
  console.error("Error accessing the microphone:", error);
465
460
  }
466
461
  };
467
- exports.getMicrophoneInfo = getMicrophoneInfo;
462
+ exports.getMicrophoneInfo = getMicrophoneInfo;
463
+ const downsampleBuffer = (buffer, sampleRate, outSampleRate) => {
464
+ if (outSampleRate == sampleRate) {
465
+ return buffer;
466
+ }
467
+ if (outSampleRate > sampleRate) {
468
+ throw new Error("downsampling rate show be smaller than original sample rate");
469
+ }
470
+ var sampleRateRatio = sampleRate / outSampleRate;
471
+ var newLength = Math.round(buffer.length / sampleRateRatio);
472
+ var result = new Int16Array(newLength);
473
+ var offsetResult = 0;
474
+ var offsetBuffer = 0;
475
+ while (offsetResult < result.length) {
476
+ var nextOffsetBuffer = Math.round((offsetResult + 1) * sampleRateRatio);
477
+ var accum = 0,
478
+ count = 0;
479
+ for (var i = offsetBuffer; i < nextOffsetBuffer && i < buffer.length; i += 1) {
480
+ accum += buffer[i];
481
+ count += 1;
482
+ }
483
+ result[offsetResult] = Math.min(1, accum / count) * 0x7fff;
484
+ offsetResult += 1;
485
+ offsetBuffer = nextOffsetBuffer;
486
+ }
487
+ return result.buffer;
488
+ };
489
+ exports.downsampleBuffer = downsampleBuffer;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nualang/nualang-ui-components",
3
- "version": "0.1.1217",
3
+ "version": "0.1.1219",
4
4
  "main": "dist/index.js",
5
5
  "files": [
6
6
  "dist",
@@ -52,6 +52,7 @@
52
52
  "luxon": "^3.3.0",
53
53
  "moment": "^2.29.4",
54
54
  "n2words": "^1.21.0",
55
+ "patch-package": "^8.0.0",
55
56
  "pino": "^9.2.0",
56
57
  "pixabay-api": "^1.0.4",
57
58
  "pre-commit": "^1.2.2",
@@ -133,7 +134,6 @@
133
134
  "intersection-observer": "^0.12.0",
134
135
  "jsdom": "^25.0.0",
135
136
  "msw": "^1.2.3",
136
- "patch-package": "^8.0.0",
137
137
  "prettier": "^3.2.5",
138
138
  "react": "^18.2.0",
139
139
  "react-dom": "^18.2.0",