Arsekl пре 3 година
родитељ
комит
70e6701b06
1 измењених фајлова са 17 додато и 8 уклоњено
  1. 17 8
      src/utils/index.ts

+ 17 - 8
src/utils/index.ts

@@ -273,25 +273,34 @@ export function getQuestion(examId: string, studentId: string) {
             response => {
                 hide()
                 if (response.err === 0) {
-                    store.dispatch(loadQuestion(response.res))
-                    const current = store.getState().loadCurrentQuestion
+                    store.dispatch(loadQuestion(response.res));
+                    const question = response.res;
+                    const current = store.getState().loadCurrentQuestion;
                     if (Object.keys(current).length === 0) {
-                        store.dispatch(loadCurrentQuestion(response.res.codeList[0]))
-                        generateFileTree(response.res.codeList[0])
+                        store.dispatch(loadCurrentQuestion(response.res.codeList[0]));
+                        generateFileTree(response.res.codeList[0]);
+                    } else {
+                        for (let i = 0; i < question.codeList.length; i++){
+                            if (question.codeList[i].questionId === current.questionId) {
+                                store.dispatch(loadCurrentQuestion(question.codeList[i]));
+                                generateFileTree(question.codeList[i]);
+                                break;
+                            }
+                        }
                     }
                 }
                 return response;
             }).then(response => {
                 if (response.err) {
-                    notification.error({key: 'QuestionError', message: response.msg})
+                    notification.error({key: 'QuestionError', message: response.msg});
                 }
             }
         ).catch(reason => {
                 console.log(reason)
-                notification.error({key: 'QuestionError', message: reason})
+                notification.error({key: 'QuestionError', message: reason});
             }
         )
     } else {
-        notification.error({key: 'ParamError', message: "Parameter Error"})
+        notification.error({key: 'ParamError', message: "Parameter Error"});
     }
-}
+}