logic done

This commit is contained in:
=
2026-04-24 17:44:39 +10:00
parent 4e2f4eb525
commit 4532122dee
6 changed files with 53 additions and 31 deletions

View File

@@ -20,6 +20,7 @@ function shuffle<T>(array: Array<T>): Array<T> {
interface QuizState {
userAnswers: (string | boolean)[][]; // хранит перемещаемые элементы каждого списка ответов
questions: string[][];
correctAnswers: (string | boolean)[][];// ответы для вопрсов, в случае с matching просто правильная последоавтельность, для sorting аналогично, для choosе последоватеьность boolean
quizTypes: Array<"M" | "S" | "C">;
isTestingDone: boolean// запрет на взаимодействие с квизом после окончания тестирования, чтобю юзер не наглел
@@ -29,6 +30,7 @@ const initialState: QuizState = {
userAnswers: [],
correctAnswers: [],
quizTypes: [],
questions:[],
isTestingDone: false,
};
@@ -36,8 +38,9 @@ const listsSlice = createSlice({
name: 'lists',
initialState,
reducers: {
addList: (state, action: PayloadAction<{ index: number; items: string[]; answers: (string|boolean)[]; quizType : "S" | "M" | "C"}>) => {
const { index, items,answers,quizType} = action.payload;
addList: (state, action: PayloadAction<{ index: number; items: string[]; questions: string[]; answers: (string|boolean)[]; quizType : "S" | "M" | "C"}>) => {
const { index, items,questions,answers,quizType} = action.payload;
state.questions.splice(index, 1, questions);
state.userAnswers.splice(index, 1, items); // с нулём создаётся по 2 экземпляра, видно в отладке
state.quizTypes.splice(index, 1, quizType); //
state.correctAnswers.splice(index, 1, answers);
@@ -49,7 +52,7 @@ const listsSlice = createSlice({
state.userAnswers[index] = items; // обновляем конкретный список
}
},
setCheckedItems: (state, action: PayloadAction<{ index: number; items: (string|boolean)[] }>) => {
setCheckedItems: (state, action: PayloadAction<{ index: number; items: boolean[] }>) => {
const { index, items } = action.payload;
if (index >= 0 && index < state.userAnswers.length) {
state.userAnswers[index] = items; // обновляем конкретный список
@@ -58,7 +61,11 @@ const listsSlice = createSlice({
mixUp: (state) => {
state.userAnswers = state.userAnswers.map((list,index) => {
if(typeof(state.correctAnswers[index][0])==="boolean"){
return list.map(()=>false);
list.map(()=>false);
let indexes = shuffle( list.map((_,idx)=>idx));
state.correctAnswers[index]=state.correctAnswers[index].map((_,i,arr)=>arr[indexes[i]])
state.questions[index]=state.questions[index].map((_,i,arr)=>arr[indexes[i]])
return list.map(()=>false)
}
return shuffle<string|boolean>(list);
})