added all components

This commit is contained in:
=
2026-04-24 17:03:42 +10:00
committed by OkunElya
parent 90441c904e
commit 0671dcaa83
7 changed files with 161 additions and 46 deletions

View File

@@ -0,0 +1,70 @@
import { Grid, List, ListItem, ListItemButton, ListItemText } from '@mui/material';
import { useDispatch, useSelector } from 'react-redux';
import type { tTasks } from "../quizData"
import { useEffect } from 'react';
import { addList, mixUp } from './quizSlice';
import Checkbox from '@mui/material/Checkbox';
import type { RootState } from '../../store';
import type { ChangeEvent } from 'react';
import { setCheckedItems } from './quizSlice';
interface ComponentProps {
tasks: tTasks;
index: number;
}
function Matching({ tasks, index }: ComponentProps) {
const dispatch = useDispatch();
const answers: boolean[] = tasks.map((item) => Boolean(item.answer));
const items: string[] = tasks.map((item) => String(item.answer));
const arr = useSelector((state: RootState) => state.quiz.userAnswers[index]);
const isDisabled = useSelector((state: RootState) => state.quiz.isTestingDone);
useEffect(() => {
dispatch(addList({ index, items: items, answers: answers, quizType: "M" }));
}, []);
useEffect(() => {
dispatch(mixUp());
}, []);
const handleCheckboxAction = (checkboxIndex: number) => (event: ChangeEvent<HTMLInputElement, Element>, checked: boolean) => {
let answersCopy = [ ...arr ];
answersCopy[checkboxIndex] = checked;
dispatch(setCheckedItems({ index, items: answersCopy }));
};
console.log(arr);
return (
<Grid container spacing={2}>
<Grid size={12}>
<List>
{tasks.map((item, itemIndex) => (
<ListItem key={itemIndex}>
<ListItemButton
sx={{
border: '1px solid gray',
borderRadius: '5px',
textAlign: 'right',
}}>
<ListItemText primary={item.question} />
<Checkbox
onChange={isDisabled ? (..._) => { _ } : handleCheckboxAction(itemIndex)}
checked={Boolean(arr == undefined ? false : arr[itemIndex])}
sx={{ '& .MuiSvgIcon-root': { fontSize: 28 } }}
/>
</ListItemButton>
</ListItem>
))}
</List>
</Grid>
<Grid size={12}>
</Grid>
</Grid>
);
}
export default Matching

View File

@@ -11,10 +11,10 @@ interface ComponentProps {
function Matching({ tasks, index }: ComponentProps) {
const dispatch = useDispatch();
const answers: string[] = tasks.map((item) => String(item.answer));
// Добавляем список ответов очередного задания в хранилище
useEffect(() => {
dispatch(addList({ index, items: answers }));
dispatch(addList({ index, items: answers, answers:answers, quizType: "M" }));
}, []);
useEffect(() => {
@@ -22,7 +22,7 @@ function Matching({tasks,index}: ComponentProps) {
}, []);
const answers: string[] = tasks.map((item) => String(item.answer));
return (
<Grid container spacing={2}>
<Grid size={6}>

View File

@@ -3,6 +3,8 @@ import { quiz } from "../quizData";
import { useSelector } from 'react-redux';
import { useState } from 'react';
import Matching from './Matching';
import Sorting from './Sorting';
import Choosing from './Choosing';
import type { RootState } from '../../store';
import store from '../../store';
import { useDispatch } from 'react-redux';
@@ -57,14 +59,23 @@ function Quiz() {
<Typography variant="h5" gutterBottom>
{index + 1}. {item.title}
</Typography>
{[<Matching index={index} tasks={item.tasks} />,<>S</>,<>c</>][(["M","S","C"].indexOf(item.type))]}
</Box>
))}
{[
<Matching index={index} tasks={item.tasks} />,
<Sorting index={index} tasks={item.tasks} />,
<Choosing index={index} tasks={item.tasks} />
][(["M", "S", "C"].indexOf(item.type))]}
</Box>
))}
<Box sx={{ display: 'flex', justifyContent: 'space-around' }}>
<Button onClick={checkQuiz} variant="contained">Проверить</Button>
<Button onClick={resetQuiz} variant="contained">Начать снова</Button>
</Box>
{displayingResults && <QuizStats />}
</Container>

View File

@@ -4,8 +4,7 @@ import { useDispatch, useSelector } from 'react-redux';
import { setDraggedItems } from './quizSlice';
import type { RootState } from '../../store';
import List from '@mui/material/List';
import { SortableItem } from '../components/SortableItem'
import { SortableItem } from '../components/SortableItem';
interface ComponentProps {
index: number;
answers: string[];

View File

@@ -0,0 +1,35 @@
import { Grid} from '@mui/material';
import type { tTasks } from "../quizData"
import SortableList from '../features/SortableList';
import { useEffect } from 'react';
import { useDispatch } from 'react-redux';
import { addList, mixUp } from './quizSlice';
interface ComponentProps {
tasks: tTasks;
index: number;
}
function Matching({ tasks, index }: ComponentProps) {
const dispatch = useDispatch();
const answers: string[] = tasks.map((item) => String(item.answer));
// Добавляем список ответов очередного задания в хранилище
useEffect(() => {
dispatch(addList({ index, items: answers, answers:answers, quizType: "M" }));
}, []);
useEffect(() => {
dispatch(mixUp());
}, []);
return (
<Grid container spacing={2}>
<Grid size={12}>
<SortableList index={index} answers={answers} />
</Grid>
</Grid>
);
}
export default Matching

View File

@@ -56,8 +56,8 @@ const listsSlice = createSlice({
}
},
mixUp: (state) => {
state.userAnswers = state.userAnswers.map((list) => {
if(typeof(list[0])==="boolean"){
state.userAnswers = state.userAnswers.map((list,index) => {
if(typeof(state.correctAnswers[index][0])==="boolean"){
return list.map(()=>false);
}
return shuffle<string|boolean>(list);
@@ -73,6 +73,6 @@ const listsSlice = createSlice({
});
// Экспортируем действия и редьюсер
export const { addList, setDraggedItems, mixUp, startTesting, stopTesting } = listsSlice.actions;
export const { addList, setDraggedItems,setCheckedItems, mixUp, startTesting, stopTesting } = listsSlice.actions;
export type { QuizState }
export default listsSlice.reducer;

View File

@@ -65,26 +65,26 @@ export const quiz: tQuizzes = [
{
"id": 3,
"type": "C",
"title": "Вопрос 3 Выбирай!",
"title": "Вопрос 3 Выбирай",
"tasks": [
{
"question": "да",
"question": "123",
"answer": true
},
{
"question": "нет",
"question": "456",
"answer": false
},
{
"question": "и снова да",
"question": "789",
"answer": true
},
{
"question": "нет",
"question": "101112",
"answer": false
},
{
"question": "дааа",
"question": "131415",
"answer": true
},
]