pre AI
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import {LoadingList} from "../components/LoadingList.tsx";
|
||||
import {Survey} from "../types/survey.ts";
|
||||
import {AgreementQuestion, Question, QuestionPair, QuestionType, Survey} from "../types/survey.ts";
|
||||
import {Link, useParams} from "react-router-dom";
|
||||
import React from "react";
|
||||
import React, { useState } from "react";
|
||||
import {useData, useDataPage} from "../API/common.ts";
|
||||
import {LoadingData} from "../components/LoadingData.tsx";
|
||||
|
||||
@@ -36,18 +36,74 @@ function SurveyQuestions({survey}: { survey: Survey | null | undefined }) {
|
||||
|
||||
const _survey = survey as Survey;
|
||||
|
||||
const questionsPairs = useDataPage("surveys", "question-pairs", {survey:_survey.id});
|
||||
const questionsAgreement = useDataPage("surveys", "question-pairs", {survey:_survey.id});
|
||||
const [questions, setQuestions] = useState<Question[]|null>(null);
|
||||
|
||||
//const questions =
|
||||
const questionsPairs = useDataPage<QuestionPair>("surveys", "question-pairs", {survey:_survey.id});
|
||||
const questionsAgreement = useDataPage<AgreementQuestion>("surveys", "agreement-questions", {survey:_survey.id});
|
||||
|
||||
if (questions === null && questionsPairs.items !== null && questionsAgreement.items !== null){
|
||||
|
||||
function setQuestionType(question: Question, questionType: QuestionType) {
|
||||
question.questionType = questionType;
|
||||
return question;
|
||||
}
|
||||
|
||||
var _questions = [...questionsPairs.items.map(q=>setQuestionType(q, QuestionType.QuestionPair)), ...questionsAgreement.items.map(q=>setQuestionType(q, QuestionType.AgreementQuestion))];
|
||||
_questions.sort(()=>Math.random() - .5);
|
||||
console.log(questionsPairs.items.map(q=>setQuestionType(q, QuestionType.QuestionPair)));
|
||||
|
||||
setQuestions(_questions);
|
||||
}
|
||||
|
||||
//console.log(questions);
|
||||
|
||||
|
||||
return (
|
||||
<>
|
||||
<LoadingList data={questions} listElement={(question=>(
|
||||
<QuestionBlock key={(question as Question).questionType+"#"+question.id} question={question as Question}/>
|
||||
|
||||
))}/>
|
||||
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
function QuestionBlock({question}:{question: Question}) {
|
||||
|
||||
switch (question.questionType) {
|
||||
case QuestionType.AgreementQuestion:
|
||||
const qa = question as AgreementQuestion;
|
||||
return (
|
||||
<div className={"question agreement"}>
|
||||
(Вы согласны с утверждением?)
|
||||
{qa.question}
|
||||
<button>
|
||||
Согласен
|
||||
</button>
|
||||
<button>
|
||||
Несогласен
|
||||
</button>
|
||||
</div>
|
||||
);
|
||||
|
||||
case QuestionType.QuestionPair:
|
||||
|
||||
const qp = question as QuestionPair;
|
||||
return (
|
||||
<div className={"question pair"}>
|
||||
(Выберите подходящий ответ)
|
||||
{qp.statements.map(s=>(<button>{s.text}</button>))}
|
||||
|
||||
</div>
|
||||
);
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -11,6 +11,24 @@ interface Statement extends UniqueItem{
|
||||
score_variable: number;
|
||||
}
|
||||
|
||||
export interface QuestionPair extends UniqueItem{
|
||||
|
||||
export enum QuestionType{
|
||||
QuestionPair,
|
||||
AgreementQuestion
|
||||
}
|
||||
|
||||
export interface Question extends UniqueItem{
|
||||
questionType: QuestionType,
|
||||
answer?: number;
|
||||
}
|
||||
|
||||
|
||||
export interface QuestionPair extends Question{
|
||||
statements: Statement[]
|
||||
}
|
||||
|
||||
|
||||
|
||||
export interface AgreementQuestion extends Question{
|
||||
question: string;
|
||||
score_variable: number;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user