@speakableio/core 1.0.18 → 1.0.20
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/dist/index.native.d.mts +2 -2556
- package/dist/index.native.d.ts +2 -2556
- package/dist/index.native.js +8 -2364
- package/dist/index.native.js.map +1 -1
- package/dist/index.native.mjs +31 -2387
- package/dist/index.native.mjs.map +1 -1
- package/dist/index.web.d.mts +2 -2556
- package/dist/index.web.js +31 -2387
- package/dist/index.web.js.map +1 -1
- package/package.json +1 -1
package/dist/index.native.mjs
CHANGED
|
@@ -1,37 +1,26 @@
|
|
|
1
|
-
// src/
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
permissions
|
|
25
|
-
},
|
|
26
|
-
children
|
|
27
|
-
}
|
|
28
|
-
);
|
|
29
|
-
}
|
|
30
|
-
function useSpeakableApi() {
|
|
31
|
-
const ctx = useContext(FsCtx);
|
|
32
|
-
if (!ctx) throw new Error("useSpeakableApi must be used within a SpeakableProvider");
|
|
33
|
-
return ctx;
|
|
34
|
-
}
|
|
1
|
+
// src/lib/create-firebase-client-native.ts
|
|
2
|
+
import {
|
|
3
|
+
getDoc,
|
|
4
|
+
getDocs,
|
|
5
|
+
addDoc,
|
|
6
|
+
setDoc,
|
|
7
|
+
updateDoc,
|
|
8
|
+
deleteDoc,
|
|
9
|
+
runTransaction,
|
|
10
|
+
writeBatch,
|
|
11
|
+
doc,
|
|
12
|
+
collection,
|
|
13
|
+
query,
|
|
14
|
+
serverTimestamp,
|
|
15
|
+
orderBy,
|
|
16
|
+
limit,
|
|
17
|
+
startAt,
|
|
18
|
+
startAfter,
|
|
19
|
+
endAt,
|
|
20
|
+
endBefore,
|
|
21
|
+
where,
|
|
22
|
+
increment
|
|
23
|
+
} from "@react-native-firebase/firestore";
|
|
35
24
|
|
|
36
25
|
// src/utils/error-handler.ts
|
|
37
26
|
var ServiceError = class extends Error {
|
|
@@ -341,30 +330,13 @@ var createAssignmentRepo = () => {
|
|
|
341
330
|
};
|
|
342
331
|
};
|
|
343
332
|
|
|
333
|
+
// src/providers/SpeakableProvider.tsx
|
|
334
|
+
import { createContext, useContext, useEffect, useState } from "react";
|
|
335
|
+
import { jsx } from "react/jsx-runtime";
|
|
336
|
+
var FsCtx = createContext(null);
|
|
337
|
+
|
|
344
338
|
// src/domains/assignment/hooks/assignment.hooks.ts
|
|
345
339
|
import { useQuery } from "@tanstack/react-query";
|
|
346
|
-
var assignmentQueryKeys = {
|
|
347
|
-
all: ["assignments"],
|
|
348
|
-
byId: (id) => [...assignmentQueryKeys.all, id],
|
|
349
|
-
list: () => [...assignmentQueryKeys.all, "list"]
|
|
350
|
-
};
|
|
351
|
-
function useAssignment({
|
|
352
|
-
assignmentId,
|
|
353
|
-
enabled = true,
|
|
354
|
-
analyticType,
|
|
355
|
-
userId
|
|
356
|
-
}) {
|
|
357
|
-
const { speakableApi } = useSpeakableApi();
|
|
358
|
-
return useQuery({
|
|
359
|
-
queryKey: assignmentQueryKeys.byId(assignmentId),
|
|
360
|
-
queryFn: () => speakableApi.assignmentRepo.getAssignment({
|
|
361
|
-
assignmentId,
|
|
362
|
-
analyticType,
|
|
363
|
-
currentUserId: userId
|
|
364
|
-
}),
|
|
365
|
-
enabled
|
|
366
|
-
});
|
|
367
|
-
}
|
|
368
340
|
|
|
369
341
|
// src/domains/assignment/hooks/score-hooks.ts
|
|
370
342
|
import { useMutation, useQuery as useQuery2 } from "@tanstack/react-query";
|
|
@@ -387,24 +359,6 @@ function debounce(func, waitFor) {
|
|
|
387
359
|
});
|
|
388
360
|
}
|
|
389
361
|
|
|
390
|
-
// src/lib/tanstack/handle-optimistic-update-query.ts
|
|
391
|
-
var handleOptimisticUpdate = async ({
|
|
392
|
-
queryClient,
|
|
393
|
-
queryKey,
|
|
394
|
-
newData
|
|
395
|
-
}) => {
|
|
396
|
-
await queryClient.cancelQueries({
|
|
397
|
-
queryKey
|
|
398
|
-
});
|
|
399
|
-
const previousData = queryClient.getQueryData(queryKey);
|
|
400
|
-
if (previousData === void 0) {
|
|
401
|
-
queryClient.setQueryData(queryKey, newData);
|
|
402
|
-
} else {
|
|
403
|
-
queryClient.setQueryData(queryKey, { ...previousData, ...newData });
|
|
404
|
-
}
|
|
405
|
-
return { previousData };
|
|
406
|
-
};
|
|
407
|
-
|
|
408
362
|
// src/constants/speakable-plans.ts
|
|
409
363
|
var FEEDBACK_PLANS = {
|
|
410
364
|
FEEDBACK_TRANSCRIPT: "FEEDBACK_TRANSCRIPT",
|
|
@@ -561,64 +515,9 @@ var SpeakablePlanHierarchy = [
|
|
|
561
515
|
SpeakablePlanTypes.organization
|
|
562
516
|
];
|
|
563
517
|
|
|
564
|
-
// src/hooks/usePermissions.ts
|
|
565
|
-
var usePermissions = () => {
|
|
566
|
-
const { permissions } = useSpeakableApi();
|
|
567
|
-
const has = (permission) => {
|
|
568
|
-
var _a;
|
|
569
|
-
return (_a = permissions.permissions) == null ? void 0 : _a.includes(permission);
|
|
570
|
-
};
|
|
571
|
-
return {
|
|
572
|
-
plan: permissions.plan,
|
|
573
|
-
permissionsLoaded: permissions.loaded,
|
|
574
|
-
isStripePlan: permissions.isStripePlan,
|
|
575
|
-
refreshDate: permissions.refreshDate,
|
|
576
|
-
isInstitutionPlan: permissions.isInstitutionPlan,
|
|
577
|
-
subscriptionId: permissions.subscriptionId,
|
|
578
|
-
contact: permissions.contact,
|
|
579
|
-
hasGradebook: has(ANALYTICS_PLANS.ANALYTICS_GRADEBOOK),
|
|
580
|
-
hasGoogleClassroomGradePassback: has(ASSIGNMENT_SETTINGS_PLANS.GOOGLE_CLASSROOM_GRADE_PASSBACK),
|
|
581
|
-
hasAssessments: has(ASSIGNMENT_SETTINGS_PLANS.ASSESSMENTS),
|
|
582
|
-
hasSectionAnalytics: has(ANALYTICS_PLANS.ANALYTICS_CLASSROOM_ANALYTICS),
|
|
583
|
-
hasStudentReports: has(ANALYTICS_PLANS.ANALYTICS_STUDENT_PROGRESS_REPORTS),
|
|
584
|
-
permissions: permissions || [],
|
|
585
|
-
hasStudentPortfolios: permissions.hasStudentPortfolios,
|
|
586
|
-
isFreeOrgTrial: permissions.type === "free_org_trial",
|
|
587
|
-
freeOrgTrialExpired: permissions.freeOrgTrialExpired
|
|
588
|
-
};
|
|
589
|
-
};
|
|
590
|
-
var usePermissions_default = usePermissions;
|
|
591
|
-
|
|
592
|
-
// src/domains/notification/notification.constants.ts
|
|
593
|
-
var SPEAKABLE_NOTIFICATIONS = {
|
|
594
|
-
NEW_ASSIGNMENT: "new_assignment",
|
|
595
|
-
ASSESSMENT_SUBMITTED: "assessment_submitted",
|
|
596
|
-
ASSESSMENT_SCORED: "assessment_scored",
|
|
597
|
-
NEW_COMMENT: "NEW_COMMENT"
|
|
598
|
-
};
|
|
599
|
-
var SpeakableNotificationTypes = {
|
|
600
|
-
NEW_ASSIGNMENT: "NEW_ASSIGNMENT",
|
|
601
|
-
FEEDBACK_FROM_TEACHER: "FEEDBACK_FROM_TEACHER",
|
|
602
|
-
MESSAGE_FROM_STUDENT: "MESSAGE_FROM_STUDENT",
|
|
603
|
-
PHRASE_MARKED_CORRECT: "PHRASE_MARKED_CORRECT",
|
|
604
|
-
STUDENT_PROGRESS: "STUDENT_PROGRESS",
|
|
605
|
-
PLAYLIST_FOLLOWERS: "PLAYLIST_FOLLOWERS",
|
|
606
|
-
PLAYLIST_PLAYS: "PLAYLIST_PLAYS",
|
|
607
|
-
// New notifications
|
|
608
|
-
ASSESSMENT_SUBMITTED: "ASSESSMENT_SUBMITTED",
|
|
609
|
-
// Notification FOR TEACHER when student submits assessment
|
|
610
|
-
ASSESSMENT_SCORED: "ASSESSMENT_SCORED",
|
|
611
|
-
// Notification FOR STUDENT when teacher scores assessment
|
|
612
|
-
// Comment
|
|
613
|
-
NEW_COMMENT: "NEW_COMMENT"
|
|
614
|
-
};
|
|
615
|
-
|
|
616
518
|
// src/domains/notification/services/create-notification.service.ts
|
|
617
519
|
import dayjs2 from "dayjs";
|
|
618
520
|
|
|
619
|
-
// src/constants/web.constants.ts
|
|
620
|
-
var WEB_BASE_URL = "https://app.speakable.io";
|
|
621
|
-
|
|
622
521
|
// src/domains/notification/services/send-notification.service.ts
|
|
623
522
|
var _sendNotification = async (sendTo, notification) => {
|
|
624
523
|
var _a, _b, _c;
|
|
@@ -631,202 +530,6 @@ var _sendNotification = async (sendTo, notification) => {
|
|
|
631
530
|
};
|
|
632
531
|
var sendNotification = withErrorHandler(_sendNotification, "sendNotification");
|
|
633
532
|
|
|
634
|
-
// src/domains/notification/services/create-notification.service.ts
|
|
635
|
-
var createNotification = async ({
|
|
636
|
-
data,
|
|
637
|
-
type,
|
|
638
|
-
userId,
|
|
639
|
-
profile
|
|
640
|
-
}) => {
|
|
641
|
-
let result;
|
|
642
|
-
switch (type) {
|
|
643
|
-
case SPEAKABLE_NOTIFICATIONS.NEW_ASSIGNMENT:
|
|
644
|
-
result = await handleAssignNotifPromise({ data, profile });
|
|
645
|
-
break;
|
|
646
|
-
case SPEAKABLE_NOTIFICATIONS.ASSESSMENT_SUBMITTED:
|
|
647
|
-
result = await createAssessmentSubmissionNotification({
|
|
648
|
-
data,
|
|
649
|
-
profile,
|
|
650
|
-
userId
|
|
651
|
-
});
|
|
652
|
-
break;
|
|
653
|
-
case SPEAKABLE_NOTIFICATIONS.ASSESSMENT_SCORED:
|
|
654
|
-
result = await createAssessmentScoredNotification({
|
|
655
|
-
data,
|
|
656
|
-
profile
|
|
657
|
-
});
|
|
658
|
-
break;
|
|
659
|
-
default:
|
|
660
|
-
result = null;
|
|
661
|
-
break;
|
|
662
|
-
}
|
|
663
|
-
return result;
|
|
664
|
-
};
|
|
665
|
-
var handleAssignNotifPromise = async ({
|
|
666
|
-
data: assignments,
|
|
667
|
-
profile
|
|
668
|
-
}) => {
|
|
669
|
-
if (!assignments.length) return;
|
|
670
|
-
try {
|
|
671
|
-
const notifsPromises = assignments.map(async (assignment) => {
|
|
672
|
-
const {
|
|
673
|
-
section,
|
|
674
|
-
section: { members },
|
|
675
|
-
...rest
|
|
676
|
-
} = assignment;
|
|
677
|
-
if (!section || !members) throw new Error("Invalid assignment data");
|
|
678
|
-
const data = { section, sendTo: members, assignment: { ...rest } };
|
|
679
|
-
return createNewAssignmentNotification({ data, profile });
|
|
680
|
-
});
|
|
681
|
-
await Promise.all(notifsPromises);
|
|
682
|
-
return {
|
|
683
|
-
success: true,
|
|
684
|
-
message: "Assignment notifications sent successfully"
|
|
685
|
-
};
|
|
686
|
-
} catch (error) {
|
|
687
|
-
console.error("Error in handleAssignNotifPromise:", error);
|
|
688
|
-
throw error;
|
|
689
|
-
}
|
|
690
|
-
};
|
|
691
|
-
var createNewAssignmentNotification = async ({
|
|
692
|
-
data,
|
|
693
|
-
profile
|
|
694
|
-
}) => {
|
|
695
|
-
var _a;
|
|
696
|
-
const { assignment, sendTo } = data;
|
|
697
|
-
const teacherName = profile.displayName || "Your teacher";
|
|
698
|
-
const dueDate = assignment.dueDateTimestamp ? dayjs2(assignment.dueDateTimestamp.toDate()).format("MMM Do") : null;
|
|
699
|
-
const results = await sendNotification(sendTo, {
|
|
700
|
-
courseId: assignment.courseId,
|
|
701
|
-
type: SPEAKABLE_NOTIFICATIONS.NEW_ASSIGNMENT,
|
|
702
|
-
senderName: teacherName,
|
|
703
|
-
link: `${WEB_BASE_URL}/assignment/${assignment.id}`,
|
|
704
|
-
messagePreview: `A new assignment "${assignment.name}" is now available. ${dueDate ? `Due ${dueDate}` : ""}`,
|
|
705
|
-
title: "New Assignment Available!",
|
|
706
|
-
imageUrl: (_a = profile.image) == null ? void 0 : _a.url
|
|
707
|
-
});
|
|
708
|
-
return results;
|
|
709
|
-
};
|
|
710
|
-
var createAssessmentSubmissionNotification = async ({
|
|
711
|
-
data: assignment,
|
|
712
|
-
profile,
|
|
713
|
-
userId
|
|
714
|
-
}) => {
|
|
715
|
-
var _a;
|
|
716
|
-
const studentName = profile.displayName || "Your student";
|
|
717
|
-
const results = await sendNotification(assignment.owners, {
|
|
718
|
-
courseId: assignment.courseId,
|
|
719
|
-
type: SPEAKABLE_NOTIFICATIONS.ASSESSMENT_SUBMITTED,
|
|
720
|
-
link: `${WEB_BASE_URL}/a/${assignment.id}?studentId=${userId}`,
|
|
721
|
-
title: `Assessment Submitted!`,
|
|
722
|
-
senderName: studentName,
|
|
723
|
-
messagePreview: `${studentName} has submitted the assessment "${assignment.name}"`,
|
|
724
|
-
imageUrl: (_a = profile.image) == null ? void 0 : _a.url
|
|
725
|
-
});
|
|
726
|
-
return results;
|
|
727
|
-
};
|
|
728
|
-
var createAssessmentScoredNotification = async ({
|
|
729
|
-
data,
|
|
730
|
-
profile
|
|
731
|
-
}) => {
|
|
732
|
-
var _a, _b, _c, _d, _e;
|
|
733
|
-
const { assignment, sendTo } = data;
|
|
734
|
-
const teacherName = profile.displayName || "Your teacher";
|
|
735
|
-
const title = `${assignment.isAssessment ? "Assessment" : "Assignment"} Reviewed!`;
|
|
736
|
-
const messagePreview = `Your ${assignment.isAssessment ? "assessment" : "assignment"} has been reviewed by your teacher. Click to view the feedback.`;
|
|
737
|
-
const results = await sendNotification(sendTo, {
|
|
738
|
-
courseId: assignment.courseId,
|
|
739
|
-
type: SPEAKABLE_NOTIFICATIONS.ASSESSMENT_SCORED,
|
|
740
|
-
link: `${WEB_BASE_URL}/assignment/${assignment.id}`,
|
|
741
|
-
title,
|
|
742
|
-
messagePreview,
|
|
743
|
-
imageUrl: (_a = profile.image) == null ? void 0 : _a.url,
|
|
744
|
-
senderName: teacherName
|
|
745
|
-
});
|
|
746
|
-
await ((_e = (_c = (_b = api).httpsCallable) == null ? void 0 : _c.call(_b, "sendAssessmentScoredEmail")) == null ? void 0 : _e({
|
|
747
|
-
assessmentTitle: assignment.name,
|
|
748
|
-
link: `${WEB_BASE_URL}/assignment/${assignment.id}`,
|
|
749
|
-
senderImage: ((_d = profile.image) == null ? void 0 : _d.url) || "",
|
|
750
|
-
studentId: sendTo[0],
|
|
751
|
-
teacherName: profile.displayName
|
|
752
|
-
}));
|
|
753
|
-
return results;
|
|
754
|
-
};
|
|
755
|
-
|
|
756
|
-
// src/domains/notification/hooks/notification.hooks.ts
|
|
757
|
-
var notificationQueryKeys = {
|
|
758
|
-
all: ["notifications"],
|
|
759
|
-
byId: (id) => [...notificationQueryKeys.all, id]
|
|
760
|
-
};
|
|
761
|
-
var useCreateNotification = () => {
|
|
762
|
-
const { user, queryClient } = useSpeakableApi();
|
|
763
|
-
const handleCreateNotifications = async (type, data) => {
|
|
764
|
-
var _a, _b;
|
|
765
|
-
const result = await createNotification({
|
|
766
|
-
type,
|
|
767
|
-
userId: user.auth.uid,
|
|
768
|
-
profile: (_a = user == null ? void 0 : user.profile) != null ? _a : {},
|
|
769
|
-
data
|
|
770
|
-
});
|
|
771
|
-
queryClient.invalidateQueries({
|
|
772
|
-
queryKey: notificationQueryKeys.byId((_b = user == null ? void 0 : user.auth.uid) != null ? _b : "")
|
|
773
|
-
});
|
|
774
|
-
return result;
|
|
775
|
-
};
|
|
776
|
-
return {
|
|
777
|
-
createNotification: handleCreateNotifications
|
|
778
|
-
};
|
|
779
|
-
};
|
|
780
|
-
|
|
781
|
-
// src/hooks/useGoogleClassroom.ts
|
|
782
|
-
var useGoogleClassroom = () => {
|
|
783
|
-
const submitAssignmentToGoogleClassroom = async ({
|
|
784
|
-
assignment,
|
|
785
|
-
scores,
|
|
786
|
-
googleUserId = null
|
|
787
|
-
// optional to override the user's googleUserId
|
|
788
|
-
}) => {
|
|
789
|
-
var _a, _b, _c;
|
|
790
|
-
try {
|
|
791
|
-
const { googleClassroomUserId = null } = scores;
|
|
792
|
-
const googleId = googleUserId || googleClassroomUserId;
|
|
793
|
-
if (!googleId)
|
|
794
|
-
return {
|
|
795
|
-
error: true,
|
|
796
|
-
message: "No Google Classroom ID found"
|
|
797
|
-
};
|
|
798
|
-
const { courseWorkId, maxPoints, owners, courseId } = assignment;
|
|
799
|
-
const draftGrade = (scores == null ? void 0 : scores.score) ? (scores == null ? void 0 : scores.score) / 100 * maxPoints : 0;
|
|
800
|
-
const result = await ((_c = (_b = (_a = api).httpsCallable) == null ? void 0 : _b.call(_a, "submitAssignmentToGoogleClassroomV2")) == null ? void 0 : _c({
|
|
801
|
-
teacherId: owners[0],
|
|
802
|
-
courseId,
|
|
803
|
-
courseWorkId,
|
|
804
|
-
userId: googleId,
|
|
805
|
-
draftGrade
|
|
806
|
-
}));
|
|
807
|
-
return result;
|
|
808
|
-
} catch (error) {
|
|
809
|
-
return { error: true, message: error.message };
|
|
810
|
-
}
|
|
811
|
-
};
|
|
812
|
-
return {
|
|
813
|
-
submitAssignmentToGoogleClassroom
|
|
814
|
-
};
|
|
815
|
-
};
|
|
816
|
-
|
|
817
|
-
// src/lib/firebase/firebase-analytics/grading-standard.ts
|
|
818
|
-
var logGradingStandardLog = (data) => {
|
|
819
|
-
var _a, _b, _c;
|
|
820
|
-
if (data.courseId && data.type && data.level) {
|
|
821
|
-
(_c = (_b = (_a = api).httpsCallable) == null ? void 0 : _b.call(_a, "handleCouresAnalyticsEvent")) == null ? void 0 : _c({
|
|
822
|
-
eventType: data.type || "custom",
|
|
823
|
-
level: data.level,
|
|
824
|
-
courseId: data.courseId
|
|
825
|
-
});
|
|
826
|
-
}
|
|
827
|
-
api.logEvent("logGradingStandard", data);
|
|
828
|
-
};
|
|
829
|
-
|
|
830
533
|
// src/constants/analytics.constants.ts
|
|
831
534
|
var ANALYTICS_EVENT_TYPES = {
|
|
832
535
|
VOICE_SUCCESS: "voice_success",
|
|
@@ -866,20 +569,6 @@ var ANALYTICS_EVENT_TYPES = {
|
|
|
866
569
|
};
|
|
867
570
|
|
|
868
571
|
// src/lib/firebase/firebase-analytics/assignment.ts
|
|
869
|
-
var logOpenAssignment = (data = {}) => {
|
|
870
|
-
api.logEvent("open_assignment", data);
|
|
871
|
-
};
|
|
872
|
-
var logOpenActivityPreview = (data = {}) => {
|
|
873
|
-
api.logEvent("open_activity_preview", data);
|
|
874
|
-
};
|
|
875
|
-
var logSubmitAssignment = (data = {}) => {
|
|
876
|
-
var _a, _b, _c;
|
|
877
|
-
(_c = (_b = (_a = api).httpsCallable) == null ? void 0 : _b.call(_a, "handleCouresAnalyticsEvent")) == null ? void 0 : _c({
|
|
878
|
-
eventType: ANALYTICS_EVENT_TYPES.SUBMISSION,
|
|
879
|
-
...data
|
|
880
|
-
});
|
|
881
|
-
api.logEvent(ANALYTICS_EVENT_TYPES.SUBMISSION, data);
|
|
882
|
-
};
|
|
883
572
|
var logStartAssignment = (data = {}) => {
|
|
884
573
|
var _a, _b, _c;
|
|
885
574
|
if (data.courseId) {
|
|
@@ -1122,72 +811,6 @@ var updateCardScore = withErrorHandler(_updateCardScore, "updateCardScore");
|
|
|
1122
811
|
|
|
1123
812
|
// src/domains/assignment/services/clear-score.service.ts
|
|
1124
813
|
import dayjs3 from "dayjs";
|
|
1125
|
-
async function clearScore(params) {
|
|
1126
|
-
var _a, _b, _c, _d, _e;
|
|
1127
|
-
const update = {
|
|
1128
|
-
[`cards.${params.cardId}`]: {
|
|
1129
|
-
attempts: ((_a = params.cardScores.attempts) != null ? _a : 1) + 1,
|
|
1130
|
-
correct: (_b = params.cardScores.correct) != null ? _b : 0,
|
|
1131
|
-
// save old score history
|
|
1132
|
-
history: [
|
|
1133
|
-
{
|
|
1134
|
-
...params.cardScores,
|
|
1135
|
-
attempts: (_c = params.cardScores.attempts) != null ? _c : 1,
|
|
1136
|
-
correct: (_d = params.cardScores.correct) != null ? _d : 0,
|
|
1137
|
-
retryTime: dayjs3().format("YYYY-MM-DD HH:mm:ss"),
|
|
1138
|
-
history: null
|
|
1139
|
-
},
|
|
1140
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
1141
|
-
...(_e = params.cardScores.history) != null ? _e : []
|
|
1142
|
-
]
|
|
1143
|
-
}
|
|
1144
|
-
};
|
|
1145
|
-
const path = params.isAssignment ? refsAssignmentFiresotre.assignmentScores({
|
|
1146
|
-
id: params.activityId,
|
|
1147
|
-
userId: params.userId
|
|
1148
|
-
}) : refsScoresPractice.practiceScores({
|
|
1149
|
-
setId: params.activityId,
|
|
1150
|
-
userId: params.userId
|
|
1151
|
-
});
|
|
1152
|
-
await api.updateDoc(path, update);
|
|
1153
|
-
return {
|
|
1154
|
-
update,
|
|
1155
|
-
activityId: params.activityId
|
|
1156
|
-
};
|
|
1157
|
-
}
|
|
1158
|
-
async function clearScoreV2(params) {
|
|
1159
|
-
var _a, _b, _c, _d, _e;
|
|
1160
|
-
const update = {
|
|
1161
|
-
[`cards.${params.cardId}`]: {
|
|
1162
|
-
...params.cardScores,
|
|
1163
|
-
attempts: ((_a = params.cardScores.attempts) != null ? _a : 1) + 1,
|
|
1164
|
-
correct: (_b = params.cardScores.correct) != null ? _b : 0,
|
|
1165
|
-
history: [
|
|
1166
|
-
{
|
|
1167
|
-
...params.cardScores,
|
|
1168
|
-
attempts: (_c = params.cardScores.attempts) != null ? _c : 1,
|
|
1169
|
-
correct: (_d = params.cardScores.correct) != null ? _d : 0,
|
|
1170
|
-
retryTime: dayjs3().format("YYYY-MM-DD HH:mm:ss"),
|
|
1171
|
-
history: null
|
|
1172
|
-
},
|
|
1173
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
1174
|
-
...(_e = params.cardScores.history) != null ? _e : []
|
|
1175
|
-
]
|
|
1176
|
-
}
|
|
1177
|
-
};
|
|
1178
|
-
const path = params.isAssignment ? refsAssignmentFiresotre.assignmentScores({
|
|
1179
|
-
id: params.activityId,
|
|
1180
|
-
userId: params.userId
|
|
1181
|
-
}) : refsScoresPractice.practiceScores({
|
|
1182
|
-
setId: params.activityId,
|
|
1183
|
-
userId: params.userId
|
|
1184
|
-
});
|
|
1185
|
-
await api.updateDoc(path, update);
|
|
1186
|
-
return {
|
|
1187
|
-
update,
|
|
1188
|
-
activityId: params.activityId
|
|
1189
|
-
};
|
|
1190
|
-
}
|
|
1191
814
|
|
|
1192
815
|
// src/domains/assignment/services/submit-assignment-score.service.ts
|
|
1193
816
|
import dayjs4 from "dayjs";
|
|
@@ -1253,465 +876,15 @@ async function handleCourseAssignment(assignment, userId) {
|
|
|
1253
876
|
userId
|
|
1254
877
|
}));
|
|
1255
878
|
}
|
|
1256
|
-
async function submitPracticeScore({
|
|
1257
|
-
setId,
|
|
1258
|
-
userId,
|
|
1259
|
-
scores
|
|
1260
|
-
}) {
|
|
1261
|
-
const { serverTimestamp: serverTimestamp2 } = api.accessHelpers();
|
|
1262
|
-
const date = dayjs4().format("YYYY-MM-DD-HH-mm");
|
|
1263
|
-
const ref = refsScoresPractice.practiceScoreHistoryRefDoc({ setId, userId, date });
|
|
1264
|
-
const fieldsUpdated = {
|
|
1265
|
-
...scores,
|
|
1266
|
-
submitted: true,
|
|
1267
|
-
progress: 100,
|
|
1268
|
-
submissionDate: serverTimestamp2(),
|
|
1269
|
-
status: "SUBMITTED"
|
|
1270
|
-
};
|
|
1271
|
-
await api.setDoc(ref, { ...fieldsUpdated });
|
|
1272
|
-
const refScores = refsScoresPractice.practiceScores({ userId, setId });
|
|
1273
|
-
await api.deleteDoc(refScores);
|
|
1274
|
-
return { success: true, fieldsUpdated };
|
|
1275
|
-
}
|
|
1276
879
|
|
|
1277
880
|
// src/domains/assignment/hooks/score-hooks.ts
|
|
1278
|
-
var scoreQueryKeys = {
|
|
1279
|
-
all: ["scores"],
|
|
1280
|
-
byId: (id) => [...scoreQueryKeys.all, id],
|
|
1281
|
-
list: () => [...scoreQueryKeys.all, "list"]
|
|
1282
|
-
};
|
|
1283
|
-
function useScore({
|
|
1284
|
-
isAssignment,
|
|
1285
|
-
activityId,
|
|
1286
|
-
userId = "",
|
|
1287
|
-
courseId,
|
|
1288
|
-
enabled = true,
|
|
1289
|
-
googleClassroomUserId
|
|
1290
|
-
}) {
|
|
1291
|
-
return useQuery2({
|
|
1292
|
-
queryFn: () => getScore({
|
|
1293
|
-
userId,
|
|
1294
|
-
courseId,
|
|
1295
|
-
activityId,
|
|
1296
|
-
googleClassroomUserId,
|
|
1297
|
-
isAssignment
|
|
1298
|
-
}),
|
|
1299
|
-
queryKey: scoreQueryKeys.byId(activityId),
|
|
1300
|
-
enabled
|
|
1301
|
-
});
|
|
1302
|
-
}
|
|
1303
881
|
var debounceUpdateScore = debounce(updateScore, 500);
|
|
1304
|
-
function useUpdateScore() {
|
|
1305
|
-
const { queryClient } = useSpeakableApi();
|
|
1306
|
-
const mutation = useMutation({
|
|
1307
|
-
mutationFn: debounceUpdateScore,
|
|
1308
|
-
onMutate: (variables) => {
|
|
1309
|
-
return handleOptimisticUpdate({
|
|
1310
|
-
queryClient,
|
|
1311
|
-
queryKey: scoreQueryKeys.byId(variables.activityId),
|
|
1312
|
-
newData: variables.data
|
|
1313
|
-
});
|
|
1314
|
-
},
|
|
1315
|
-
onError: (_, variables, context) => {
|
|
1316
|
-
if (context == null ? void 0 : context.previousData)
|
|
1317
|
-
queryClient.setQueryData(scoreQueryKeys.byId(variables.activityId), context.previousData);
|
|
1318
|
-
},
|
|
1319
|
-
onSettled: (_, err, variables) => {
|
|
1320
|
-
queryClient.invalidateQueries({
|
|
1321
|
-
queryKey: scoreQueryKeys.byId(variables.activityId)
|
|
1322
|
-
});
|
|
1323
|
-
}
|
|
1324
|
-
});
|
|
1325
|
-
return {
|
|
1326
|
-
mutationUpdateScore: mutation
|
|
1327
|
-
};
|
|
1328
|
-
}
|
|
1329
|
-
function useUpdateCardScore({
|
|
1330
|
-
isAssignment,
|
|
1331
|
-
activityId,
|
|
1332
|
-
userId,
|
|
1333
|
-
cardIds,
|
|
1334
|
-
weights
|
|
1335
|
-
}) {
|
|
1336
|
-
const { queryClient } = useSpeakableApi();
|
|
1337
|
-
const queryKey = scoreQueryKeys.byId(activityId);
|
|
1338
|
-
const mutation = useMutation({
|
|
1339
|
-
mutationFn: async ({ cardId, cardScore }) => {
|
|
1340
|
-
const previousScores = queryClient.getQueryData(queryKey);
|
|
1341
|
-
const { progress, score, newScoreUpdated, updatedCardScore } = getScoreUpdated({
|
|
1342
|
-
previousScores: previousScores != null ? previousScores : {},
|
|
1343
|
-
cardId,
|
|
1344
|
-
cardScore,
|
|
1345
|
-
cardIds,
|
|
1346
|
-
weights
|
|
1347
|
-
});
|
|
1348
|
-
console.log("updates", {
|
|
1349
|
-
cardScore: updatedCardScore,
|
|
1350
|
-
progress,
|
|
1351
|
-
score
|
|
1352
|
-
});
|
|
1353
|
-
await updateCardScore({
|
|
1354
|
-
userId,
|
|
1355
|
-
cardId,
|
|
1356
|
-
isAssignment,
|
|
1357
|
-
activityId,
|
|
1358
|
-
updates: {
|
|
1359
|
-
cardScore: updatedCardScore,
|
|
1360
|
-
progress,
|
|
1361
|
-
score
|
|
1362
|
-
}
|
|
1363
|
-
});
|
|
1364
|
-
return { cardId, scoresUpdated: newScoreUpdated };
|
|
1365
|
-
},
|
|
1366
|
-
onMutate: ({ cardId, cardScore }) => {
|
|
1367
|
-
const previousData = queryClient.getQueryData(queryKey);
|
|
1368
|
-
queryClient.setQueryData(queryKey, (previousScore) => {
|
|
1369
|
-
const updates = handleOptimisticScore({
|
|
1370
|
-
score: previousScore,
|
|
1371
|
-
cardId,
|
|
1372
|
-
cardScore,
|
|
1373
|
-
cardIds,
|
|
1374
|
-
weights
|
|
1375
|
-
});
|
|
1376
|
-
return {
|
|
1377
|
-
...previousScore,
|
|
1378
|
-
...updates
|
|
1379
|
-
};
|
|
1380
|
-
});
|
|
1381
|
-
return { previousData };
|
|
1382
|
-
},
|
|
1383
|
-
onError: (error, variables, context) => {
|
|
1384
|
-
console.log("Error updating card score:", error.message);
|
|
1385
|
-
if (context == null ? void 0 : context.previousData) {
|
|
1386
|
-
queryClient.setQueryData(queryKey, context.previousData);
|
|
1387
|
-
}
|
|
1388
|
-
},
|
|
1389
|
-
onSettled: () => {
|
|
1390
|
-
queryClient.invalidateQueries({
|
|
1391
|
-
queryKey
|
|
1392
|
-
});
|
|
1393
|
-
}
|
|
1394
|
-
});
|
|
1395
|
-
return {
|
|
1396
|
-
mutationUpdateCardScore: mutation
|
|
1397
|
-
};
|
|
1398
|
-
}
|
|
1399
|
-
var getScoreUpdated = ({
|
|
1400
|
-
cardId,
|
|
1401
|
-
cardScore,
|
|
1402
|
-
previousScores,
|
|
1403
|
-
cardIds,
|
|
1404
|
-
weights
|
|
1405
|
-
}) => {
|
|
1406
|
-
var _a, _b;
|
|
1407
|
-
const previousCard = (_a = previousScores.cards) == null ? void 0 : _a[cardId];
|
|
1408
|
-
const newCardScore = {
|
|
1409
|
-
...previousCard != null ? previousCard : {},
|
|
1410
|
-
...cardScore
|
|
1411
|
-
};
|
|
1412
|
-
const newScores = {
|
|
1413
|
-
...previousScores,
|
|
1414
|
-
cards: {
|
|
1415
|
-
...(_b = previousScores.cards) != null ? _b : {},
|
|
1416
|
-
[cardId]: newCardScore
|
|
1417
|
-
}
|
|
1418
|
-
};
|
|
1419
|
-
console.log("newScores", newScores, cardIds, weights);
|
|
1420
|
-
const { score, progress } = calculateScoreAndProgress_default(newScores, cardIds, weights);
|
|
1421
|
-
console.log("score and progress", score, progress);
|
|
1422
|
-
return {
|
|
1423
|
-
newScoreUpdated: newScores,
|
|
1424
|
-
updatedCardScore: cardScore,
|
|
1425
|
-
score,
|
|
1426
|
-
progress
|
|
1427
|
-
};
|
|
1428
|
-
};
|
|
1429
|
-
var handleOptimisticScore = ({
|
|
1430
|
-
score,
|
|
1431
|
-
cardId,
|
|
1432
|
-
cardScore,
|
|
1433
|
-
cardIds,
|
|
1434
|
-
weights
|
|
1435
|
-
}) => {
|
|
1436
|
-
var _a;
|
|
1437
|
-
let cards = { ...(_a = score == null ? void 0 : score.cards) != null ? _a : {} };
|
|
1438
|
-
cards = {
|
|
1439
|
-
...cards,
|
|
1440
|
-
[cardId]: {
|
|
1441
|
-
...cards[cardId],
|
|
1442
|
-
...cardScore
|
|
1443
|
-
}
|
|
1444
|
-
};
|
|
1445
|
-
const { score: scoreValue, progress } = calculateScoreAndProgress_default(
|
|
1446
|
-
// @ts-ignore
|
|
1447
|
-
{
|
|
1448
|
-
...score != null ? score : {},
|
|
1449
|
-
cards
|
|
1450
|
-
},
|
|
1451
|
-
cardIds,
|
|
1452
|
-
weights
|
|
1453
|
-
);
|
|
1454
|
-
return { cards, score: scoreValue, progress };
|
|
1455
|
-
};
|
|
1456
|
-
function useClearScore() {
|
|
1457
|
-
const { queryClient } = useSpeakableApi();
|
|
1458
|
-
const mutation = useMutation({
|
|
1459
|
-
mutationFn: clearScore,
|
|
1460
|
-
onError: (error) => {
|
|
1461
|
-
console.log("Error clearing score:", error.message);
|
|
1462
|
-
},
|
|
1463
|
-
onSettled: (result) => {
|
|
1464
|
-
var _a;
|
|
1465
|
-
queryClient.invalidateQueries({
|
|
1466
|
-
queryKey: scoreQueryKeys.byId((_a = result == null ? void 0 : result.activityId) != null ? _a : "")
|
|
1467
|
-
});
|
|
1468
|
-
}
|
|
1469
|
-
});
|
|
1470
|
-
return {
|
|
1471
|
-
mutationClearScore: mutation
|
|
1472
|
-
};
|
|
1473
|
-
}
|
|
1474
|
-
function useClearScoreV2() {
|
|
1475
|
-
const { queryClient } = useSpeakableApi();
|
|
1476
|
-
const mutation = useMutation({
|
|
1477
|
-
mutationFn: clearScoreV2,
|
|
1478
|
-
onError: (error) => {
|
|
1479
|
-
console.log("Error clearing score V2:", error.message);
|
|
1480
|
-
},
|
|
1481
|
-
onSettled: (result) => {
|
|
1482
|
-
var _a;
|
|
1483
|
-
queryClient.invalidateQueries({
|
|
1484
|
-
queryKey: scoreQueryKeys.byId((_a = result == null ? void 0 : result.activityId) != null ? _a : "")
|
|
1485
|
-
});
|
|
1486
|
-
}
|
|
1487
|
-
});
|
|
1488
|
-
return {
|
|
1489
|
-
mutationClearScore: mutation
|
|
1490
|
-
};
|
|
1491
|
-
}
|
|
1492
|
-
function useSubmitAssignmentScore({
|
|
1493
|
-
onAssignmentSubmitted,
|
|
1494
|
-
studentName
|
|
1495
|
-
}) {
|
|
1496
|
-
const { queryClient } = useSpeakableApi();
|
|
1497
|
-
const { hasGoogleClassroomGradePassback } = usePermissions_default();
|
|
1498
|
-
const { submitAssignmentToGoogleClassroom } = useGoogleClassroom();
|
|
1499
|
-
const { createNotification: createNotification2 } = useCreateNotification();
|
|
1500
|
-
const mutation = useMutation({
|
|
1501
|
-
mutationFn: async ({
|
|
1502
|
-
assignment,
|
|
1503
|
-
userId,
|
|
1504
|
-
cardIds,
|
|
1505
|
-
weights,
|
|
1506
|
-
scores,
|
|
1507
|
-
status
|
|
1508
|
-
}) => {
|
|
1509
|
-
try {
|
|
1510
|
-
const scoreUpdated = await submitAssignmentScore({
|
|
1511
|
-
assignment,
|
|
1512
|
-
userId,
|
|
1513
|
-
cardIds,
|
|
1514
|
-
weights,
|
|
1515
|
-
status,
|
|
1516
|
-
studentName
|
|
1517
|
-
});
|
|
1518
|
-
if (assignment.courseWorkId != null && !assignment.isAssessment && hasGoogleClassroomGradePassback) {
|
|
1519
|
-
await submitAssignmentToGoogleClassroom({
|
|
1520
|
-
assignment,
|
|
1521
|
-
scores
|
|
1522
|
-
});
|
|
1523
|
-
}
|
|
1524
|
-
if (assignment.isAssessment) {
|
|
1525
|
-
createNotification2(SpeakableNotificationTypes.ASSESSMENT_SUBMITTED, assignment);
|
|
1526
|
-
}
|
|
1527
|
-
if (assignment == null ? void 0 : assignment.id) {
|
|
1528
|
-
logSubmitAssignment({
|
|
1529
|
-
courseId: assignment == null ? void 0 : assignment.courseId
|
|
1530
|
-
});
|
|
1531
|
-
}
|
|
1532
|
-
onAssignmentSubmitted(assignment.id);
|
|
1533
|
-
queryClient.setQueryData(scoreQueryKeys.byId(assignment.id), {
|
|
1534
|
-
...scores,
|
|
1535
|
-
...scoreUpdated.fieldsUpdated
|
|
1536
|
-
});
|
|
1537
|
-
return {
|
|
1538
|
-
success: true,
|
|
1539
|
-
message: "Score submitted successfully"
|
|
1540
|
-
};
|
|
1541
|
-
} catch (error) {
|
|
1542
|
-
return {
|
|
1543
|
-
success: false,
|
|
1544
|
-
error
|
|
1545
|
-
};
|
|
1546
|
-
}
|
|
1547
|
-
}
|
|
1548
|
-
});
|
|
1549
|
-
return {
|
|
1550
|
-
submitAssignmentScore: mutation.mutateAsync,
|
|
1551
|
-
isLoading: mutation.isPending
|
|
1552
|
-
};
|
|
1553
|
-
}
|
|
1554
|
-
function useSubmitPracticeScore() {
|
|
1555
|
-
const { queryClient } = useSpeakableApi();
|
|
1556
|
-
const mutation = useMutation({
|
|
1557
|
-
mutationFn: async ({
|
|
1558
|
-
setId,
|
|
1559
|
-
userId,
|
|
1560
|
-
scores
|
|
1561
|
-
}) => {
|
|
1562
|
-
try {
|
|
1563
|
-
await submitPracticeScore({
|
|
1564
|
-
setId,
|
|
1565
|
-
userId,
|
|
1566
|
-
scores
|
|
1567
|
-
});
|
|
1568
|
-
queryClient.invalidateQueries({
|
|
1569
|
-
queryKey: scoreQueryKeys.byId(setId)
|
|
1570
|
-
});
|
|
1571
|
-
return {
|
|
1572
|
-
success: true,
|
|
1573
|
-
message: "Score submitted successfully"
|
|
1574
|
-
};
|
|
1575
|
-
} catch (error) {
|
|
1576
|
-
return {
|
|
1577
|
-
success: false,
|
|
1578
|
-
error
|
|
1579
|
-
};
|
|
1580
|
-
}
|
|
1581
|
-
}
|
|
1582
|
-
});
|
|
1583
|
-
return {
|
|
1584
|
-
submitPracticeScore: mutation.mutateAsync,
|
|
1585
|
-
isLoading: mutation.isPending
|
|
1586
|
-
};
|
|
1587
|
-
}
|
|
1588
882
|
|
|
1589
883
|
// src/domains/cards/card.hooks.ts
|
|
1590
884
|
import { useMutation as useMutation2, useQueries, useQuery as useQuery3 } from "@tanstack/react-query";
|
|
1591
885
|
import { useMemo } from "react";
|
|
1592
886
|
|
|
1593
|
-
// src/domains/cards/card.model.ts
|
|
1594
|
-
var ActivityPageType = /* @__PURE__ */ ((ActivityPageType2) => {
|
|
1595
|
-
ActivityPageType2["READ_REPEAT"] = "READ_REPEAT";
|
|
1596
|
-
ActivityPageType2["READ_RESPOND"] = "READ_RESPOND";
|
|
1597
|
-
ActivityPageType2["FREE_RESPONSE"] = "FREE_RESPONSE";
|
|
1598
|
-
ActivityPageType2["REPEAT"] = "REPEAT";
|
|
1599
|
-
ActivityPageType2["RESPOND"] = "RESPOND";
|
|
1600
|
-
ActivityPageType2["RESPOND_WRITE"] = "RESPOND_WRITE";
|
|
1601
|
-
ActivityPageType2["MULTIPLE_CHOICE"] = "MULTIPLE_CHOICE";
|
|
1602
|
-
ActivityPageType2["MEDIA_PAGE"] = "MEDIA_PAGE";
|
|
1603
|
-
ActivityPageType2["SHORT_ANSWER"] = "SHORT_ANSWER";
|
|
1604
|
-
return ActivityPageType2;
|
|
1605
|
-
})(ActivityPageType || {});
|
|
1606
|
-
var RESPOND_PAGE_ACTIVITY_TYPES = [
|
|
1607
|
-
"READ_RESPOND" /* READ_RESPOND */,
|
|
1608
|
-
"RESPOND" /* RESPOND */,
|
|
1609
|
-
"RESPOND_WRITE" /* RESPOND_WRITE */,
|
|
1610
|
-
"FREE_RESPONSE" /* FREE_RESPONSE */
|
|
1611
|
-
];
|
|
1612
|
-
var MULTIPLE_CHOICE_PAGE_ACTIVITY_TYPES = ["MULTIPLE_CHOICE" /* MULTIPLE_CHOICE */];
|
|
1613
|
-
var REPEAT_PAGE_ACTIVITY_TYPES = ["READ_REPEAT" /* READ_REPEAT */, "REPEAT" /* REPEAT */];
|
|
1614
|
-
var RESPOND_WRITE_PAGE_ACTIVITY_TYPES = [
|
|
1615
|
-
"RESPOND_WRITE" /* RESPOND_WRITE */,
|
|
1616
|
-
"FREE_RESPONSE" /* FREE_RESPONSE */
|
|
1617
|
-
];
|
|
1618
|
-
var RESPOND_AUDIO_PAGE_ACTIVITY_TYPES = [
|
|
1619
|
-
"RESPOND" /* RESPOND */,
|
|
1620
|
-
"READ_RESPOND" /* READ_RESPOND */
|
|
1621
|
-
];
|
|
1622
|
-
|
|
1623
887
|
// src/domains/cards/card.constants.ts
|
|
1624
|
-
var FeedbackTypesCard = /* @__PURE__ */ ((FeedbackTypesCard2) => {
|
|
1625
|
-
FeedbackTypesCard2["SuggestedResponse"] = "suggested_response";
|
|
1626
|
-
FeedbackTypesCard2["Wida"] = "wida";
|
|
1627
|
-
FeedbackTypesCard2["GrammarInsights"] = "grammar_insights";
|
|
1628
|
-
FeedbackTypesCard2["Actfl"] = "actfl";
|
|
1629
|
-
FeedbackTypesCard2["ProficiencyLevel"] = "proficiency_level";
|
|
1630
|
-
return FeedbackTypesCard2;
|
|
1631
|
-
})(FeedbackTypesCard || {});
|
|
1632
|
-
var LeniencyCard = /* @__PURE__ */ ((LeniencyCard2) => {
|
|
1633
|
-
LeniencyCard2["CONFIDENCE"] = "confidence";
|
|
1634
|
-
LeniencyCard2["EASY"] = "easy";
|
|
1635
|
-
LeniencyCard2["NORMAL"] = "normal";
|
|
1636
|
-
LeniencyCard2["HARD"] = "hard";
|
|
1637
|
-
return LeniencyCard2;
|
|
1638
|
-
})(LeniencyCard || {});
|
|
1639
|
-
var LENIENCY_OPTIONS = [
|
|
1640
|
-
{
|
|
1641
|
-
label: "Build Confidence - most lenient",
|
|
1642
|
-
value: "confidence" /* CONFIDENCE */
|
|
1643
|
-
},
|
|
1644
|
-
{
|
|
1645
|
-
label: "Very Lenient",
|
|
1646
|
-
value: "easy" /* EASY */
|
|
1647
|
-
},
|
|
1648
|
-
{
|
|
1649
|
-
label: "Normal",
|
|
1650
|
-
value: "normal" /* NORMAL */
|
|
1651
|
-
},
|
|
1652
|
-
{
|
|
1653
|
-
label: "No leniency - most strict",
|
|
1654
|
-
value: "hard" /* HARD */
|
|
1655
|
-
}
|
|
1656
|
-
];
|
|
1657
|
-
var STUDENT_LEVELS_OPTIONS = [
|
|
1658
|
-
{
|
|
1659
|
-
label: "Beginner",
|
|
1660
|
-
description: "Beginner Level: Just starting out. Can say a few basic words and phrases.",
|
|
1661
|
-
value: "beginner"
|
|
1662
|
-
},
|
|
1663
|
-
{
|
|
1664
|
-
label: "Elementary",
|
|
1665
|
-
description: "Elementary Level: Can understand simple sentences and have very basic conversations.",
|
|
1666
|
-
value: "elementary"
|
|
1667
|
-
},
|
|
1668
|
-
{
|
|
1669
|
-
label: "Intermediate",
|
|
1670
|
-
description: "Intermediate Level: Can talk about everyday topics and handle common situations.",
|
|
1671
|
-
value: "intermediate"
|
|
1672
|
-
},
|
|
1673
|
-
{
|
|
1674
|
-
label: "Advanced",
|
|
1675
|
-
description: "Advanced Level: Can speak and understand with ease, and explain ideas clearly.",
|
|
1676
|
-
value: "advanced"
|
|
1677
|
-
},
|
|
1678
|
-
{
|
|
1679
|
-
label: "Fluent",
|
|
1680
|
-
description: "Fluent Level: Speaks naturally and easily. Can use the language in work or school settings.",
|
|
1681
|
-
value: "fluent"
|
|
1682
|
-
},
|
|
1683
|
-
{
|
|
1684
|
-
label: "Native-like",
|
|
1685
|
-
description: "Native-like Level: Understands and speaks like a native. Can discuss complex ideas accurately.",
|
|
1686
|
-
value: "nativeLike"
|
|
1687
|
-
}
|
|
1688
|
-
];
|
|
1689
|
-
var BASE_RESPOND_FIELD_VALUES = {
|
|
1690
|
-
title: "",
|
|
1691
|
-
allowRetries: true,
|
|
1692
|
-
respondTime: 180,
|
|
1693
|
-
maxCharacters: 1e3
|
|
1694
|
-
};
|
|
1695
|
-
var BASE_REPEAT_FIELD_VALUES = {
|
|
1696
|
-
repeat: 1
|
|
1697
|
-
};
|
|
1698
|
-
var BASE_MULTIPLE_CHOICE_FIELD_VALUES = {
|
|
1699
|
-
MCQType: "single",
|
|
1700
|
-
answer: ["A"],
|
|
1701
|
-
choices: [
|
|
1702
|
-
{ option: "A", value: "Option A" },
|
|
1703
|
-
{ option: "B", value: "Option B" },
|
|
1704
|
-
{ option: "C", value: "Option C" }
|
|
1705
|
-
]
|
|
1706
|
-
};
|
|
1707
|
-
var VerificationCardStatus = /* @__PURE__ */ ((VerificationCardStatus2) => {
|
|
1708
|
-
VerificationCardStatus2["VERIFIED"] = "VERIFIED";
|
|
1709
|
-
VerificationCardStatus2["WARNING"] = "WARNING";
|
|
1710
|
-
VerificationCardStatus2["NOT_RECOMMENDED"] = "NOT_RECOMMENDED";
|
|
1711
|
-
VerificationCardStatus2["NOT_WORKING"] = "NOT_WORKING";
|
|
1712
|
-
VerificationCardStatus2["NOT_CHECKED"] = "NOT_CHECKED";
|
|
1713
|
-
return VerificationCardStatus2;
|
|
1714
|
-
})(VerificationCardStatus || {});
|
|
1715
888
|
var CARDS_COLLECTION = "flashcards";
|
|
1716
889
|
var refsCardsFiresotre = {
|
|
1717
890
|
allCards: CARDS_COLLECTION,
|
|
@@ -1758,13 +931,6 @@ var getWordHash = (word, language) => {
|
|
|
1758
931
|
console.log("wordHash core library", wordHash);
|
|
1759
932
|
return wordHash;
|
|
1760
933
|
};
|
|
1761
|
-
function getPhraseLength(phrase, input) {
|
|
1762
|
-
if (Array.isArray(phrase) && phrase.includes(input)) {
|
|
1763
|
-
return phrase[phrase.indexOf(input)].split(" ").length;
|
|
1764
|
-
} else {
|
|
1765
|
-
return phrase ? phrase.split(" ").length : 0;
|
|
1766
|
-
}
|
|
1767
|
-
}
|
|
1768
934
|
|
|
1769
935
|
// src/domains/cards/services/get-card-verification-status.service.ts
|
|
1770
936
|
var charactarLanguages = ["zh", "ja", "ko"];
|
|
@@ -1835,83 +1001,8 @@ async function _createCards({ cards }) {
|
|
|
1835
1001
|
}
|
|
1836
1002
|
var createCards = withErrorHandler(_createCards, "createCards");
|
|
1837
1003
|
|
|
1838
|
-
// src/domains/cards/card.
|
|
1839
|
-
var
|
|
1840
|
-
all: ["cards"],
|
|
1841
|
-
one: (params) => [...cardsQueryKeys.all, params.cardId]
|
|
1842
|
-
};
|
|
1843
|
-
function useCards({
|
|
1844
|
-
cardIds,
|
|
1845
|
-
enabled = true,
|
|
1846
|
-
asObject
|
|
1847
|
-
}) {
|
|
1848
|
-
const queries = useQueries({
|
|
1849
|
-
queries: cardIds.map((cardId) => ({
|
|
1850
|
-
enabled: enabled && cardIds.length > 0,
|
|
1851
|
-
queryKey: cardsQueryKeys.one({
|
|
1852
|
-
cardId
|
|
1853
|
-
}),
|
|
1854
|
-
queryFn: () => getCard({ cardId })
|
|
1855
|
-
}))
|
|
1856
|
-
});
|
|
1857
|
-
const cards = queries.map((query2) => query2.data).filter(Boolean);
|
|
1858
|
-
const cardsObject = useMemo(() => {
|
|
1859
|
-
if (!asObject) return null;
|
|
1860
|
-
return cards.reduce((acc, card) => {
|
|
1861
|
-
acc[card.id] = card;
|
|
1862
|
-
return acc;
|
|
1863
|
-
}, {});
|
|
1864
|
-
}, [asObject, cards]);
|
|
1865
|
-
return {
|
|
1866
|
-
cards,
|
|
1867
|
-
cardsObject,
|
|
1868
|
-
cardsQueries: queries
|
|
1869
|
-
};
|
|
1870
|
-
}
|
|
1871
|
-
function useCreateCard() {
|
|
1872
|
-
const { queryClient } = useSpeakableApi();
|
|
1873
|
-
const mutationCreateCard = useMutation2({
|
|
1874
|
-
mutationFn: createCard,
|
|
1875
|
-
onSuccess: (cardCreated) => {
|
|
1876
|
-
queryClient.invalidateQueries({ queryKey: cardsQueryKeys.one({ cardId: cardCreated.id }) });
|
|
1877
|
-
}
|
|
1878
|
-
});
|
|
1879
|
-
return {
|
|
1880
|
-
mutationCreateCard
|
|
1881
|
-
};
|
|
1882
|
-
}
|
|
1883
|
-
function useCreateCards() {
|
|
1884
|
-
const mutationCreateCards = useMutation2({
|
|
1885
|
-
mutationFn: createCards
|
|
1886
|
-
});
|
|
1887
|
-
return {
|
|
1888
|
-
mutationCreateCards
|
|
1889
|
-
};
|
|
1890
|
-
}
|
|
1891
|
-
function getCardFromCache({
|
|
1892
|
-
cardId,
|
|
1893
|
-
queryClient
|
|
1894
|
-
}) {
|
|
1895
|
-
return queryClient.getQueryData(cardsQueryKeys.one({ cardId }));
|
|
1896
|
-
}
|
|
1897
|
-
function updateCardInCache({
|
|
1898
|
-
cardId,
|
|
1899
|
-
card,
|
|
1900
|
-
queryClient
|
|
1901
|
-
}) {
|
|
1902
|
-
queryClient.setQueryData(cardsQueryKeys.one({ cardId }), card);
|
|
1903
|
-
}
|
|
1904
|
-
function useGetCard({ cardId, enabled = true }) {
|
|
1905
|
-
const query2 = useQuery3({
|
|
1906
|
-
queryKey: cardsQueryKeys.one({ cardId }),
|
|
1907
|
-
queryFn: () => getCard({ cardId }),
|
|
1908
|
-
enabled: enabled && !!cardId
|
|
1909
|
-
});
|
|
1910
|
-
return query2;
|
|
1911
|
-
}
|
|
1912
|
-
|
|
1913
|
-
// src/domains/cards/card.repo.ts
|
|
1914
|
-
var createCardRepo = () => {
|
|
1004
|
+
// src/domains/cards/card.repo.ts
|
|
1005
|
+
var createCardRepo = () => {
|
|
1915
1006
|
return {
|
|
1916
1007
|
createCard,
|
|
1917
1008
|
createCards,
|
|
@@ -1919,177 +1010,6 @@ var createCardRepo = () => {
|
|
|
1919
1010
|
};
|
|
1920
1011
|
};
|
|
1921
1012
|
|
|
1922
|
-
// src/domains/cards/utils/check-page-type.ts
|
|
1923
|
-
function checkIsRepeatPage(cardType) {
|
|
1924
|
-
if (cardType === void 0) return false;
|
|
1925
|
-
return REPEAT_PAGE_ACTIVITY_TYPES.includes(cardType);
|
|
1926
|
-
}
|
|
1927
|
-
function checkIsMCPage(cardType) {
|
|
1928
|
-
if (cardType === void 0) return false;
|
|
1929
|
-
return MULTIPLE_CHOICE_PAGE_ACTIVITY_TYPES.includes(cardType);
|
|
1930
|
-
}
|
|
1931
|
-
function checkIsRespondPage(cardType) {
|
|
1932
|
-
if (cardType === void 0) return false;
|
|
1933
|
-
return RESPOND_PAGE_ACTIVITY_TYPES.includes(cardType);
|
|
1934
|
-
}
|
|
1935
|
-
function checkIsRespondWrittenPage(cardType) {
|
|
1936
|
-
if (cardType === void 0) return false;
|
|
1937
|
-
return RESPOND_WRITE_PAGE_ACTIVITY_TYPES.includes(cardType);
|
|
1938
|
-
}
|
|
1939
|
-
function checkIsRespondAudioPage(cardType) {
|
|
1940
|
-
if (cardType === void 0) return false;
|
|
1941
|
-
return RESPOND_AUDIO_PAGE_ACTIVITY_TYPES.includes(cardType);
|
|
1942
|
-
}
|
|
1943
|
-
var checkIsMediaPage = (cardType) => {
|
|
1944
|
-
if (cardType === void 0) return false;
|
|
1945
|
-
return cardType === "MEDIA_PAGE" /* MEDIA_PAGE */;
|
|
1946
|
-
};
|
|
1947
|
-
var checkIsShortAnswerPage = (cardType) => {
|
|
1948
|
-
if (cardType === void 0) return false;
|
|
1949
|
-
return cardType === "SHORT_ANSWER" /* SHORT_ANSWER */;
|
|
1950
|
-
};
|
|
1951
|
-
var checkTypePageActivity = (cardType) => {
|
|
1952
|
-
const isRespondAudio = checkIsRespondAudioPage(cardType);
|
|
1953
|
-
const isRespondWritten = checkIsRespondWrittenPage(cardType);
|
|
1954
|
-
const isRespond = checkIsRespondPage(cardType);
|
|
1955
|
-
const isMC = checkIsMCPage(cardType);
|
|
1956
|
-
const isRepeat = checkIsRepeatPage(cardType);
|
|
1957
|
-
const isMediaPage = checkIsMediaPage(cardType);
|
|
1958
|
-
const isShortAnswer = checkIsShortAnswerPage(cardType);
|
|
1959
|
-
const isNoOneOfThem = !isRespond && !isMC && !isRepeat && !isMediaPage && !isShortAnswer;
|
|
1960
|
-
if (isNoOneOfThem) {
|
|
1961
|
-
return {
|
|
1962
|
-
isRespondAudio: false,
|
|
1963
|
-
isRespondWritten: false,
|
|
1964
|
-
isRespond: false,
|
|
1965
|
-
isMC: false,
|
|
1966
|
-
isRepeat: true,
|
|
1967
|
-
isMediaPage: false,
|
|
1968
|
-
isShortAnswer: false,
|
|
1969
|
-
hasSomeType: false
|
|
1970
|
-
};
|
|
1971
|
-
}
|
|
1972
|
-
return {
|
|
1973
|
-
isRespondAudio,
|
|
1974
|
-
isRespondWritten,
|
|
1975
|
-
isRespond,
|
|
1976
|
-
isMC,
|
|
1977
|
-
isRepeat,
|
|
1978
|
-
isMediaPage,
|
|
1979
|
-
isShortAnswer,
|
|
1980
|
-
hasSomeType: true
|
|
1981
|
-
};
|
|
1982
|
-
};
|
|
1983
|
-
|
|
1984
|
-
// src/domains/cards/utils/get-page-prompt.ts
|
|
1985
|
-
function extractTextFromRichText(richText) {
|
|
1986
|
-
if (!richText) return "";
|
|
1987
|
-
return richText.replace(/<[^>]*>/g, "").replace(/ /g, " ").replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, '"').replace(/'/g, "'").trim();
|
|
1988
|
-
}
|
|
1989
|
-
function getPagePrompt(card) {
|
|
1990
|
-
if (!card) return { has: false, text: "", rich_text: "", isTextEqualToRichText: false };
|
|
1991
|
-
const { isMC, isRepeat, isRespond, isShortAnswer } = checkTypePageActivity(card == null ? void 0 : card.type);
|
|
1992
|
-
const hidePrompt = (card == null ? void 0 : card.hidePrompt) === true;
|
|
1993
|
-
const createReturnObject = (text, richText) => {
|
|
1994
|
-
const plainText = text || "";
|
|
1995
|
-
const richTextPlain = extractTextFromRichText(richText);
|
|
1996
|
-
return {
|
|
1997
|
-
has: true,
|
|
1998
|
-
text: plainText,
|
|
1999
|
-
rich_text: richText || "",
|
|
2000
|
-
isTextEqualToRichText: plainText.trim() === richTextPlain.trim()
|
|
2001
|
-
};
|
|
2002
|
-
};
|
|
2003
|
-
if (isRepeat) {
|
|
2004
|
-
return createReturnObject(card == null ? void 0 : card.target_text, card == null ? void 0 : card.rich_text);
|
|
2005
|
-
}
|
|
2006
|
-
if (isRespond && !hidePrompt) {
|
|
2007
|
-
return createReturnObject(card == null ? void 0 : card.prompt, card == null ? void 0 : card.rich_text);
|
|
2008
|
-
}
|
|
2009
|
-
if (isMC) {
|
|
2010
|
-
return createReturnObject(card == null ? void 0 : card.question, card == null ? void 0 : card.rich_text);
|
|
2011
|
-
}
|
|
2012
|
-
if (isShortAnswer && !hidePrompt) {
|
|
2013
|
-
return createReturnObject(card == null ? void 0 : card.prompt, card == null ? void 0 : card.rich_text);
|
|
2014
|
-
}
|
|
2015
|
-
return {
|
|
2016
|
-
has: false,
|
|
2017
|
-
text: "",
|
|
2018
|
-
rich_text: "",
|
|
2019
|
-
isTextEqualToRichText: false
|
|
2020
|
-
};
|
|
2021
|
-
}
|
|
2022
|
-
|
|
2023
|
-
// src/domains/cards/utils/get-completed-pages.ts
|
|
2024
|
-
var getTotalCompletedCards = (pageScores) => {
|
|
2025
|
-
return Object.values(pageScores != null ? pageScores : {}).reduce((acc, cardScore) => {
|
|
2026
|
-
var _a, _b;
|
|
2027
|
-
if (((_b = (_a = cardScore.completed) != null ? _a : cardScore.score) != null ? _b : cardScore.score === 0) && !cardScore.media_area_opened) {
|
|
2028
|
-
acc++;
|
|
2029
|
-
}
|
|
2030
|
-
return acc;
|
|
2031
|
-
}, 0);
|
|
2032
|
-
};
|
|
2033
|
-
|
|
2034
|
-
// src/domains/cards/utils/get-label-page.ts
|
|
2035
|
-
var labels = {
|
|
2036
|
-
repeat: {
|
|
2037
|
-
short: "Repeat",
|
|
2038
|
-
long: "Listen & Repeat"
|
|
2039
|
-
},
|
|
2040
|
-
mc: {
|
|
2041
|
-
short: "Multiple Choice",
|
|
2042
|
-
long: "Multiple Choice"
|
|
2043
|
-
},
|
|
2044
|
-
mediaPage: {
|
|
2045
|
-
short: "Media Page",
|
|
2046
|
-
long: "Media Page"
|
|
2047
|
-
},
|
|
2048
|
-
shortAnswer: {
|
|
2049
|
-
short: "Short Answer",
|
|
2050
|
-
long: "Short Answer"
|
|
2051
|
-
},
|
|
2052
|
-
respondWritten: {
|
|
2053
|
-
short: "Open Response",
|
|
2054
|
-
long: "Written Open Response"
|
|
2055
|
-
},
|
|
2056
|
-
respondAudio: {
|
|
2057
|
-
short: "Open Response",
|
|
2058
|
-
long: "Spoken Open Response"
|
|
2059
|
-
}
|
|
2060
|
-
};
|
|
2061
|
-
var getLabelPage = (pageType) => {
|
|
2062
|
-
if (!pageType) {
|
|
2063
|
-
return {
|
|
2064
|
-
short: "",
|
|
2065
|
-
long: ""
|
|
2066
|
-
};
|
|
2067
|
-
}
|
|
2068
|
-
const { isRepeat, isMC, isMediaPage, isShortAnswer, isRespondWritten, isRespondAudio } = checkTypePageActivity(pageType);
|
|
2069
|
-
if (isRepeat) {
|
|
2070
|
-
return labels.repeat;
|
|
2071
|
-
}
|
|
2072
|
-
if (isMC) {
|
|
2073
|
-
return labels.mc;
|
|
2074
|
-
}
|
|
2075
|
-
if (isMediaPage) {
|
|
2076
|
-
return labels.mediaPage;
|
|
2077
|
-
}
|
|
2078
|
-
if (isShortAnswer) {
|
|
2079
|
-
return labels.shortAnswer;
|
|
2080
|
-
}
|
|
2081
|
-
if (isRespondWritten) {
|
|
2082
|
-
return labels.respondWritten;
|
|
2083
|
-
}
|
|
2084
|
-
if (isRespondAudio) {
|
|
2085
|
-
return labels.respondAudio;
|
|
2086
|
-
}
|
|
2087
|
-
return {
|
|
2088
|
-
short: "",
|
|
2089
|
-
long: ""
|
|
2090
|
-
};
|
|
2091
|
-
};
|
|
2092
|
-
|
|
2093
1013
|
// src/domains/sets/set.hooks.ts
|
|
2094
1014
|
import { useQuery as useQuery4 } from "@tanstack/react-query";
|
|
2095
1015
|
|
|
@@ -2107,1212 +1027,6 @@ async function _getSet({ setId }) {
|
|
|
2107
1027
|
}
|
|
2108
1028
|
var getSet = withErrorHandler(_getSet, "getSet");
|
|
2109
1029
|
|
|
2110
|
-
// src/domains/sets/set.hooks.ts
|
|
2111
|
-
var setsQueryKeys = {
|
|
2112
|
-
all: ["sets"],
|
|
2113
|
-
one: (params) => [...setsQueryKeys.all, params.setId]
|
|
2114
|
-
};
|
|
2115
|
-
var useSet = ({ setId, enabled }) => {
|
|
2116
|
-
return useQuery4({
|
|
2117
|
-
queryKey: setsQueryKeys.one({ setId }),
|
|
2118
|
-
queryFn: () => getSet({ setId }),
|
|
2119
|
-
enabled: setId !== void 0 && setId !== "" && enabled
|
|
2120
|
-
});
|
|
2121
|
-
};
|
|
2122
|
-
function getSetFromCache({
|
|
2123
|
-
setId,
|
|
2124
|
-
queryClient
|
|
2125
|
-
}) {
|
|
2126
|
-
if (!setId) return null;
|
|
2127
|
-
return queryClient.getQueryData(setsQueryKeys.one({ setId }));
|
|
2128
|
-
}
|
|
2129
|
-
function updateSetInCache({
|
|
2130
|
-
set,
|
|
2131
|
-
queryClient
|
|
2132
|
-
}) {
|
|
2133
|
-
const { id, ...setData } = set;
|
|
2134
|
-
queryClient.setQueryData(setsQueryKeys.one({ setId: id }), setData);
|
|
2135
|
-
}
|
|
2136
|
-
|
|
2137
|
-
// src/domains/sets/set.repo.ts
|
|
2138
|
-
var createSetRepo = () => {
|
|
2139
|
-
return {
|
|
2140
|
-
getSet
|
|
2141
|
-
};
|
|
2142
|
-
};
|
|
2143
|
-
|
|
2144
|
-
// src/constants/all-langs.json
|
|
2145
|
-
var all_langs_default = {
|
|
2146
|
-
af: "Afrikaans",
|
|
2147
|
-
sq: "Albanian",
|
|
2148
|
-
am: "Amharic",
|
|
2149
|
-
ar: "Arabic",
|
|
2150
|
-
hy: "Armenian",
|
|
2151
|
-
az: "Azerbaijani",
|
|
2152
|
-
eu: "Basque",
|
|
2153
|
-
be: "Belarusian",
|
|
2154
|
-
bn: "Bengali",
|
|
2155
|
-
bs: "Bosnian",
|
|
2156
|
-
bg: "Bulgarian",
|
|
2157
|
-
ca: "Catalan",
|
|
2158
|
-
ceb: "Cebuano",
|
|
2159
|
-
zh: "Chinese",
|
|
2160
|
-
co: "Corsican",
|
|
2161
|
-
hr: "Croatian",
|
|
2162
|
-
cs: "Czech",
|
|
2163
|
-
da: "Danish",
|
|
2164
|
-
nl: "Dutch",
|
|
2165
|
-
en: "English",
|
|
2166
|
-
eo: "Esperanto",
|
|
2167
|
-
et: "Estonian",
|
|
2168
|
-
fi: "Finnish",
|
|
2169
|
-
fr: "French",
|
|
2170
|
-
fy: "Frisian",
|
|
2171
|
-
gl: "Galician",
|
|
2172
|
-
ka: "Georgian",
|
|
2173
|
-
de: "German",
|
|
2174
|
-
el: "Greek",
|
|
2175
|
-
gu: "Gujarati",
|
|
2176
|
-
ht: "Haitian Creole",
|
|
2177
|
-
ha: "Hausa",
|
|
2178
|
-
haw: "Hawaiian",
|
|
2179
|
-
he: "Hebrew",
|
|
2180
|
-
hi: "Hindi",
|
|
2181
|
-
hmn: "Hmong",
|
|
2182
|
-
hu: "Hungarian",
|
|
2183
|
-
is: "Icelandic",
|
|
2184
|
-
ig: "Igbo",
|
|
2185
|
-
id: "Indonesian",
|
|
2186
|
-
ga: "Irish",
|
|
2187
|
-
it: "Italian",
|
|
2188
|
-
ja: "Japanese",
|
|
2189
|
-
jv: "Javanese",
|
|
2190
|
-
kn: "Kannada",
|
|
2191
|
-
kk: "Kazakh",
|
|
2192
|
-
km: "Khmer",
|
|
2193
|
-
ko: "Korean",
|
|
2194
|
-
ku: "Kurdish",
|
|
2195
|
-
ky: "Kyrgyz",
|
|
2196
|
-
lo: "Lao",
|
|
2197
|
-
la: "Latin",
|
|
2198
|
-
lv: "Latvian",
|
|
2199
|
-
lt: "Lithuanian",
|
|
2200
|
-
lb: "Luxembourgish",
|
|
2201
|
-
mk: "Macedonian",
|
|
2202
|
-
mg: "Malagasy",
|
|
2203
|
-
ms: "Malay",
|
|
2204
|
-
ml: "Malayalam",
|
|
2205
|
-
mt: "Maltese",
|
|
2206
|
-
mi: "Maori",
|
|
2207
|
-
mr: "Marathi",
|
|
2208
|
-
mn: "Mongolian",
|
|
2209
|
-
my: "Myanmar (Burmese)",
|
|
2210
|
-
ne: "Nepali",
|
|
2211
|
-
no: "Norwegian",
|
|
2212
|
-
ny: "Nyanja (Chichewa)",
|
|
2213
|
-
ps: "Pashto",
|
|
2214
|
-
fa: "Persian",
|
|
2215
|
-
pl: "Polish",
|
|
2216
|
-
pt: "Portuguese",
|
|
2217
|
-
pa: "Punjabi",
|
|
2218
|
-
ro: "Romanian",
|
|
2219
|
-
ru: "Russian",
|
|
2220
|
-
sm: "Samoan",
|
|
2221
|
-
gd: "Scots Gaelic",
|
|
2222
|
-
sr: "Serbian",
|
|
2223
|
-
st: "Sesotho",
|
|
2224
|
-
sn: "Shona",
|
|
2225
|
-
sd: "Sindhi",
|
|
2226
|
-
si: "Sinhala (Sinhalese)",
|
|
2227
|
-
sk: "Slovak",
|
|
2228
|
-
sl: "Slovenian",
|
|
2229
|
-
so: "Somali",
|
|
2230
|
-
es: "Spanish",
|
|
2231
|
-
su: "Sundanese",
|
|
2232
|
-
sw: "Swahili",
|
|
2233
|
-
sv: "Swedish",
|
|
2234
|
-
tl: "Tagalog (Filipino)",
|
|
2235
|
-
tg: "Tajik",
|
|
2236
|
-
ta: "Tamil",
|
|
2237
|
-
te: "Telugu",
|
|
2238
|
-
th: "Thai",
|
|
2239
|
-
tr: "Turkish",
|
|
2240
|
-
uk: "Ukrainian",
|
|
2241
|
-
ur: "Urdu",
|
|
2242
|
-
uz: "Uzbek",
|
|
2243
|
-
vi: "Vietnamese",
|
|
2244
|
-
cy: "Welsh",
|
|
2245
|
-
xh: "Xhosa",
|
|
2246
|
-
yi: "Yiddish",
|
|
2247
|
-
yo: "Yoruba",
|
|
2248
|
-
zu: "Zulu"
|
|
2249
|
-
};
|
|
2250
|
-
|
|
2251
|
-
// src/utils/ai/get-respond-card-tool.ts
|
|
2252
|
-
var getRespondCardTool = ({
|
|
2253
|
-
language,
|
|
2254
|
-
standard = "actfl"
|
|
2255
|
-
}) => {
|
|
2256
|
-
const lang = all_langs_default[language] || "English";
|
|
2257
|
-
const tool = {
|
|
2258
|
-
tool_choice: {
|
|
2259
|
-
type: "function",
|
|
2260
|
-
function: { name: "get_feedback" }
|
|
2261
|
-
},
|
|
2262
|
-
tools: [
|
|
2263
|
-
{
|
|
2264
|
-
type: "function",
|
|
2265
|
-
function: {
|
|
2266
|
-
name: "get_feedback",
|
|
2267
|
-
description: "Get feedback on a student's response",
|
|
2268
|
-
parameters: {
|
|
2269
|
-
type: "object",
|
|
2270
|
-
required: [
|
|
2271
|
-
"success",
|
|
2272
|
-
"score",
|
|
2273
|
-
"score_justification",
|
|
2274
|
-
"errors",
|
|
2275
|
-
"improvedResponse",
|
|
2276
|
-
"compliments"
|
|
2277
|
-
],
|
|
2278
|
-
properties: {
|
|
2279
|
-
success: {
|
|
2280
|
-
type: "boolean",
|
|
2281
|
-
description: "Mark true if the student's response was on-topic and generally demonstrated understanding. A few grammar mistakes are acceptable. Mark false if the student's response was off-topic or did not demonstrate understanding."
|
|
2282
|
-
},
|
|
2283
|
-
errors: {
|
|
2284
|
-
type: "array",
|
|
2285
|
-
items: {
|
|
2286
|
-
type: "object",
|
|
2287
|
-
required: ["error", "grammar_error_type", "correction", "justification"],
|
|
2288
|
-
properties: {
|
|
2289
|
-
error: {
|
|
2290
|
-
type: "string",
|
|
2291
|
-
description: "The grammatical error in the student's response."
|
|
2292
|
-
},
|
|
2293
|
-
correction: {
|
|
2294
|
-
type: "string",
|
|
2295
|
-
description: "The suggested correction to the error"
|
|
2296
|
-
},
|
|
2297
|
-
justification: {
|
|
2298
|
-
type: "string",
|
|
2299
|
-
description: `An explanation of the rationale behind the suggested correction. WRITE THIS IN ${lang}!`
|
|
2300
|
-
},
|
|
2301
|
-
grammar_error_type: {
|
|
2302
|
-
type: "string",
|
|
2303
|
-
enum: [
|
|
2304
|
-
"subjVerbAgree",
|
|
2305
|
-
"tenseErrors",
|
|
2306
|
-
"articleMisuse",
|
|
2307
|
-
"prepositionErrors",
|
|
2308
|
-
"adjNounAgree",
|
|
2309
|
-
"pronounErrors",
|
|
2310
|
-
"wordOrder",
|
|
2311
|
-
"verbConjugation",
|
|
2312
|
-
"pluralization",
|
|
2313
|
-
"negationErrors",
|
|
2314
|
-
"modalVerbMisuse",
|
|
2315
|
-
"relativeClause",
|
|
2316
|
-
"auxiliaryVerb",
|
|
2317
|
-
"complexSentenceAgreement",
|
|
2318
|
-
"idiomaticExpression",
|
|
2319
|
-
"registerInconsistency",
|
|
2320
|
-
"voiceMisuse"
|
|
2321
|
-
],
|
|
2322
|
-
description: "The type of grammatical error found. It should be one of the following categories: subject-verb agreement, tense errors, article misuse, preposition errors, adjective-noun agreement, pronoun errors, word order, verb conjugation, pluralization errors, negation errors, modal verb misuse, relative clause errors, auxiliary verb misuse, complex sentence agreement, idiomatic expression, register inconsistency, or voice misuse"
|
|
2323
|
-
}
|
|
2324
|
-
}
|
|
2325
|
-
},
|
|
2326
|
-
description: "An array of objects, each representing a grammatical error in the student's response. Each object should have the following properties: error, grammar_error_type, correction, and justification. If there were no errors, return an empty array."
|
|
2327
|
-
},
|
|
2328
|
-
compliments: {
|
|
2329
|
-
type: "array",
|
|
2330
|
-
items: {
|
|
2331
|
-
type: "string"
|
|
2332
|
-
},
|
|
2333
|
-
description: `An array of strings, each representing something the student did well. Each string should be WRITTEN IN ${lang}!`
|
|
2334
|
-
},
|
|
2335
|
-
improvedResponse: {
|
|
2336
|
-
type: "string",
|
|
2337
|
-
description: "An improved response with proper grammar and more detail, if applicable."
|
|
2338
|
-
},
|
|
2339
|
-
score: {
|
|
2340
|
-
type: "number",
|
|
2341
|
-
description: "A score between 0 and 100, reflecting the overall quality of the response"
|
|
2342
|
-
},
|
|
2343
|
-
score_justification: {
|
|
2344
|
-
type: "string",
|
|
2345
|
-
description: "An explanation of the rationale behind the assigned score, considering both accuracy and fluency"
|
|
2346
|
-
}
|
|
2347
|
-
}
|
|
2348
|
-
}
|
|
2349
|
-
}
|
|
2350
|
-
}
|
|
2351
|
-
]
|
|
2352
|
-
};
|
|
2353
|
-
if (standard === "wida") {
|
|
2354
|
-
const wida_level = {
|
|
2355
|
-
type: "number",
|
|
2356
|
-
enum: [1, 2, 3, 4, 5, 6],
|
|
2357
|
-
description: `The student's WIDA (World-Class Instructional Design and Assessment) proficiency level. Choose one of the following options: 1, 2, 3, 4, 5, 6 which corresponds to
|
|
2358
|
-
|
|
2359
|
-
1 - Entering
|
|
2360
|
-
2 - Emerging
|
|
2361
|
-
3 - Developing
|
|
2362
|
-
4 - Expanding
|
|
2363
|
-
5 - Bridging
|
|
2364
|
-
6 - Reaching
|
|
2365
|
-
|
|
2366
|
-
This is an estimate based on the level of the student's response. Use the descriptions of the WIDA speaking standards to guide your decision.
|
|
2367
|
-
`
|
|
2368
|
-
};
|
|
2369
|
-
const wida_justification = {
|
|
2370
|
-
type: "string",
|
|
2371
|
-
description: `An explanation of the rationale behind the assigned WIDA level of the response, considering both accuracy and fluency. WRITE THIS IN ENGLISH!`
|
|
2372
|
-
};
|
|
2373
|
-
tool.tools[0].function.parameters.required.push("wida_level");
|
|
2374
|
-
tool.tools[0].function.parameters.required.push("wida_justification");
|
|
2375
|
-
tool.tools[0].function.parameters.properties.wida_level = wida_level;
|
|
2376
|
-
tool.tools[0].function.parameters.properties.wida_justification = wida_justification;
|
|
2377
|
-
} else {
|
|
2378
|
-
const actfl_level = {
|
|
2379
|
-
type: "string",
|
|
2380
|
-
enum: ["NL", "NM", "NH", "IL", "IM", "IH", "AL", "AM", "AH", "S", "D"],
|
|
2381
|
-
description: "The student's ACTFL (American Council on the Teaching of Foreign Languages) proficiency level. Choose one of the following options: NL, NM, NH, IL, IM, IH, AL, AM, AH, S, or D"
|
|
2382
|
-
};
|
|
2383
|
-
const actfl_justification = {
|
|
2384
|
-
type: "string",
|
|
2385
|
-
description: "An explanation of the rationale behind the assigned ACTFL level, considering both accuracy and fluency"
|
|
2386
|
-
};
|
|
2387
|
-
tool.tools[0].function.parameters.required.push("actfl_level");
|
|
2388
|
-
tool.tools[0].function.parameters.required.push("actfl_justification");
|
|
2389
|
-
tool.tools[0].function.parameters.properties.actfl_level = actfl_level;
|
|
2390
|
-
tool.tools[0].function.parameters.properties.actfl_justification = actfl_justification;
|
|
2391
|
-
}
|
|
2392
|
-
return tool;
|
|
2393
|
-
};
|
|
2394
|
-
|
|
2395
|
-
// src/hooks/useActivity.ts
|
|
2396
|
-
import { useEffect as useEffect2 } from "react";
|
|
2397
|
-
|
|
2398
|
-
// src/services/add-grading-standard.ts
|
|
2399
|
-
var addGradingStandardLog = async (gradingStandard, userId) => {
|
|
2400
|
-
logGradingStandardLog(gradingStandard);
|
|
2401
|
-
const path = `users/${userId}/grading_standard_logs`;
|
|
2402
|
-
await api.addDoc(path, gradingStandard);
|
|
2403
|
-
};
|
|
2404
|
-
|
|
2405
|
-
// src/hooks/useActivityTracker.ts
|
|
2406
|
-
import { v4 as v42 } from "uuid";
|
|
2407
|
-
function useActivityTracker({ userId }) {
|
|
2408
|
-
const trackActivity = async ({
|
|
2409
|
-
activityName,
|
|
2410
|
-
activityType,
|
|
2411
|
-
id = v42(),
|
|
2412
|
-
language = ""
|
|
2413
|
-
}) => {
|
|
2414
|
-
if (userId) {
|
|
2415
|
-
const { doc: doc2, serverTimestamp: serverTimestamp2, setDoc: setDoc2 } = api.accessHelpers();
|
|
2416
|
-
const activityRef = doc2(`users/${userId}/activity/${id}`);
|
|
2417
|
-
const timestamp = serverTimestamp2();
|
|
2418
|
-
await setDoc2(activityRef, {
|
|
2419
|
-
name: activityName,
|
|
2420
|
-
type: activityType,
|
|
2421
|
-
lastSeen: timestamp,
|
|
2422
|
-
id,
|
|
2423
|
-
language
|
|
2424
|
-
});
|
|
2425
|
-
}
|
|
2426
|
-
};
|
|
2427
|
-
return {
|
|
2428
|
-
trackActivity
|
|
2429
|
-
};
|
|
2430
|
-
}
|
|
2431
|
-
|
|
2432
|
-
// src/hooks/useActivity.ts
|
|
2433
|
-
function useActivity({
|
|
2434
|
-
id,
|
|
2435
|
-
isAssignment,
|
|
2436
|
-
onAssignmentSubmitted,
|
|
2437
|
-
ltiData
|
|
2438
|
-
}) {
|
|
2439
|
-
var _a, _b;
|
|
2440
|
-
const { queryClient, user } = useSpeakableApi();
|
|
2441
|
-
const userId = user.auth.uid;
|
|
2442
|
-
const assignmentQuery = useAssignment({
|
|
2443
|
-
assignmentId: id,
|
|
2444
|
-
userId,
|
|
2445
|
-
enabled: isAssignment
|
|
2446
|
-
});
|
|
2447
|
-
const activeAssignment = assignmentQuery.data;
|
|
2448
|
-
const setId = isAssignment ? (_a = activeAssignment == null ? void 0 : activeAssignment.setId) != null ? _a : "" : id;
|
|
2449
|
-
const querySet = useSet({ setId });
|
|
2450
|
-
const setData = querySet.data;
|
|
2451
|
-
const assignmentContent = activeAssignment == null ? void 0 : activeAssignment.content;
|
|
2452
|
-
const assignmentWeights = activeAssignment == null ? void 0 : activeAssignment.weights;
|
|
2453
|
-
const setContent = setData == null ? void 0 : setData.content;
|
|
2454
|
-
const setWeights = setData == null ? void 0 : setData.weights;
|
|
2455
|
-
const contentCardsToUse = isAssignment ? assignmentContent != null ? assignmentContent : setContent : setContent;
|
|
2456
|
-
const weightsToUse = isAssignment ? assignmentWeights != null ? assignmentWeights : setWeights : setWeights;
|
|
2457
|
-
const activityId = isAssignment ? (_b = activeAssignment == null ? void 0 : activeAssignment.id) != null ? _b : "" : setId;
|
|
2458
|
-
const { cardsObject, cardsQueries, cards } = useCards({
|
|
2459
|
-
cardIds: contentCardsToUse != null ? contentCardsToUse : [],
|
|
2460
|
-
enabled: querySet.isSuccess,
|
|
2461
|
-
asObject: true
|
|
2462
|
-
});
|
|
2463
|
-
const scorableCardIds = (contentCardsToUse != null ? contentCardsToUse : []).filter((cardId) => {
|
|
2464
|
-
const card = cardsObject == null ? void 0 : cardsObject[cardId];
|
|
2465
|
-
return (card == null ? void 0 : card.type) !== "MEDIA_PAGE" /* MEDIA_PAGE */;
|
|
2466
|
-
});
|
|
2467
|
-
const scoreQuery = useScore({
|
|
2468
|
-
isAssignment,
|
|
2469
|
-
activityId: id,
|
|
2470
|
-
userId,
|
|
2471
|
-
courseId: activeAssignment == null ? void 0 : activeAssignment.courseId,
|
|
2472
|
-
googleClassroomUserId: user.profile.googleClassroomUserId,
|
|
2473
|
-
enabled: isAssignment ? assignmentQuery.isSuccess : querySet.isSuccess
|
|
2474
|
-
});
|
|
2475
|
-
const { mutationUpdateScore } = useUpdateScore();
|
|
2476
|
-
const { mutationUpdateCardScore } = useUpdateCardScore({
|
|
2477
|
-
activityId,
|
|
2478
|
-
isAssignment,
|
|
2479
|
-
userId,
|
|
2480
|
-
cardIds: scorableCardIds,
|
|
2481
|
-
weights: weightsToUse != null ? weightsToUse : {}
|
|
2482
|
-
});
|
|
2483
|
-
const { mutationClearScore } = useClearScore();
|
|
2484
|
-
const { submitAssignmentScore: submitAssignmentScore2 } = useSubmitAssignmentScore({
|
|
2485
|
-
onAssignmentSubmitted,
|
|
2486
|
-
studentName: user.profile.displayName
|
|
2487
|
-
});
|
|
2488
|
-
const { submitPracticeScore: submitPracticeScore2 } = useSubmitPracticeScore();
|
|
2489
|
-
const handleUpdateScore = (data) => {
|
|
2490
|
-
mutationUpdateScore.mutate({
|
|
2491
|
-
data,
|
|
2492
|
-
isAssignment,
|
|
2493
|
-
activityId,
|
|
2494
|
-
userId
|
|
2495
|
-
});
|
|
2496
|
-
};
|
|
2497
|
-
const handleUpdateCardScore = (cardId, cardScore) => {
|
|
2498
|
-
mutationUpdateCardScore.mutate({ cardId, cardScore });
|
|
2499
|
-
if (cardScore.proficiency_level) {
|
|
2500
|
-
logGradingStandardEntry({
|
|
2501
|
-
type: cardScore.proficiency_level.standardId,
|
|
2502
|
-
cardId,
|
|
2503
|
-
gradingStandard: cardScore.proficiency_level
|
|
2504
|
-
});
|
|
2505
|
-
} else if (cardScore.wida || cardScore.actfl) {
|
|
2506
|
-
logGradingStandardEntry({
|
|
2507
|
-
type: cardScore.wida ? "wida" : "actfl",
|
|
2508
|
-
cardId,
|
|
2509
|
-
gradingStandard: cardScore.wida || cardScore.actfl || { level: "", justification: "" }
|
|
2510
|
-
});
|
|
2511
|
-
}
|
|
2512
|
-
};
|
|
2513
|
-
const onClearScore = ({
|
|
2514
|
-
cardId,
|
|
2515
|
-
wasCompleted = true
|
|
2516
|
-
}) => {
|
|
2517
|
-
var _a2, _b2;
|
|
2518
|
-
const currentCard = cardsObject == null ? void 0 : cardsObject[cardId];
|
|
2519
|
-
if ((currentCard == null ? void 0 : currentCard.type) === "MULTIPLE_CHOICE" /* MULTIPLE_CHOICE */ || (currentCard == null ? void 0 : currentCard.type) === "READ_REPEAT" /* READ_REPEAT */) {
|
|
2520
|
-
return;
|
|
2521
|
-
}
|
|
2522
|
-
const queryKeys = scoreQueryKeys.byId(activityId);
|
|
2523
|
-
const activeCardScores = (_b2 = (_a2 = queryClient.getQueryData(queryKeys)) == null ? void 0 : _a2.cards) == null ? void 0 : _b2[cardId];
|
|
2524
|
-
if (activeCardScores === void 0) return;
|
|
2525
|
-
mutationClearScore.mutate({
|
|
2526
|
-
isAssignment,
|
|
2527
|
-
activityId,
|
|
2528
|
-
cardScores: activeCardScores,
|
|
2529
|
-
cardId,
|
|
2530
|
-
userId
|
|
2531
|
-
});
|
|
2532
|
-
};
|
|
2533
|
-
const onSubmitScore = async () => {
|
|
2534
|
-
var _a2, _b2, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w;
|
|
2535
|
-
try {
|
|
2536
|
-
let results;
|
|
2537
|
-
if (isAssignment) {
|
|
2538
|
-
const someCardIsManualGraded = cards.some((page) => page.grading_method === "manual");
|
|
2539
|
-
results = await submitAssignmentScore2({
|
|
2540
|
-
assignment: {
|
|
2541
|
-
id: (_b2 = (_a2 = assignmentQuery.data) == null ? void 0 : _a2.id) != null ? _b2 : "",
|
|
2542
|
-
name: (_d = (_c = assignmentQuery.data) == null ? void 0 : _c.name) != null ? _d : "",
|
|
2543
|
-
owners: (_f = (_e = assignmentQuery.data) == null ? void 0 : _e.owners) != null ? _f : [],
|
|
2544
|
-
courseId: (_h = (_g = assignmentQuery.data) == null ? void 0 : _g.courseId) != null ? _h : "",
|
|
2545
|
-
courseWorkId: (_j = (_i = assignmentQuery.data) == null ? void 0 : _i.courseWorkId) != null ? _j : "",
|
|
2546
|
-
isAssessment: (_l = (_k = assignmentQuery.data) == null ? void 0 : _k.isAssessment) != null ? _l : false,
|
|
2547
|
-
maxPoints: (_n = (_m = assignmentQuery.data) == null ? void 0 : _m.maxPoints) != null ? _n : 0
|
|
2548
|
-
},
|
|
2549
|
-
userId,
|
|
2550
|
-
cardIds: scorableCardIds,
|
|
2551
|
-
scores: scoreQuery.data,
|
|
2552
|
-
weights: weightsToUse != null ? weightsToUse : {},
|
|
2553
|
-
status: someCardIsManualGraded ? "PENDING_REVIEW" : "SUBMITTED"
|
|
2554
|
-
});
|
|
2555
|
-
if ((_o = assignmentQuery.data) == null ? void 0 : _o.ltiDeeplink) {
|
|
2556
|
-
submitLTIScore({
|
|
2557
|
-
maxPoints: (_p = assignmentQuery.data) == null ? void 0 : _p.maxPoints,
|
|
2558
|
-
score: (_r = (_q = scoreQuery.data) == null ? void 0 : _q.score) != null ? _r : 0,
|
|
2559
|
-
SERVICE_KEY: (_s = ltiData == null ? void 0 : ltiData.serviceKey) != null ? _s : "",
|
|
2560
|
-
lineItemId: (_t = ltiData == null ? void 0 : ltiData.lineItemId) != null ? _t : "",
|
|
2561
|
-
lti_id: (_u = ltiData == null ? void 0 : ltiData.lti_id) != null ? _u : ""
|
|
2562
|
-
});
|
|
2563
|
-
}
|
|
2564
|
-
} else {
|
|
2565
|
-
results = await submitPracticeScore2({
|
|
2566
|
-
setId: (_w = (_v = querySet.data) == null ? void 0 : _v.id) != null ? _w : "",
|
|
2567
|
-
userId,
|
|
2568
|
-
scores: scoreQuery.data
|
|
2569
|
-
});
|
|
2570
|
-
}
|
|
2571
|
-
return results;
|
|
2572
|
-
} catch (error) {
|
|
2573
|
-
return {
|
|
2574
|
-
success: false,
|
|
2575
|
-
error
|
|
2576
|
-
};
|
|
2577
|
-
}
|
|
2578
|
-
};
|
|
2579
|
-
const logGradingStandardEntry = ({
|
|
2580
|
-
cardId,
|
|
2581
|
-
gradingStandard,
|
|
2582
|
-
type
|
|
2583
|
-
}) => {
|
|
2584
|
-
var _a2, _b2, _c, _d, _e, _f, _g, _h, _i;
|
|
2585
|
-
const card = cardsObject == null ? void 0 : cardsObject[cardId];
|
|
2586
|
-
const scoresObject = queryClient.getQueryData(scoreQueryKeys.byId(activityId));
|
|
2587
|
-
const cardScore = (_a2 = scoresObject == null ? void 0 : scoresObject.cards) == null ? void 0 : _a2[cardId];
|
|
2588
|
-
const serverTimestamp2 = api.helpers.serverTimestamp;
|
|
2589
|
-
addGradingStandardLog(
|
|
2590
|
-
{
|
|
2591
|
-
assignmentId: (_b2 = activeAssignment == null ? void 0 : activeAssignment.id) != null ? _b2 : "",
|
|
2592
|
-
courseId: (_c = activeAssignment == null ? void 0 : activeAssignment.courseId) != null ? _c : "",
|
|
2593
|
-
teacherId: (_d = activeAssignment == null ? void 0 : activeAssignment.owners[0]) != null ? _d : "",
|
|
2594
|
-
setId: (_e = setData == null ? void 0 : setData.id) != null ? _e : "",
|
|
2595
|
-
cardId,
|
|
2596
|
-
level: gradingStandard.level,
|
|
2597
|
-
justification: gradingStandard.justification,
|
|
2598
|
-
transcript: (_f = cardScore == null ? void 0 : cardScore.transcript) != null ? _f : "",
|
|
2599
|
-
audioUrl: (_g = cardScore == null ? void 0 : cardScore.audio) != null ? _g : "",
|
|
2600
|
-
prompt: (_h = card == null ? void 0 : card.prompt) != null ? _h : "",
|
|
2601
|
-
responseType: (card == null ? void 0 : card.type) === "RESPOND_WRITE" /* RESPOND_WRITE */ ? "written" : "spoken",
|
|
2602
|
-
type,
|
|
2603
|
-
dateMade: serverTimestamp2(),
|
|
2604
|
-
language: (_i = card == null ? void 0 : card.language) != null ? _i : ""
|
|
2605
|
-
},
|
|
2606
|
-
userId
|
|
2607
|
-
);
|
|
2608
|
-
};
|
|
2609
|
-
useEffect2(() => {
|
|
2610
|
-
if (isAssignment) {
|
|
2611
|
-
logOpenAssignment({ assignmentId: id });
|
|
2612
|
-
} else {
|
|
2613
|
-
logOpenActivityPreview({ setId: id });
|
|
2614
|
-
}
|
|
2615
|
-
}, []);
|
|
2616
|
-
useInitActivity({
|
|
2617
|
-
assignment: activeAssignment != null ? activeAssignment : void 0,
|
|
2618
|
-
set: setData != null ? setData : void 0,
|
|
2619
|
-
enabled: !!setData,
|
|
2620
|
-
userId
|
|
2621
|
-
});
|
|
2622
|
-
return {
|
|
2623
|
-
set: {
|
|
2624
|
-
data: setData,
|
|
2625
|
-
query: querySet
|
|
2626
|
-
},
|
|
2627
|
-
cards: {
|
|
2628
|
-
data: cardsObject,
|
|
2629
|
-
query: cardsQueries,
|
|
2630
|
-
cardsArray: cards
|
|
2631
|
-
},
|
|
2632
|
-
assignment: {
|
|
2633
|
-
data: isAssignment ? activeAssignment : void 0,
|
|
2634
|
-
query: assignmentQuery
|
|
2635
|
-
},
|
|
2636
|
-
scores: {
|
|
2637
|
-
data: scoreQuery.data,
|
|
2638
|
-
query: scoreQuery,
|
|
2639
|
-
actions: {
|
|
2640
|
-
update: handleUpdateScore,
|
|
2641
|
-
clear: onClearScore,
|
|
2642
|
-
submit: onSubmitScore,
|
|
2643
|
-
updateCard: handleUpdateCardScore,
|
|
2644
|
-
logGradingStandardEntry
|
|
2645
|
-
}
|
|
2646
|
-
}
|
|
2647
|
-
};
|
|
2648
|
-
}
|
|
2649
|
-
var useInitActivity = ({
|
|
2650
|
-
assignment,
|
|
2651
|
-
set,
|
|
2652
|
-
enabled,
|
|
2653
|
-
userId
|
|
2654
|
-
}) => {
|
|
2655
|
-
const { trackActivity } = useActivityTracker({ userId });
|
|
2656
|
-
const init = () => {
|
|
2657
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
2658
|
-
if (!enabled) return;
|
|
2659
|
-
if (!assignment) {
|
|
2660
|
-
trackActivity({
|
|
2661
|
-
activityName: (_a = set == null ? void 0 : set.name) != null ? _a : "",
|
|
2662
|
-
activityType: "set",
|
|
2663
|
-
id: set == null ? void 0 : set.id,
|
|
2664
|
-
language: set == null ? void 0 : set.language
|
|
2665
|
-
});
|
|
2666
|
-
} else if (assignment.name) {
|
|
2667
|
-
trackActivity({
|
|
2668
|
-
activityName: assignment.name,
|
|
2669
|
-
activityType: assignment.isAssessment ? "assessment" : "assignment",
|
|
2670
|
-
id: assignment.id,
|
|
2671
|
-
language: set == null ? void 0 : set.language
|
|
2672
|
-
});
|
|
2673
|
-
}
|
|
2674
|
-
if (set == null ? void 0 : set.public) {
|
|
2675
|
-
(_d = (_c = (_b = api).httpsCallable) == null ? void 0 : _c.call(_b, "onSetOpened")) == null ? void 0 : _d({
|
|
2676
|
-
setId: set.id,
|
|
2677
|
-
language: set.language
|
|
2678
|
-
});
|
|
2679
|
-
}
|
|
2680
|
-
(_g = (_f = (_e = api).httpsCallable) == null ? void 0 : _f.call(_e, "updateAlgoliaIndex")) == null ? void 0 : _g({
|
|
2681
|
-
updatePlays: true,
|
|
2682
|
-
objectID: set == null ? void 0 : set.id
|
|
2683
|
-
});
|
|
2684
|
-
};
|
|
2685
|
-
useEffect2(() => {
|
|
2686
|
-
init();
|
|
2687
|
-
}, [set]);
|
|
2688
|
-
};
|
|
2689
|
-
var submitLTIScore = async ({
|
|
2690
|
-
maxPoints,
|
|
2691
|
-
score,
|
|
2692
|
-
SERVICE_KEY,
|
|
2693
|
-
lineItemId,
|
|
2694
|
-
lti_id
|
|
2695
|
-
}) => {
|
|
2696
|
-
var _a, _b, _c;
|
|
2697
|
-
try {
|
|
2698
|
-
if (!SERVICE_KEY || !lineItemId || !lti_id) {
|
|
2699
|
-
throw new Error("Missing required LTI credentials");
|
|
2700
|
-
}
|
|
2701
|
-
const earnedPoints = score ? score / 100 * maxPoints : 0;
|
|
2702
|
-
const { data } = await ((_c = (_b = (_a = api).httpsCallable) == null ? void 0 : _b.call(_a, "submitLTIAssignmentScore")) == null ? void 0 : _c({
|
|
2703
|
-
SERVICE_KEY,
|
|
2704
|
-
scoreData: {
|
|
2705
|
-
lineItemId,
|
|
2706
|
-
userId: lti_id,
|
|
2707
|
-
maxPoints,
|
|
2708
|
-
earnedPoints
|
|
2709
|
-
}
|
|
2710
|
-
}));
|
|
2711
|
-
return { success: true, data };
|
|
2712
|
-
} catch (error) {
|
|
2713
|
-
console.error("Failed to submit LTI score:", error);
|
|
2714
|
-
return {
|
|
2715
|
-
success: false,
|
|
2716
|
-
error: error instanceof Error ? error : new Error("Unknown error occurred")
|
|
2717
|
-
};
|
|
2718
|
-
}
|
|
2719
|
-
};
|
|
2720
|
-
|
|
2721
|
-
// src/hooks/useCredits.ts
|
|
2722
|
-
import { useQuery as useQuery5 } from "@tanstack/react-query";
|
|
2723
|
-
var creditQueryKeys = {
|
|
2724
|
-
userCredits: (uid) => ["userCredits", uid]
|
|
2725
|
-
};
|
|
2726
|
-
var useUserCredits = () => {
|
|
2727
|
-
const { user } = useSpeakableApi();
|
|
2728
|
-
const email = user.auth.email;
|
|
2729
|
-
const uid = user.auth.uid;
|
|
2730
|
-
const query2 = useQuery5({
|
|
2731
|
-
queryKey: creditQueryKeys.userCredits(uid),
|
|
2732
|
-
queryFn: () => fetchUserCredits({ uid, email }),
|
|
2733
|
-
enabled: !!uid,
|
|
2734
|
-
refetchInterval: 1e3 * 60 * 5
|
|
2735
|
-
});
|
|
2736
|
-
return {
|
|
2737
|
-
...query2
|
|
2738
|
-
};
|
|
2739
|
-
};
|
|
2740
|
-
var fetchUserCredits = async ({ uid, email }) => {
|
|
2741
|
-
if (!uid) {
|
|
2742
|
-
throw new Error("User ID is required");
|
|
2743
|
-
}
|
|
2744
|
-
const contractSnap = await api.getDoc(`creditContracts/${uid}`);
|
|
2745
|
-
if (contractSnap.data == null) {
|
|
2746
|
-
return {
|
|
2747
|
-
id: uid,
|
|
2748
|
-
userId: uid,
|
|
2749
|
-
email,
|
|
2750
|
-
effectivePlanId: "free_tier",
|
|
2751
|
-
status: "inactive",
|
|
2752
|
-
isUnlimited: false,
|
|
2753
|
-
creditsAvailable: 100,
|
|
2754
|
-
creditsAllocatedThisPeriod: 100,
|
|
2755
|
-
topOffCreditsAvailable: 0,
|
|
2756
|
-
topOffCreditsTotal: 0,
|
|
2757
|
-
allocationSource: "free_tier",
|
|
2758
|
-
sourceDetails: {},
|
|
2759
|
-
periodStart: null,
|
|
2760
|
-
periodEnd: null,
|
|
2761
|
-
planTermEndTimestamp: null,
|
|
2762
|
-
ownerType: "individual",
|
|
2763
|
-
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
2764
|
-
lastUpdatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
2765
|
-
};
|
|
2766
|
-
}
|
|
2767
|
-
const contractData = contractSnap.data;
|
|
2768
|
-
const monthlyCredits = (contractData == null ? void 0 : contractData.creditsAvailable) || 0;
|
|
2769
|
-
const topOffCredits = (contractData == null ? void 0 : contractData.topOffCreditsAvailable) || 0;
|
|
2770
|
-
const totalCredits = monthlyCredits + topOffCredits;
|
|
2771
|
-
return {
|
|
2772
|
-
id: contractSnap.id,
|
|
2773
|
-
...contractData,
|
|
2774
|
-
// Add computed total for convenience
|
|
2775
|
-
totalCreditsAvailable: totalCredits
|
|
2776
|
-
};
|
|
2777
|
-
};
|
|
2778
|
-
|
|
2779
|
-
// src/hooks/useOrganizationAccess.ts
|
|
2780
|
-
import { useQuery as useQuery6 } from "@tanstack/react-query";
|
|
2781
|
-
var useOrganizationAccess = () => {
|
|
2782
|
-
const { user } = useSpeakableApi();
|
|
2783
|
-
const email = user.auth.email;
|
|
2784
|
-
const query2 = useQuery6({
|
|
2785
|
-
queryKey: ["organizationAccess", email],
|
|
2786
|
-
queryFn: async () => {
|
|
2787
|
-
if (!email) {
|
|
2788
|
-
return {
|
|
2789
|
-
hasUnlimitedAccess: false,
|
|
2790
|
-
subscriptionId: null,
|
|
2791
|
-
organizationId: null,
|
|
2792
|
-
organizationName: null,
|
|
2793
|
-
subscriptionEndDate: null,
|
|
2794
|
-
accessType: "individual"
|
|
2795
|
-
};
|
|
2796
|
-
}
|
|
2797
|
-
return getOrganizationAccess(email);
|
|
2798
|
-
},
|
|
2799
|
-
enabled: !!email,
|
|
2800
|
-
// Only run query if we have a user email
|
|
2801
|
-
staleTime: 5 * 60 * 1e3,
|
|
2802
|
-
// Consider data fresh for 5 minutes
|
|
2803
|
-
gcTime: 10 * 60 * 1e3,
|
|
2804
|
-
// Keep in cache for 10 minutes
|
|
2805
|
-
retry: 2
|
|
2806
|
-
// Retry failed requests twice
|
|
2807
|
-
});
|
|
2808
|
-
return {
|
|
2809
|
-
...query2
|
|
2810
|
-
};
|
|
2811
|
-
};
|
|
2812
|
-
var getOrganizationAccess = async (email) => {
|
|
2813
|
-
const { limit: limit2, where: where2 } = api.accessQueryConstraints();
|
|
2814
|
-
try {
|
|
2815
|
-
const organizationSnapshot = await api.getDocs(
|
|
2816
|
-
"organizations",
|
|
2817
|
-
where2("members", "array-contains", email),
|
|
2818
|
-
where2("masterSubscriptionStatus", "==", "active"),
|
|
2819
|
-
limit2(1)
|
|
2820
|
-
);
|
|
2821
|
-
if (!organizationSnapshot.empty) {
|
|
2822
|
-
const orgData = organizationSnapshot.data[0];
|
|
2823
|
-
return {
|
|
2824
|
-
hasUnlimitedAccess: true,
|
|
2825
|
-
subscriptionId: orgData == null ? void 0 : orgData.masterSubscriptionId,
|
|
2826
|
-
organizationId: orgData.id,
|
|
2827
|
-
organizationName: orgData.name || "Unknown Organization",
|
|
2828
|
-
subscriptionEndDate: orgData.masterSubscriptionEndDate || null,
|
|
2829
|
-
accessType: "organization"
|
|
2830
|
-
};
|
|
2831
|
-
}
|
|
2832
|
-
const institutionSnapshot = await api.getDocs(
|
|
2833
|
-
"institution_subscriptions",
|
|
2834
|
-
where2("users", "array-contains", email),
|
|
2835
|
-
where2("active", "==", true),
|
|
2836
|
-
limit2(1)
|
|
2837
|
-
);
|
|
2838
|
-
if (!institutionSnapshot.empty) {
|
|
2839
|
-
const institutionData = institutionSnapshot.data[0];
|
|
2840
|
-
const isUnlimited = (institutionData == null ? void 0 : institutionData.plan) === "organization" || (institutionData == null ? void 0 : institutionData.plan) === "school_starter";
|
|
2841
|
-
return {
|
|
2842
|
-
hasUnlimitedAccess: isUnlimited,
|
|
2843
|
-
subscriptionId: institutionData.id,
|
|
2844
|
-
organizationId: institutionData == null ? void 0 : institutionData.institutionId,
|
|
2845
|
-
organizationName: institutionData.name || institutionData.institutionId || "Legacy Institution",
|
|
2846
|
-
subscriptionEndDate: institutionData.endDate || null,
|
|
2847
|
-
accessType: "institution_subscriptions"
|
|
2848
|
-
};
|
|
2849
|
-
}
|
|
2850
|
-
return {
|
|
2851
|
-
hasUnlimitedAccess: false,
|
|
2852
|
-
subscriptionId: null,
|
|
2853
|
-
organizationId: null,
|
|
2854
|
-
organizationName: null,
|
|
2855
|
-
subscriptionEndDate: null,
|
|
2856
|
-
accessType: "individual"
|
|
2857
|
-
};
|
|
2858
|
-
} catch (error) {
|
|
2859
|
-
console.error("Error checking organization access:", error);
|
|
2860
|
-
return {
|
|
2861
|
-
hasUnlimitedAccess: false,
|
|
2862
|
-
subscriptionId: null,
|
|
2863
|
-
organizationId: null,
|
|
2864
|
-
organizationName: null,
|
|
2865
|
-
subscriptionEndDate: null,
|
|
2866
|
-
accessType: "individual"
|
|
2867
|
-
};
|
|
2868
|
-
}
|
|
2869
|
-
};
|
|
2870
|
-
|
|
2871
|
-
// src/hooks/useUpdateStudentVoc.ts
|
|
2872
|
-
var useUpdateStudentVocab = (page) => {
|
|
2873
|
-
const { user } = useSpeakableApi();
|
|
2874
|
-
const currentUserId = user == null ? void 0 : user.auth.uid;
|
|
2875
|
-
if (!page || !currentUserId || !page.target_text || !page.language) {
|
|
2876
|
-
return {
|
|
2877
|
-
studentVocabMarkVoiceSuccess: void 0,
|
|
2878
|
-
studentVocabMarkVoiceFail: void 0
|
|
2879
|
-
};
|
|
2880
|
-
}
|
|
2881
|
-
const getDataObject = () => {
|
|
2882
|
-
var _a, _b;
|
|
2883
|
-
const { serverTimestamp: serverTimestamp2 } = api.accessHelpers();
|
|
2884
|
-
const language = (_a = page.language) != null ? _a : "en";
|
|
2885
|
-
const word = (_b = page.target_text) != null ? _b : "";
|
|
2886
|
-
const phrase_length = getPhraseLength(word);
|
|
2887
|
-
const wordHash = getWordHash(word, language);
|
|
2888
|
-
const docPath = `users/${currentUserId}/vocab/${wordHash}`;
|
|
2889
|
-
const communityPath = `checked-pronunciations/${wordHash}`;
|
|
2890
|
-
const id = `${language}-${cleanString(word)}`;
|
|
2891
|
-
const data = {
|
|
2892
|
-
id,
|
|
2893
|
-
word,
|
|
2894
|
-
words: (word == null ? void 0 : word.split(" ")) || [],
|
|
2895
|
-
wordHash,
|
|
2896
|
-
language,
|
|
2897
|
-
lastSeen: serverTimestamp2(),
|
|
2898
|
-
phrase_length
|
|
2899
|
-
};
|
|
2900
|
-
return {
|
|
2901
|
-
docPath,
|
|
2902
|
-
communityPath,
|
|
2903
|
-
data
|
|
2904
|
-
};
|
|
2905
|
-
};
|
|
2906
|
-
const markVoiceSuccess = async () => {
|
|
2907
|
-
const { docPath, communityPath, data } = getDataObject();
|
|
2908
|
-
const { increment: increment2 } = api.accessQueryConstraints();
|
|
2909
|
-
const { serverTimestamp: serverTimestamp2 } = api.accessHelpers();
|
|
2910
|
-
data.voiceSuccess = increment2(1);
|
|
2911
|
-
try {
|
|
2912
|
-
await api.updateDoc(docPath, data);
|
|
2913
|
-
} catch (error) {
|
|
2914
|
-
if (error instanceof Error && error.message === "not-found") {
|
|
2915
|
-
data.firstSeen = serverTimestamp2();
|
|
2916
|
-
await api.setDoc(docPath, data, { merge: true });
|
|
2917
|
-
} else {
|
|
2918
|
-
console.log(error);
|
|
2919
|
-
}
|
|
2920
|
-
}
|
|
2921
|
-
try {
|
|
2922
|
-
data.pronunciations = increment2(1);
|
|
2923
|
-
await api.setDoc(communityPath, data, { merge: true });
|
|
2924
|
-
} catch (error) {
|
|
2925
|
-
console.log(error);
|
|
2926
|
-
}
|
|
2927
|
-
};
|
|
2928
|
-
const markVoiceFail = async () => {
|
|
2929
|
-
const { docPath, communityPath, data } = getDataObject();
|
|
2930
|
-
const { increment: increment2 } = api.accessQueryConstraints();
|
|
2931
|
-
const { serverTimestamp: serverTimestamp2 } = api.accessHelpers();
|
|
2932
|
-
data.voiceFail = increment2(1);
|
|
2933
|
-
try {
|
|
2934
|
-
await api.updateDoc(docPath, data);
|
|
2935
|
-
} catch (error) {
|
|
2936
|
-
if (error instanceof Error && error.message === "not-found") {
|
|
2937
|
-
data.firstSeen = serverTimestamp2();
|
|
2938
|
-
await api.setDoc(docPath, data, { merge: true });
|
|
2939
|
-
} else {
|
|
2940
|
-
console.log(error);
|
|
2941
|
-
}
|
|
2942
|
-
}
|
|
2943
|
-
try {
|
|
2944
|
-
data.fails = increment2(1);
|
|
2945
|
-
await api.setDoc(communityPath, data, { merge: true });
|
|
2946
|
-
} catch (error) {
|
|
2947
|
-
console.log(error);
|
|
2948
|
-
}
|
|
2949
|
-
};
|
|
2950
|
-
return {
|
|
2951
|
-
studentVocabMarkVoiceSuccess: markVoiceSuccess,
|
|
2952
|
-
studentVocabMarkVoiceFail: markVoiceFail
|
|
2953
|
-
};
|
|
2954
|
-
};
|
|
2955
|
-
|
|
2956
|
-
// src/hooks/useActivityFeedbackAccess.ts
|
|
2957
|
-
import { useQuery as useQuery7 } from "@tanstack/react-query";
|
|
2958
|
-
var activityFeedbackAccessQueryKeys = {
|
|
2959
|
-
activityFeedbackAccess: (args) => ["activityFeedbackAccess", ...Object.values(args)]
|
|
2960
|
-
};
|
|
2961
|
-
var useActivityFeedbackAccess = ({
|
|
2962
|
-
aiEnabled = false,
|
|
2963
|
-
isActivityRoute = false
|
|
2964
|
-
}) => {
|
|
2965
|
-
var _a, _b, _c;
|
|
2966
|
-
const { user } = useSpeakableApi();
|
|
2967
|
-
const uid = user.auth.uid;
|
|
2968
|
-
const isTeacher = (_a = user.profile) == null ? void 0 : _a.isTeacher;
|
|
2969
|
-
const isStudent = (_b = user.profile) == null ? void 0 : _b.isStudent;
|
|
2970
|
-
const userRoles = ((_c = user.profile) == null ? void 0 : _c.roles) || [];
|
|
2971
|
-
const query2 = useQuery7({
|
|
2972
|
-
queryKey: activityFeedbackAccessQueryKeys.activityFeedbackAccess({
|
|
2973
|
-
aiEnabled,
|
|
2974
|
-
isActivityRoute
|
|
2975
|
-
}),
|
|
2976
|
-
queryFn: async () => {
|
|
2977
|
-
var _a2, _b2, _c2;
|
|
2978
|
-
if (!uid) {
|
|
2979
|
-
return {
|
|
2980
|
-
canAccessFeedback: false,
|
|
2981
|
-
reason: "Missing user ID",
|
|
2982
|
-
isUnlimited: false,
|
|
2983
|
-
accessType: "none"
|
|
2984
|
-
};
|
|
2985
|
-
}
|
|
2986
|
-
try {
|
|
2987
|
-
if (aiEnabled) {
|
|
2988
|
-
return {
|
|
2989
|
-
canAccessFeedback: true,
|
|
2990
|
-
reason: "AI feedback enabled",
|
|
2991
|
-
isUnlimited: true,
|
|
2992
|
-
accessType: "ai_enabled"
|
|
2993
|
-
};
|
|
2994
|
-
}
|
|
2995
|
-
if (isTeacher || userRoles.includes("ADMIN")) {
|
|
2996
|
-
return {
|
|
2997
|
-
canAccessFeedback: true,
|
|
2998
|
-
reason: "Teacher preview access",
|
|
2999
|
-
isUnlimited: true,
|
|
3000
|
-
accessType: "teacher_preview"
|
|
3001
|
-
};
|
|
3002
|
-
}
|
|
3003
|
-
if (isStudent && isActivityRoute) {
|
|
3004
|
-
try {
|
|
3005
|
-
const result = await ((_c2 = (_b2 = (_a2 = api).httpsCallable) == null ? void 0 : _b2.call(_a2, "checkStudentTeacherPlan")) == null ? void 0 : _c2({
|
|
3006
|
-
studentId: uid
|
|
3007
|
-
}));
|
|
3008
|
-
const planCheckResult = result.data;
|
|
3009
|
-
if (planCheckResult.canAccessFeedback) {
|
|
3010
|
-
return {
|
|
3011
|
-
canAccessFeedback: true,
|
|
3012
|
-
reason: planCheckResult.reason || "Student access via teacher with active plan",
|
|
3013
|
-
isUnlimited: planCheckResult.hasTeacherWithUnlimitedAccess,
|
|
3014
|
-
accessType: "student_with_teacher_plan"
|
|
3015
|
-
};
|
|
3016
|
-
} else {
|
|
3017
|
-
return {
|
|
3018
|
-
canAccessFeedback: false,
|
|
3019
|
-
reason: planCheckResult.reason || "No teacher with active plan found",
|
|
3020
|
-
isUnlimited: false,
|
|
3021
|
-
accessType: "none"
|
|
3022
|
-
};
|
|
3023
|
-
}
|
|
3024
|
-
} catch (error) {
|
|
3025
|
-
console.error("Error checking student teacher plan:", error);
|
|
3026
|
-
return {
|
|
3027
|
-
canAccessFeedback: false,
|
|
3028
|
-
reason: "Error checking teacher plans",
|
|
3029
|
-
isUnlimited: false,
|
|
3030
|
-
accessType: "none"
|
|
3031
|
-
};
|
|
3032
|
-
}
|
|
3033
|
-
}
|
|
3034
|
-
return {
|
|
3035
|
-
canAccessFeedback: false,
|
|
3036
|
-
reason: "No access permissions found for current context",
|
|
3037
|
-
isUnlimited: false,
|
|
3038
|
-
accessType: "none"
|
|
3039
|
-
};
|
|
3040
|
-
} catch (error) {
|
|
3041
|
-
console.error("Error checking activity feedback access:", error);
|
|
3042
|
-
return {
|
|
3043
|
-
canAccessFeedback: false,
|
|
3044
|
-
reason: "Error checking access permissions",
|
|
3045
|
-
isUnlimited: false,
|
|
3046
|
-
accessType: "none"
|
|
3047
|
-
};
|
|
3048
|
-
}
|
|
3049
|
-
},
|
|
3050
|
-
enabled: !!uid,
|
|
3051
|
-
staleTime: 5 * 60 * 1e3,
|
|
3052
|
-
// 5 minutes
|
|
3053
|
-
gcTime: 10 * 60 * 1e3
|
|
3054
|
-
// 10 minutes
|
|
3055
|
-
});
|
|
3056
|
-
return {
|
|
3057
|
-
...query2
|
|
3058
|
-
};
|
|
3059
|
-
};
|
|
3060
|
-
|
|
3061
|
-
// src/hooks/useOpenAI.ts
|
|
3062
|
-
var useBaseOpenAI = ({
|
|
3063
|
-
onTranscriptSuccess,
|
|
3064
|
-
onTranscriptError,
|
|
3065
|
-
onCompletionSuccess,
|
|
3066
|
-
onCompletionError,
|
|
3067
|
-
aiEnabled,
|
|
3068
|
-
submitAudioResponse,
|
|
3069
|
-
uploadAudioAndGetTranscript,
|
|
3070
|
-
onGetAudioUrlAndTranscript
|
|
3071
|
-
}) => {
|
|
3072
|
-
const { user, queryClient } = useSpeakableApi();
|
|
3073
|
-
const currentUserId = user.auth.uid;
|
|
3074
|
-
const { data: feedbackAccess } = useActivityFeedbackAccess({
|
|
3075
|
-
aiEnabled
|
|
3076
|
-
});
|
|
3077
|
-
const getTranscript = async (audioUrl, language, prompt) => {
|
|
3078
|
-
var _a, _b, _c, _d;
|
|
3079
|
-
const getGeminiTranscript = (_b = (_a = api).httpsCallable) == null ? void 0 : _b.call(_a, "getGeminiTranscript");
|
|
3080
|
-
const getAssemblyAITranscript = (_d = (_c = api).httpsCallable) == null ? void 0 : _d.call(_c, "transcribeAssemblyAIAudio");
|
|
3081
|
-
try {
|
|
3082
|
-
const { data } = await (getGeminiTranscript == null ? void 0 : getGeminiTranscript({
|
|
3083
|
-
audioUrl,
|
|
3084
|
-
targetLanguage: language,
|
|
3085
|
-
prompt: prompt || ""
|
|
3086
|
-
}));
|
|
3087
|
-
const transcript = data.transcript;
|
|
3088
|
-
if (transcript) {
|
|
3089
|
-
return transcript;
|
|
3090
|
-
}
|
|
3091
|
-
} catch (error) {
|
|
3092
|
-
console.log("Gemini transcript failed, trying AssemblyAI fallback:", error);
|
|
3093
|
-
}
|
|
3094
|
-
try {
|
|
3095
|
-
const response = await (getAssemblyAITranscript == null ? void 0 : getAssemblyAITranscript({
|
|
3096
|
-
audioUrl,
|
|
3097
|
-
language
|
|
3098
|
-
}));
|
|
3099
|
-
const transcript = response == null ? void 0 : response.data;
|
|
3100
|
-
if (transcript) {
|
|
3101
|
-
return transcript;
|
|
3102
|
-
}
|
|
3103
|
-
throw new Error("Both transcript services failed");
|
|
3104
|
-
} catch (error) {
|
|
3105
|
-
console.log("AssemblyAI transcript also failed:", error);
|
|
3106
|
-
onTranscriptError({
|
|
3107
|
-
type: "TRANSCRIPT",
|
|
3108
|
-
message: (error == null ? void 0 : error.message) || "Error getting transcript from both services"
|
|
3109
|
-
});
|
|
3110
|
-
throw new Error(error);
|
|
3111
|
-
}
|
|
3112
|
-
};
|
|
3113
|
-
const getFreeResponseCompletion = async (messages, isFreeResponse, feedbackLanguage, gradingStandard = "actfl") => {
|
|
3114
|
-
var _a, _b, _c, _d, _e;
|
|
3115
|
-
const responseTool = getRespondCardTool({
|
|
3116
|
-
language: feedbackLanguage,
|
|
3117
|
-
standard: gradingStandard
|
|
3118
|
-
});
|
|
3119
|
-
try {
|
|
3120
|
-
const createChatCompletion = (_b = (_a = api).httpsCallable) == null ? void 0 : _b.call(_a, "createChatCompletion");
|
|
3121
|
-
const {
|
|
3122
|
-
data: {
|
|
3123
|
-
response,
|
|
3124
|
-
prompt_tokens = 0,
|
|
3125
|
-
completion_tokens = 0,
|
|
3126
|
-
success: aiSuccess = false
|
|
3127
|
-
// the AI was able to generate a response
|
|
3128
|
-
}
|
|
3129
|
-
} = await (createChatCompletion == null ? void 0 : createChatCompletion({
|
|
3130
|
-
chat: {
|
|
3131
|
-
model: isFreeResponse ? "gpt-4-1106-preview" : "gpt-3.5-turbo-1106",
|
|
3132
|
-
messages,
|
|
3133
|
-
temperature: 0.7,
|
|
3134
|
-
...responseTool
|
|
3135
|
-
},
|
|
3136
|
-
type: isFreeResponse ? "LONG_RESPONSE" : "SHORT_RESPONSE"
|
|
3137
|
-
}));
|
|
3138
|
-
const functionArguments = JSON.parse(((_e = (_d = (_c = response == null ? void 0 : response.tool_calls) == null ? void 0 : _c[0]) == null ? void 0 : _d.function) == null ? void 0 : _e.arguments) || "{}");
|
|
3139
|
-
const result = {
|
|
3140
|
-
...functionArguments,
|
|
3141
|
-
prompt_tokens,
|
|
3142
|
-
completion_tokens,
|
|
3143
|
-
aiSuccess
|
|
3144
|
-
};
|
|
3145
|
-
onCompletionSuccess(result);
|
|
3146
|
-
return result;
|
|
3147
|
-
} catch (error) {
|
|
3148
|
-
onCompletionError({
|
|
3149
|
-
type: "COMPLETION",
|
|
3150
|
-
message: (error == null ? void 0 : error.message) || "Error getting completion"
|
|
3151
|
-
});
|
|
3152
|
-
throw new Error(error);
|
|
3153
|
-
}
|
|
3154
|
-
};
|
|
3155
|
-
const getFeedback = async ({
|
|
3156
|
-
cardId,
|
|
3157
|
-
language = "en",
|
|
3158
|
-
// required
|
|
3159
|
-
writtenResponse = null,
|
|
3160
|
-
// if the type = RESPOND_WRITE
|
|
3161
|
-
audio = null,
|
|
3162
|
-
autoGrade = true,
|
|
3163
|
-
file = null,
|
|
3164
|
-
pagePrompt = null
|
|
3165
|
-
}) => {
|
|
3166
|
-
try {
|
|
3167
|
-
if (!(feedbackAccess == null ? void 0 : feedbackAccess.canAccessFeedback)) {
|
|
3168
|
-
const result = {
|
|
3169
|
-
noFeedbackAvailable: true,
|
|
3170
|
-
success: true,
|
|
3171
|
-
reason: (feedbackAccess == null ? void 0 : feedbackAccess.reason) || "No feedback access",
|
|
3172
|
-
accessType: (feedbackAccess == null ? void 0 : feedbackAccess.accessType) || "none"
|
|
3173
|
-
};
|
|
3174
|
-
onCompletionSuccess(result);
|
|
3175
|
-
return result;
|
|
3176
|
-
}
|
|
3177
|
-
let transcript;
|
|
3178
|
-
let audioUrl = void 0;
|
|
3179
|
-
if (writtenResponse) {
|
|
3180
|
-
transcript = writtenResponse;
|
|
3181
|
-
onTranscriptSuccess(writtenResponse);
|
|
3182
|
-
} else if (typeof audio === "string" && file) {
|
|
3183
|
-
if (feedbackAccess == null ? void 0 : feedbackAccess.canAccessFeedback) {
|
|
3184
|
-
transcript = await getTranscript(audio, language, pagePrompt != null ? pagePrompt : "");
|
|
3185
|
-
audioUrl = audio;
|
|
3186
|
-
onTranscriptSuccess(transcript);
|
|
3187
|
-
} else {
|
|
3188
|
-
console.info(
|
|
3189
|
-
`Transcript not available: ${(feedbackAccess == null ? void 0 : feedbackAccess.reason) || "No feedback access"}`
|
|
3190
|
-
);
|
|
3191
|
-
}
|
|
3192
|
-
} else {
|
|
3193
|
-
const response = await uploadAudioAndGetTranscript(audio || "", language, pagePrompt != null ? pagePrompt : "");
|
|
3194
|
-
transcript = response.transcript;
|
|
3195
|
-
audioUrl = response.audioUrl;
|
|
3196
|
-
}
|
|
3197
|
-
onGetAudioUrlAndTranscript == null ? void 0 : onGetAudioUrlAndTranscript({ transcript, audioUrl });
|
|
3198
|
-
if (feedbackAccess == null ? void 0 : feedbackAccess.canAccessFeedback) {
|
|
3199
|
-
const results = await getAIResponse({
|
|
3200
|
-
cardId,
|
|
3201
|
-
transcript: transcript || ""
|
|
3202
|
-
});
|
|
3203
|
-
let output = results;
|
|
3204
|
-
if (!autoGrade) {
|
|
3205
|
-
output = {
|
|
3206
|
-
...output,
|
|
3207
|
-
noFeedbackAvailable: true,
|
|
3208
|
-
success: true
|
|
3209
|
-
};
|
|
3210
|
-
}
|
|
3211
|
-
onCompletionSuccess(output);
|
|
3212
|
-
return output;
|
|
3213
|
-
} else {
|
|
3214
|
-
const result = {
|
|
3215
|
-
noFeedbackAvailable: true,
|
|
3216
|
-
success: true,
|
|
3217
|
-
reason: (feedbackAccess == null ? void 0 : feedbackAccess.reason) || "No feedback access",
|
|
3218
|
-
accessType: (feedbackAccess == null ? void 0 : feedbackAccess.accessType) || "none"
|
|
3219
|
-
};
|
|
3220
|
-
onCompletionSuccess(result);
|
|
3221
|
-
return result;
|
|
3222
|
-
}
|
|
3223
|
-
} catch (error) {
|
|
3224
|
-
console.error("Error getting feedback:", error);
|
|
3225
|
-
throw new Error(error);
|
|
3226
|
-
}
|
|
3227
|
-
};
|
|
3228
|
-
const getAIResponse = async ({ cardId, transcript }) => {
|
|
3229
|
-
var _a, _b, _c, _d, _e;
|
|
3230
|
-
try {
|
|
3231
|
-
const getGeminiFeedback = (_b = (_a = api).httpsCallable) == null ? void 0 : _b.call(_a, "callGetFeedback");
|
|
3232
|
-
const getProficiencyEstimate = (_d = (_c = api).httpsCallable) == null ? void 0 : _d.call(_c, "getProficiencyEstimate");
|
|
3233
|
-
const card = getCardFromCache({
|
|
3234
|
-
cardId,
|
|
3235
|
-
queryClient
|
|
3236
|
-
});
|
|
3237
|
-
let feedbackData;
|
|
3238
|
-
let proficiencyData = {};
|
|
3239
|
-
if (card && card.grading_method === "manual") {
|
|
3240
|
-
} else if (card && card.grading_method !== "standards_based") {
|
|
3241
|
-
const [geminiResult, proficiencyResult] = await Promise.all([
|
|
3242
|
-
getGeminiFeedback == null ? void 0 : getGeminiFeedback({
|
|
3243
|
-
cardId,
|
|
3244
|
-
studentId: currentUserId,
|
|
3245
|
-
studentResponse: transcript
|
|
3246
|
-
}),
|
|
3247
|
-
getProficiencyEstimate == null ? void 0 : getProficiencyEstimate({
|
|
3248
|
-
cardId,
|
|
3249
|
-
studentId: currentUserId,
|
|
3250
|
-
studentResponse: transcript
|
|
3251
|
-
})
|
|
3252
|
-
]);
|
|
3253
|
-
proficiencyData = (proficiencyResult == null ? void 0 : proficiencyResult.data) || {};
|
|
3254
|
-
feedbackData = {
|
|
3255
|
-
...(_e = geminiResult == null ? void 0 : geminiResult.data) != null ? _e : {},
|
|
3256
|
-
// @ts-ignore
|
|
3257
|
-
proficiency_level: (proficiencyData == null ? void 0 : proficiencyData.proficiency_level) || null
|
|
3258
|
-
};
|
|
3259
|
-
} else {
|
|
3260
|
-
const geminiResult = await (getGeminiFeedback == null ? void 0 : getGeminiFeedback({
|
|
3261
|
-
cardId,
|
|
3262
|
-
studentId: currentUserId,
|
|
3263
|
-
studentResponse: transcript
|
|
3264
|
-
}));
|
|
3265
|
-
feedbackData = geminiResult == null ? void 0 : geminiResult.data;
|
|
3266
|
-
}
|
|
3267
|
-
const results = {
|
|
3268
|
-
...proficiencyData,
|
|
3269
|
-
...feedbackData,
|
|
3270
|
-
aiSuccess: true,
|
|
3271
|
-
promptSuccess: (feedbackData == null ? void 0 : feedbackData.success) || false,
|
|
3272
|
-
transcript
|
|
3273
|
-
};
|
|
3274
|
-
return results;
|
|
3275
|
-
} catch (error) {
|
|
3276
|
-
onCompletionError({
|
|
3277
|
-
type: "AI_FEEDBACK",
|
|
3278
|
-
message: (error == null ? void 0 : error.message) || "Error getting ai feedback"
|
|
3279
|
-
});
|
|
3280
|
-
throw new Error(error);
|
|
3281
|
-
}
|
|
3282
|
-
};
|
|
3283
|
-
return {
|
|
3284
|
-
submitAudioResponse,
|
|
3285
|
-
uploadAudioAndGetTranscript,
|
|
3286
|
-
getTranscript,
|
|
3287
|
-
getFreeResponseCompletion,
|
|
3288
|
-
getFeedback
|
|
3289
|
-
};
|
|
3290
|
-
};
|
|
3291
|
-
|
|
3292
|
-
// src/lib/create-firebase-client-native.ts
|
|
3293
|
-
import {
|
|
3294
|
-
getDoc,
|
|
3295
|
-
getDocs,
|
|
3296
|
-
addDoc,
|
|
3297
|
-
setDoc,
|
|
3298
|
-
updateDoc,
|
|
3299
|
-
deleteDoc,
|
|
3300
|
-
runTransaction,
|
|
3301
|
-
writeBatch,
|
|
3302
|
-
doc,
|
|
3303
|
-
collection,
|
|
3304
|
-
query,
|
|
3305
|
-
serverTimestamp,
|
|
3306
|
-
orderBy,
|
|
3307
|
-
limit,
|
|
3308
|
-
startAt,
|
|
3309
|
-
startAfter,
|
|
3310
|
-
endAt,
|
|
3311
|
-
endBefore,
|
|
3312
|
-
where,
|
|
3313
|
-
increment
|
|
3314
|
-
} from "@react-native-firebase/firestore";
|
|
3315
|
-
|
|
3316
1030
|
// src/lib/create-firebase-client.ts
|
|
3317
1031
|
function createFsClientBase({
|
|
3318
1032
|
db,
|
|
@@ -3364,76 +1078,6 @@ var createFsClientNative = ({ db, httpsCallable, logEvent }) => {
|
|
|
3364
1078
|
});
|
|
3365
1079
|
};
|
|
3366
1080
|
export {
|
|
3367
|
-
|
|
3368
|
-
BASE_MULTIPLE_CHOICE_FIELD_VALUES,
|
|
3369
|
-
BASE_REPEAT_FIELD_VALUES,
|
|
3370
|
-
BASE_RESPOND_FIELD_VALUES,
|
|
3371
|
-
FeedbackTypesCard,
|
|
3372
|
-
FsCtx,
|
|
3373
|
-
LENIENCY_OPTIONS,
|
|
3374
|
-
LeniencyCard,
|
|
3375
|
-
MULTIPLE_CHOICE_PAGE_ACTIVITY_TYPES,
|
|
3376
|
-
REPEAT_PAGE_ACTIVITY_TYPES,
|
|
3377
|
-
RESPOND_AUDIO_PAGE_ACTIVITY_TYPES,
|
|
3378
|
-
RESPOND_PAGE_ACTIVITY_TYPES,
|
|
3379
|
-
RESPOND_WRITE_PAGE_ACTIVITY_TYPES,
|
|
3380
|
-
SPEAKABLE_NOTIFICATIONS,
|
|
3381
|
-
STUDENT_LEVELS_OPTIONS,
|
|
3382
|
-
SpeakableNotificationTypes,
|
|
3383
|
-
SpeakableProvider,
|
|
3384
|
-
VerificationCardStatus,
|
|
3385
|
-
assignmentQueryKeys,
|
|
3386
|
-
cardsQueryKeys,
|
|
3387
|
-
checkIsMCPage,
|
|
3388
|
-
checkIsMediaPage,
|
|
3389
|
-
checkIsRepeatPage,
|
|
3390
|
-
checkIsRespondAudioPage,
|
|
3391
|
-
checkIsRespondPage,
|
|
3392
|
-
checkIsRespondWrittenPage,
|
|
3393
|
-
checkIsShortAnswerPage,
|
|
3394
|
-
checkTypePageActivity,
|
|
3395
|
-
cleanString,
|
|
3396
|
-
createAssignmentRepo,
|
|
3397
|
-
createCardRepo,
|
|
3398
|
-
createFsClientNative as createFsClient,
|
|
3399
|
-
createSetRepo,
|
|
3400
|
-
creditQueryKeys,
|
|
3401
|
-
debounce,
|
|
3402
|
-
getCardFromCache,
|
|
3403
|
-
getLabelPage,
|
|
3404
|
-
getPagePrompt,
|
|
3405
|
-
getPhraseLength,
|
|
3406
|
-
getRespondCardTool,
|
|
3407
|
-
getSetFromCache,
|
|
3408
|
-
getTotalCompletedCards,
|
|
3409
|
-
getWordHash,
|
|
3410
|
-
purify,
|
|
3411
|
-
refsCardsFiresotre,
|
|
3412
|
-
refsSetsFirestore,
|
|
3413
|
-
scoreQueryKeys,
|
|
3414
|
-
setsQueryKeys,
|
|
3415
|
-
updateCardInCache,
|
|
3416
|
-
updateSetInCache,
|
|
3417
|
-
useActivity,
|
|
3418
|
-
useActivityFeedbackAccess,
|
|
3419
|
-
useAssignment,
|
|
3420
|
-
useBaseOpenAI,
|
|
3421
|
-
useCards,
|
|
3422
|
-
useClearScore,
|
|
3423
|
-
useClearScoreV2,
|
|
3424
|
-
useCreateCard,
|
|
3425
|
-
useCreateCards,
|
|
3426
|
-
useCreateNotification,
|
|
3427
|
-
useGetCard,
|
|
3428
|
-
useOrganizationAccess,
|
|
3429
|
-
useScore,
|
|
3430
|
-
useSet,
|
|
3431
|
-
useSpeakableApi,
|
|
3432
|
-
useSubmitAssignmentScore,
|
|
3433
|
-
useSubmitPracticeScore,
|
|
3434
|
-
useUpdateCardScore,
|
|
3435
|
-
useUpdateScore,
|
|
3436
|
-
useUpdateStudentVocab,
|
|
3437
|
-
useUserCredits
|
|
1081
|
+
createFsClientNative as createFsClient
|
|
3438
1082
|
};
|
|
3439
1083
|
//# sourceMappingURL=index.native.mjs.map
|