Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| c168c96820 | |||
| b70fa47bbc | |||
| bd35029fc1 | |||
| 92dc5df96b | |||
| 3d34262203 | |||
| 1bc2e883a1 | |||
| 8a8a17f44d | |||
| 8f46470a26 |
Generated
+1258
-52
File diff suppressed because it is too large
Load Diff
+4
-3
@@ -10,10 +10,9 @@
|
|||||||
"preview": "vite preview"
|
"preview": "vite preview"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"immer": "^11.1.8",
|
"info": "^1.0.0",
|
||||||
"react": "^19.1.0",
|
"react": "^19.1.0",
|
||||||
"react-dom": "^19.1.0",
|
"react-dom": "^19.1.0"
|
||||||
"zustand": "^5.0.14"
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@eslint/js": "^9.25.0",
|
"@eslint/js": "^9.25.0",
|
||||||
@@ -24,6 +23,8 @@
|
|||||||
"eslint-plugin-react-hooks": "^5.2.0",
|
"eslint-plugin-react-hooks": "^5.2.0",
|
||||||
"eslint-plugin-react-refresh": "^0.4.19",
|
"eslint-plugin-react-refresh": "^0.4.19",
|
||||||
"globals": "^16.0.0",
|
"globals": "^16.0.0",
|
||||||
|
"sass": "^1.99.0",
|
||||||
|
"sass-embedded": "^1.99.0",
|
||||||
"vite": "^6.3.5"
|
"vite": "^6.3.5"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+22
-3
@@ -1,10 +1,29 @@
|
|||||||
import Quiz from './components/Quiz'
|
import styles from './styles/App.module.scss'
|
||||||
|
import React, { useState, useCallback } from 'react'
|
||||||
|
|
||||||
|
function CounterButton({label, onClick}) {
|
||||||
|
return (
|
||||||
|
<button onClick={onClick} className={styles.counter_button}>{label}</button>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
function CounterDisplay({value}) {
|
||||||
|
return (<div className={styles.counter_display}>
|
||||||
|
Значение счетчика: <b>{value}</b>
|
||||||
|
</div>)
|
||||||
|
}
|
||||||
|
|
||||||
function App() {
|
function App() {
|
||||||
|
const [counter,setCounter] = useState(0);
|
||||||
|
|
||||||
|
const increment = () => setCounter(prev => prev + 1);
|
||||||
|
const decrement = () => setCounter(prev => prev - 1);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<h1>Практика по созданию списка задач</h1>
|
<h2>Практика по созданию счетчика с колбэками</h2>
|
||||||
<Quiz />
|
<CounterButton label="Увеличить" onClick={increment} />
|
||||||
|
<CounterButton label="уменьшить" onClick={decrement} />
|
||||||
|
<CounterDisplay value={counter} />
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,31 +0,0 @@
|
|||||||
import { useState } from 'react'
|
|
||||||
|
|
||||||
const Question = ({question, onSubmit}) => {
|
|
||||||
const [selectedOption,setSelectedOption] = useState('')
|
|
||||||
const handleSubmit = () => {
|
|
||||||
console.log(selectedOption);
|
|
||||||
if (selectedOption) onSubmit(selectedOption);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div>
|
|
||||||
<h2>Вопрос {question.id}: {question.text}</h2>
|
|
||||||
<div>
|
|
||||||
{question.options.map((option, index)=>(
|
|
||||||
<label key={index}>
|
|
||||||
<input
|
|
||||||
type="radio"
|
|
||||||
name={`question-${question.id}`}
|
|
||||||
value={option}
|
|
||||||
checked={selectedOption === option}
|
|
||||||
onChange={() => setSelectedOption(option)} />
|
|
||||||
{option}
|
|
||||||
</label>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
<button onClick={handleSubmit} >Следующий вопрос</button>
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
export default Question
|
|
||||||
@@ -1,35 +0,0 @@
|
|||||||
import useQuizStore from './store/useQuizStore'
|
|
||||||
import Question from './Question'
|
|
||||||
import Result from './Result'
|
|
||||||
|
|
||||||
const Quiz = () => {
|
|
||||||
const {
|
|
||||||
questions,
|
|
||||||
currentQuestion,
|
|
||||||
userAswers,
|
|
||||||
isFinished,
|
|
||||||
submitAnswer,
|
|
||||||
goToNextQuestion,
|
|
||||||
restartQuiz,
|
|
||||||
} = useQuizStore();
|
|
||||||
|
|
||||||
const handleAnswerSubmit = (anwser) => {
|
|
||||||
console.log('Yes')
|
|
||||||
submitAnswer(answer)
|
|
||||||
if (currentQuestion < questions.length - 1 ) {
|
|
||||||
goToNextQuestion()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(isFinished) {
|
|
||||||
return (<Result />)
|
|
||||||
}
|
|
||||||
return (
|
|
||||||
<div className="quiz">
|
|
||||||
<Question
|
|
||||||
question={questions[currentQuestion]}
|
|
||||||
onSubmit={handleAnswerSubmit} />
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
export default Quiz
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
const Result = ({questions, userAswers, onRestart}) => {
|
|
||||||
return (
|
|
||||||
<div>
|
|
||||||
<h2>Результат</h2>
|
|
||||||
<button onClick={onRestart}>Начать заново</button>
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
export default Result
|
|
||||||
@@ -1,36 +0,0 @@
|
|||||||
import { create } from 'zustand'
|
|
||||||
|
|
||||||
const useQuizStore = create(set => ({
|
|
||||||
questions: [
|
|
||||||
{
|
|
||||||
id:1,
|
|
||||||
text: 'Сколько будет 2+2?',
|
|
||||||
options: ['3','4','2'],
|
|
||||||
correctAnswer: '4',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id:2,
|
|
||||||
text: 'Столица России?',
|
|
||||||
options: ['Москва','Париж','Лондон'],
|
|
||||||
correctAnswer: 'Москва',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
currentQuestion: 0,
|
|
||||||
userAnswer:[],
|
|
||||||
isFinished: false,
|
|
||||||
goToNextQuestion: () => set(state => ({
|
|
||||||
currentQuestion: state.currentQuestion + 1,
|
|
||||||
})),
|
|
||||||
submitAnswer: answer => set(state => {
|
|
||||||
const updatedAnswer = [...state.userAnswer, answer];
|
|
||||||
const isFinished = (state.currentQuestion >= state.questions.length - 1);
|
|
||||||
return {userAnswer: updatedAnswer, isFinished};
|
|
||||||
}),/*
|
|
||||||
restartQuiz: () => set({
|
|
||||||
currentQuestion: 0,
|
|
||||||
userAnswer: [],
|
|
||||||
isFinished: false
|
|
||||||
}), */
|
|
||||||
}))
|
|
||||||
|
|
||||||
export default useQuizStore
|
|
||||||
+3
-1
@@ -1,8 +1,10 @@
|
|||||||
import { StrictMode } from 'react'
|
import { StrictMode } from 'react'
|
||||||
import { createRoot } from 'react-dom/client'
|
import { createRoot } from 'react-dom/client'
|
||||||
// удаляем import './index.css'
|
|
||||||
import App from './App.jsx'
|
import App from './App.jsx'
|
||||||
|
|
||||||
createRoot(document.getElementById('root')).render(
|
createRoot(document.getElementById('root')).render(
|
||||||
|
<StrictMode>
|
||||||
<App />
|
<App />
|
||||||
|
</StrictMode>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
.container {
|
||||||
|
display:flex;
|
||||||
|
flex-direction: row;
|
||||||
|
border: 1px solid black;
|
||||||
|
border-radius: 5px;
|
||||||
|
margin-bottom: 10px;
|
||||||
|
p {
|
||||||
|
padding: 5px 10px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.counter {
|
||||||
|
&_display{
|
||||||
|
border: 1px solid black;
|
||||||
|
border-width: 3px;
|
||||||
|
border-radius: 10px;
|
||||||
|
padding: 10px;
|
||||||
|
width: 300px;
|
||||||
|
}
|
||||||
|
&_button{
|
||||||
|
padding: 10px;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user