From 504b8059ff4e162e089177e366a312dd583d5cff Mon Sep 17 00:00:00 2001
From: bobzel <zzzman@gmail.com>
Date: Mon, 7 Oct 2024 21:47:05 -0400
Subject: moved some more quiz functions to styleProviderQuiz

---
 src/client/views/StyleProviderQuiz.tsx | 21 ++++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)

(limited to 'src/client/views/StyleProviderQuiz.tsx')

diff --git a/src/client/views/StyleProviderQuiz.tsx b/src/client/views/StyleProviderQuiz.tsx
index 8973ada95..1f2ad1485 100644
--- a/src/client/views/StyleProviderQuiz.tsx
+++ b/src/client/views/StyleProviderQuiz.tsx
@@ -83,7 +83,7 @@ export namespace styleProviderQuiz {
         imgBox.Document._quizMode = quiz;
         const quizBoxes = DocListCast(imgBox.Document.quizBoxes);
         if (!quizBoxes.length) {
-            //    this._loading = true;
+            imgBox.Loading = true;
 
             const img = {
                 file: i ? i : imgBox.paths[0],
@@ -98,7 +98,7 @@ export namespace styleProviderQuiz {
             if (response.data['boxes'].length != 0) {
                 createBoxes(imgBox, response.data['boxes'], response.data['text']);
             } else {
-                // this._loading = false;
+                imgBox.Loading = false;
             }
         } else quizBoxes.forEach(box => (box.hidden = false));
     }
@@ -121,7 +121,7 @@ export namespace styleProviderQuiz {
      * Create flashcards from an image.
      */
     async function getImageDesc(img: ImageBox) {
-        // this._loading = true;
+        img.Loading = true;
         try {
             const hrefBase64 = await createCanvas(img);
             const response = await gptImageLabel(hrefBase64, 'Make flashcards out of this image with each question and answer labeled as "question" and "answer". Do not label each flashcard and do not include asterisks: ');
@@ -129,7 +129,7 @@ export namespace styleProviderQuiz {
         } catch (error) {
             console.log('Error', error);
         }
-        // this._loading = false;
+        img.Loading = false;
     }
 
     /**
@@ -241,14 +241,21 @@ export namespace styleProviderQuiz {
             return { error: 'The input string does not match the expected format.' };
         }
     }
+    function imgQuizBoxes(img: ImageBox) {
+        return DocListCast(img.Document.quizBoxes);
+    }
+    function imgQuizMode(img: ImageBox) {
+        return StrCast(img.Document._quizMode);
+    }
+
     /**
      * Check whether the contents of the label boxes on an image are correct.
      */
     function check(img: ImageBox) {
         //this._loading = true;
-        img.quizBoxes.forEach(async doc => {
+        imgQuizBoxes(img).forEach(async doc => {
             const input = StrCast(doc[DocData].title);
-            if (img.quizMode == quizMode.SMART && input) {
+            if (imgQuizMode(img) == quizMode.SMART && input) {
                 const questionText = 'Question: What was labeled in this image?';
                 const rubricText = ' Rubric: ' + StrCast(doc.quiz);
                 const queryText =
@@ -271,7 +278,7 @@ export namespace styleProviderQuiz {
     }
 
     function redo(img: ImageBox) {
-        img.quizBoxes.forEach(doc => {
+        imgQuizBoxes(img).forEach(doc => {
             doc[DocData].title = '';
             doc.backgroundColor = '#e4e4e4';
         });
-- 
cgit v1.2.3-70-g09d2

