@speakableio/core 0.1.64 → 0.1.66

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.web.js CHANGED
@@ -95,7 +95,7 @@ var FirebaseAPI = class _FirebaseAPI {
95
95
  (_a = this.config) == null ? void 0 : _a.logEvent(name, data);
96
96
  }
97
97
  accessQueryConstraints() {
98
- const { query: query2, orderBy: orderBy2, limit: limit2, startAt: startAt2, startAfter: startAfter2, endAt: endAt2, endBefore: endBefore2, where: where2 } = this.helpers;
98
+ const { query: query2, orderBy: orderBy2, limit: limit2, startAt: startAt2, startAfter: startAfter2, endAt: endAt2, endBefore: endBefore2, where: where2, increment: increment2 } = this.helpers;
99
99
  return {
100
100
  query: query2,
101
101
  orderBy: orderBy2,
@@ -104,7 +104,8 @@ var FirebaseAPI = class _FirebaseAPI {
104
104
  startAfter: startAfter2,
105
105
  endAt: endAt2,
106
106
  endBefore: endBefore2,
107
- where: where2
107
+ where: where2,
108
+ increment: increment2
108
109
  };
109
110
  }
110
111
  accessHelpers() {
@@ -1669,6 +1670,13 @@ var getWordHash = (word, language) => {
1669
1670
  console.log("wordHash core library", wordHash);
1670
1671
  return wordHash;
1671
1672
  };
1673
+ function getPhraseLength(phrase, input) {
1674
+ if (Array.isArray(phrase) && phrase.includes(input)) {
1675
+ return phrase[phrase.indexOf(input)].split(" ").length;
1676
+ } else {
1677
+ return phrase ? phrase.split(" ").length : 0;
1678
+ }
1679
+ }
1672
1680
 
1673
1681
  // src/domains/cards/services/get-card-verification-status.service.ts
1674
1682
  var charactarLanguages = ["zh", "ja", "ko"];
@@ -2675,6 +2683,91 @@ var getOrganizationAccess = async (email) => {
2675
2683
  }
2676
2684
  };
2677
2685
 
2686
+ // src/hooks/useUpdateStudentVoc.ts
2687
+ var useUpdateStudentVocab = (page) => {
2688
+ const { user } = useSpeakableApi();
2689
+ const currentUserId = user == null ? void 0 : user.auth.uid;
2690
+ if (!page || !currentUserId || !page.target_text || !page.language) {
2691
+ return {
2692
+ markVoiceSuccess: void 0,
2693
+ markVoiceFail: void 0
2694
+ };
2695
+ }
2696
+ const getDataObject = () => {
2697
+ var _a, _b;
2698
+ const { serverTimestamp: serverTimestamp2 } = api.accessHelpers();
2699
+ const language = (_a = page.language) != null ? _a : "en";
2700
+ const word = (_b = page.target_text) != null ? _b : "";
2701
+ const phrase_length = getPhraseLength(word);
2702
+ const wordHash = getWordHash(word, language);
2703
+ const docPath = `users/${currentUserId}/vocab/${wordHash}`;
2704
+ const communityPath = `checked-pronunciations/${wordHash}`;
2705
+ const id = `${language}-${cleanString(word)}`;
2706
+ const data = {
2707
+ id,
2708
+ word,
2709
+ words: (word == null ? void 0 : word.split(" ")) || [],
2710
+ wordHash,
2711
+ language,
2712
+ lastSeen: serverTimestamp2(),
2713
+ phrase_length
2714
+ };
2715
+ return {
2716
+ docPath,
2717
+ communityPath,
2718
+ data
2719
+ };
2720
+ };
2721
+ const markVoiceSuccess = async () => {
2722
+ const { docPath, communityPath, data } = getDataObject();
2723
+ const { increment: increment2 } = api.accessQueryConstraints();
2724
+ const { serverTimestamp: serverTimestamp2 } = api.accessHelpers();
2725
+ data.voiceSuccess = increment2(1);
2726
+ try {
2727
+ await api.updateDoc(docPath, data);
2728
+ } catch (error) {
2729
+ if (error instanceof Error && error.message === "not-found") {
2730
+ data.firstSeen = serverTimestamp2();
2731
+ await api.setDoc(docPath, data);
2732
+ } else {
2733
+ console.log(error);
2734
+ }
2735
+ }
2736
+ try {
2737
+ data.pronunciations = increment2(1);
2738
+ await api.setDoc(communityPath, data, { merge: true });
2739
+ } catch (error) {
2740
+ console.log(error);
2741
+ }
2742
+ };
2743
+ const markVoiceFail = async () => {
2744
+ const { docPath, communityPath, data } = getDataObject();
2745
+ const { increment: increment2 } = api.accessQueryConstraints();
2746
+ const { serverTimestamp: serverTimestamp2 } = api.accessHelpers();
2747
+ data.voiceFail = increment2(1);
2748
+ try {
2749
+ await api.updateDoc(docPath, data);
2750
+ } catch (error) {
2751
+ if (error instanceof Error && error.message === "not-found") {
2752
+ data.firstSeen = serverTimestamp2();
2753
+ await api.setDoc(docPath, data);
2754
+ } else {
2755
+ console.log(error);
2756
+ }
2757
+ }
2758
+ try {
2759
+ data.fails = increment2(1);
2760
+ await api.setDoc(communityPath, data, { merge: true });
2761
+ } catch (error) {
2762
+ console.log(error);
2763
+ }
2764
+ };
2765
+ return {
2766
+ studentVocabMarkVoiceSuccess: markVoiceSuccess,
2767
+ studentVocabMarkVoiceFail: markVoiceFail
2768
+ };
2769
+ };
2770
+
2678
2771
  // src/hooks/useActivityFeedbackAccess.ts
2679
2772
  import { useQuery as useQuery7 } from "@tanstack/react-query";
2680
2773
  var activityFeedbackAccessQueryKeys = {
@@ -3014,7 +3107,8 @@ import {
3014
3107
  startAfter,
3015
3108
  endAt,
3016
3109
  endBefore,
3017
- where
3110
+ where,
3111
+ increment
3018
3112
  } from "firebase/firestore";
3019
3113
 
3020
3114
  // src/lib/create-firebase-client.ts
@@ -3062,7 +3156,8 @@ var createFsClientWeb = ({ db, httpsCallable, logEvent }) => {
3062
3156
  startAfter,
3063
3157
  endAt,
3064
3158
  endBefore,
3065
- where
3159
+ where,
3160
+ increment
3066
3161
  }
3067
3162
  });
3068
3163
  };
@@ -3104,6 +3199,7 @@ export {
3104
3199
  debounce,
3105
3200
  getCardFromCache,
3106
3201
  getPagePrompt,
3202
+ getPhraseLength,
3107
3203
  getRespondCardTool,
3108
3204
  getSetFromCache,
3109
3205
  getWordHash,
@@ -3132,6 +3228,7 @@ export {
3132
3228
  useSubmitPracticeScore,
3133
3229
  useUpdateCardScore,
3134
3230
  useUpdateScore,
3231
+ useUpdateStudentVocab,
3135
3232
  useUserCredits
3136
3233
  };
3137
3234
  //# sourceMappingURL=index.web.js.map