diff --git a/site/src/quiz/features/Quiz.tsx b/site/src/quiz/features/Quiz.tsx index 4c322b9..549d068 100644 --- a/site/src/quiz/features/Quiz.tsx +++ b/site/src/quiz/features/Quiz.tsx @@ -10,25 +10,26 @@ import { mixUp, startTesting, stopTesting } from './quizSlice'; function QuizStats() { - const checkTask = (index: number): string => { - useSelector((state: RootState) => state.lists.lists[index]); + const correctCount = (index: number):number => { + let quiz = useSelector((state: RootState) => state.quiz); let state = store.getState(); - if (state.lists.correctAnswers.length <= index) { - return ""; + if (state.quiz.correctAnswers.length <= index) { + return 0; } - let correctCounter = state.lists.lists[index].reduce((prev, answ, i) => prev + Number(state.lists.correctAnswers[index][i] === answ), 0) + return quiz.userAnswers[index].reduce((prev, answ, i) => prev + Number(quiz.correctAnswers[index][i] === answ), 0); + } - if (correctCounter == state.lists.lists[index].length) { + const quizPartText = (counter:number, len:number):string=>{ + if (counter == len) { return "все ответы верные" } - return `верно ${correctCounter}/${state.lists.lists[index].length}` - + return `верно ${counter}/${len}` } return (

Результаты теста

- Задание 1: {checkTask(0)} - Задание 2: {checkTask(1)} + {/* Задание 1: {checkTask(0)} */} + {/* Задание 2: {checkTask(1)} */}
) } @@ -42,6 +43,7 @@ function Quiz() { dispatch(mixUp()); dispatch(startTesting()); } + const checkQuiz = () => { setDisplayingResults(true); dispatch(stopTesting()); @@ -55,7 +57,7 @@ function Quiz() { {index + 1}. {item.title} - + {[,<>S,<>c][(["M","S","C"].indexOf(item.type))]} ))} diff --git a/site/src/quiz/features/SortableList.tsx b/site/src/quiz/features/SortableList.tsx index 300d822..f697aac 100644 --- a/site/src/quiz/features/SortableList.tsx +++ b/site/src/quiz/features/SortableList.tsx @@ -14,8 +14,8 @@ interface ComponentProps { function SortableList({ index}: ComponentProps) { const dispatch = useDispatch(); - const arr = useSelector((state: RootState) => state.lists.lists[index]) - const isDisabled = useSelector((state: RootState) => state.lists.isTestingDone) + const arr = useSelector((state: RootState) => state.quiz.userAnswers[index]) + const isDisabled = useSelector((state: RootState) => state.quiz.isTestingDone) const draggedItems = arr || []; const handleDragEnd = (event: any) => { @@ -30,11 +30,11 @@ function SortableList({ index}: ComponentProps) { return ( - String(x))} strategy={verticalListSortingStrategy}> {draggedItems.map((item) => ( - + ))} diff --git a/site/src/quiz/features/quizSlice.tsx b/site/src/quiz/features/quizSlice.tsx index dccdbb5..fef31a3 100644 --- a/site/src/quiz/features/quizSlice.tsx +++ b/site/src/quiz/features/quizSlice.tsx @@ -1,7 +1,7 @@ import { createSlice } from '@reduxjs/toolkit'; -import type {PayloadAction} from '@reduxjs/toolkit'; +import type { PayloadAction } from '@reduxjs/toolkit'; -function shuffle(array:Array):Array { +function shuffle(array: Array): Array { let currentIndex = array.length; // While there remain elements to shuffle... @@ -19,55 +19,60 @@ function shuffle(array:Array):Array { } interface QuizState { - userAnswers: string[][]; // хранит перемещаемые элементы каждого списка ответов - correctAnswers:string[][] |boolean[][];// ответы для вопрсов, в случае с matching просто правильная последоавтельность, для sorting аналогично, для choosе последоватеьность boolean - isTestingDone:boolean// запрет на взаимодействие с квизом после окончания тестирования, чтобю юзер не наглел + userAnswers: (string | boolean)[][]; // хранит перемещаемые элементы каждого списка ответов + correctAnswers: (string | boolean)[][];// ответы для вопрсов, в случае с matching просто правильная последоавтельность, для sorting аналогично, для choosе последоватеьность boolean + quizTypes: Array<"M" | "S" | "C">; + isTestingDone: boolean// запрет на взаимодействие с квизом после окончания тестирования, чтобю юзер не наглел } const initialState: QuizState = { - userAnswers: [], - correctAnswers:[], - isTestingDone:false + userAnswers: [], + correctAnswers: [], + quizTypes: [], + isTestingDone: false, }; const listsSlice = createSlice({ name: 'lists', initialState, reducers: { - addList: (state, action: PayloadAction<{index: number; items: string[]}>)=>{ - const { index, items } = action.payload; + addList: (state, action: PayloadAction<{ index: number; items: string[]; answers: (string|boolean)[]; quizType : "S" | "M" | "C"}>) => { + const { index, items,answers,quizType} = action.payload; state.userAnswers.splice(index, 1, items); // с нулём создаётся по 2 экземпляра, видно в отладке - state.correctAnswers.splice(index, 1, items); - + state.quizTypes.splice(index, 1, quizType); // + state.correctAnswers.splice(index, 1, answers); + }, - setDraggedItems: (state, action: PayloadAction<{ index: number; items: string[] }>) => { - const { index, items } = action.payload; - if (index >= 0 && index < state.userAnswers.length) { - state.userAnswers[index] = items; // обновляем конкретный список - } + setDraggedItems: (state, action: PayloadAction<{ index: number; items: (string|boolean)[] }>) => { + const { index, items } = action.payload; + if (index >= 0 && index < state.userAnswers.length) { + state.userAnswers[index] = items; // обновляем конкретный список + } }, - setCheckedItems: (state, action: PayloadAction<{ index: number; items: string[] }>) => { - const { index, items } = action.payload; - if (index >= 0 && index < state.userAnswers.length) { - state.userAnswers[index] = items; // обновляем конкретный список - } + setCheckedItems: (state, action: PayloadAction<{ index: number; items: (string|boolean)[] }>) => { + const { index, items } = action.payload; + if (index >= 0 && index < state.userAnswers.length) { + state.userAnswers[index] = items; // обновляем конкретный список + } }, mixUp: (state) => { - state.userAnswers=state.userAnswers.map((list)=> - { - return shuffle(list); - }) + state.userAnswers = state.userAnswers.map((list) => { + if(typeof(list[0])==="boolean"){ + return list.map(()=>false); + } + return shuffle(list); + }) }, - stopTesting:(state)=>{ - state.isTestingDone=true; + stopTesting: (state) => { + state.isTestingDone = true; }, - startTesting:(state)=>{ - state.isTestingDone=false; + startTesting: (state) => { + state.isTestingDone = false; } }, }); // Экспортируем действия и редьюсер -export const { addList, setDraggedItems,mixUp,startTesting,stopTesting } = listsSlice.actions; -export type {QuizState} +export const { addList, setDraggedItems, mixUp, startTesting, stopTesting } = listsSlice.actions; +export type { QuizState } export default listsSlice.reducer; \ No newline at end of file diff --git a/site/src/quiz/quizData.tsx b/site/src/quiz/quizData.tsx index 24d1db3..07adc88 100644 --- a/site/src/quiz/quizData.tsx +++ b/site/src/quiz/quizData.tsx @@ -63,7 +63,7 @@ export const quiz: tQuizzes = [ } , { - "id": 2, + "id": 3, "type": "C", "title": "Вопрос 3 Выбирай!", "tasks": [