added all components

This commit is contained in:
=
2026-04-24 17:03:42 +10:00
parent 1335275ed7
commit 4e2f4eb525
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) { function Matching({ tasks, index }: ComponentProps) {
const dispatch = useDispatch(); const dispatch = useDispatch();
const answers: string[] = tasks.map((item) => String(item.answer));
// Добавляем список ответов очередного задания в хранилище // Добавляем список ответов очередного задания в хранилище
useEffect(() => { useEffect(() => {
dispatch(addList({ index, items: answers })); dispatch(addList({ index, items: answers, answers:answers, quizType: "M" }));
}, []); }, []);
useEffect(() => { useEffect(() => {
@@ -22,7 +22,7 @@ function Matching({tasks,index}: ComponentProps) {
}, []); }, []);
const answers: string[] = tasks.map((item) => String(item.answer));
return ( return (
<Grid container spacing={2}> <Grid container spacing={2}>
<Grid size={6}> <Grid size={6}>

View File

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

View File

@@ -4,8 +4,7 @@ import { useDispatch, useSelector } from 'react-redux';
import { setDraggedItems } from './quizSlice'; import { setDraggedItems } from './quizSlice';
import type { RootState } from '../../store'; import type { RootState } from '../../store';
import List from '@mui/material/List'; import List from '@mui/material/List';
import { SortableItem } from '../components/SortableItem' import { SortableItem } from '../components/SortableItem';
interface ComponentProps { interface ComponentProps {
index: number; index: number;
answers: string[]; 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) => { mixUp: (state) => {
state.userAnswers = state.userAnswers.map((list) => { state.userAnswers = state.userAnswers.map((list,index) => {
if(typeof(list[0])==="boolean"){ if(typeof(state.correctAnswers[index][0])==="boolean"){
return list.map(()=>false); return list.map(()=>false);
} }
return shuffle<string|boolean>(list); 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 type { QuizState }
export default listsSlice.reducer; export default listsSlice.reducer;

View File

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