diff --git a/src/components/Modals/AIToolModal.tsx b/src/components/Modals/AIToolModal.tsx index dbbfc7c..f7ba84a 100644 --- a/src/components/Modals/AIToolModal.tsx +++ b/src/components/Modals/AIToolModal.tsx @@ -24,7 +24,14 @@ import { AxiosResponse } from 'axios'; import { useState } from 'react'; import { useFormContext } from 'react-hook-form'; import { API } from '../../data/api'; -import { TypeOfExercise } from '../../types/polyglotElements/AIGenerativeTypes/AIGenerativeTypes'; +import { + AIExerciseGenerated, + AIMaterialGenerated, + EducationLevel, + LearningOutcome, + QuestionType, + Topic, +} from '../../types/polyglotElements/AIGenerativeTypes/AIGenerativeTypes'; export type ModaTemplateProps = { isOpen: boolean; @@ -33,16 +40,19 @@ export type ModaTemplateProps = { action?: (i: boolean) => void; }; -export type Topic = { - Topic: string; - Type: TypeOfExercise; - Description: string; -}; - function delay(ms: number) { return new Promise((resolve) => setTimeout(resolve, ms)); } +function shuffleArray(array: T[]) { + const arr = [...array]; + for (let i = arr.length - 1; i > 0; i--) { + const j = Math.floor(Math.random() * (i + 1)); + [arr[i], arr[j]] = [arr[j], arr[i]]; + } + return arr; +} + const AIToolModal = ({ isOpen, onClose, @@ -53,19 +63,21 @@ const AIToolModal = ({ const [sourceMaterial, setSourceMaterial] = useState(''); const [titleGen, setTitle] = useState(''); const [macroSubjectGen, setMacroSubject] = useState(''); + const [learningOutcome, setLearningOutcome] = useState(); + const [choosingLearningOutcome, setChoosingLearningOutcome] = + useState(); const [language, setLanguage] = useState(''); - const [level, setLevel] = useState(0); + const [duration, setDuration] = useState(0); + const [eduLevel, setEduLevel] = useState(); const [topicGen, setTopicGen] = useState([ - { Topic: 'prova', Type: 0, Description: '' }, + { topic: 'prova', explanation: '' }, ]); + const [topicIndex, setTopicIndex] = useState(0); - let exerciseType: number; - const [noW, setNoW] = useState(200); + let exerciseType: QuestionType | string; const [ca_n, setCA_N] = useState(1); const [da_n, setDA_N] = useState(1); const [eda_n, setEDA_N] = useState(1); - const [choices, setChoices] = useState(['']); - const [choiceIndex, setChoiceIndex] = useState(0); const [screen1, setScreen1] = useState(true); const [screen2, setScreen2] = useState(false); const [screen3, setScreen3] = useState(false); @@ -74,19 +86,19 @@ const AIToolModal = ({ const word = exType == 'TrueFalseNode' ? 'Statements' : 'Answers'; switch (exType) { case 'closeEndedQuestionNode': - exerciseType = 3; + exerciseType = QuestionType.ShortAnswerQuestion; break; case 'OpenQuestionNode': - exerciseType = 0; + exerciseType = QuestionType.OpenQuestion; break; case 'TrueFalseNode': - exerciseType = 4; + exerciseType = QuestionType.TrueOrFalse; break; case 'multipleChoiceQuestionNode': - exerciseType = 4; + exerciseType = QuestionType.MultipleChoice; break; case 'ReadMaterialNode': - exerciseType = 100; + exerciseType = 'ReadMaterial'; break; default: throw 'error in type'; @@ -134,14 +146,22 @@ const AIToolModal = ({ throw ': no text given'; } const response: AxiosResponse = await API.analyseMaterial({ - material: sourceMaterial, + text: sourceMaterial, }); console.log(response); - setTitle(response.data.Title); - setLanguage(response.data.Language); - setMacroSubject(response.data.MacroSubject); - setLevel(response.data.PerceivedDifficulty); - setTopicGen(response.data.MainTopics); + setTitle(response.data.title); + setLanguage(response.data.language); + setMacroSubject(response.data.macro_subject); + setLearningOutcome( + response.data.learning_outcome as LearningOutcome + ); + setChoosingLearningOutcome( + response.data.learning_outcome as LearningOutcome + ); + setEduLevel(response.data.education_level as EducationLevel); + setLanguage(response.data.language); + setDuration(response.data.estimated_duration); + setTopicGen(response.data.topics); setScreen1(false); setScreen2(true); } catch (error: any) { @@ -206,19 +226,19 @@ const AIToolModal = ({ paddingTop={'5px'} paddingBottom={'-5px'} > - Level: + Educational Level: @@ -241,7 +261,7 @@ const AIToolModal = ({ {topicGen.map((p, id) => { return ( ); })} @@ -257,32 +277,12 @@ const AIToolModal = ({ > Topic Description: - {topicGen[topicIndex].Description} + {topicGen[topicIndex].explanation}