laba5
BIN
laba5/Color Hunt Palette 252b484450695b9a8bf7e987.png
Normal file
After Width: | Height: | Size: 479 B |
BIN
laba5/Color Hunt Palette 57375dff3fa4ff9b82ffc8c8.png
Normal file
After Width: | Height: | Size: 479 B |
BIN
laba5/Icon.png
Normal file
After Width: | Height: | Size: 5.1 KiB |
BIN
laba5/checkBox.png
Normal file
After Width: | Height: | Size: 184 B |
BIN
laba5/createtest.jpg
Normal file
After Width: | Height: | Size: 113 KiB |
BIN
laba5/createtest.psd
Normal file
BIN
laba5/icon.psd
Normal file
BIN
laba5/logIn.jpg
Normal file
After Width: | Height: | Size: 108 KiB |
BIN
laba5/logIn.psd
Normal file
BIN
laba5/mainPage.jpg
Normal file
After Width: | Height: | Size: 500 KiB |
BIN
laba5/mainPage.psd
Normal file
BIN
laba5/profile.jpg
Normal file
After Width: | Height: | Size: 75 KiB |
BIN
laba5/profile.psd
Normal file
BIN
laba5/signIn.jpg
Normal file
After Width: | Height: | Size: 144 KiB |
BIN
laba5/signIn.psd
Normal file
2
laba5/site/.editorconfig
Normal file
@ -0,0 +1,2 @@
|
||||
[*]
|
||||
end_of_line = lf
|
26
laba5/site/.eslintrc.cjs
Normal file
@ -0,0 +1,26 @@
|
||||
module.exports = {
|
||||
root: true,
|
||||
env: { browser: true, es2020: true },
|
||||
extends: [
|
||||
'airbnb-base',
|
||||
'plugin:react/recommended',
|
||||
'plugin:react/jsx-runtime',
|
||||
'plugin:react-hooks/recommended',
|
||||
],
|
||||
ignorePatterns: ['dist', '.eslintrc.cjs'],
|
||||
parserOptions: { ecmaVersion: 12, sourceType: 'module' },
|
||||
settings: { react: { version: '18.2' } },
|
||||
plugins: ['react-refresh'],
|
||||
rules: {
|
||||
'react-refresh/only-export-components': [
|
||||
'warn',
|
||||
{ allowConstantExport: true },
|
||||
],
|
||||
'indent': 'off',
|
||||
'no-console': 'off',
|
||||
'arrow-body-style': 'off',
|
||||
'implicit-arrow-linebreak': 'off',
|
||||
'linebreak-style': 'off',
|
||||
'object-curly-newline': 'off',
|
||||
},
|
||||
}
|
24
laba5/site/.gitignore
vendored
Normal file
@ -0,0 +1,24 @@
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
pnpm-debug.log*
|
||||
lerna-debug.log*
|
||||
|
||||
node_modules
|
||||
dist
|
||||
dist-ssr
|
||||
*.local
|
||||
|
||||
# Editor directories and files
|
||||
.vscode/*
|
||||
!.vscode/extensions.json
|
||||
.idea
|
||||
.DS_Store
|
||||
*.suo
|
||||
*.ntvs*
|
||||
*.njsproj
|
||||
*.sln
|
||||
*.sw?
|
29
laba5/site/README.md
Normal file
@ -0,0 +1,29 @@
|
||||
#### Окружение:
|
||||
- nodejs 18;
|
||||
- VSCode;
|
||||
- ESLint плагин для VSCode;
|
||||
- для отладки необходимы бразузеры Chrome или Edge.
|
||||
|
||||
#### Создание пустого проекта:
|
||||
|
||||
```commandline
|
||||
npm create vite@latest ./ -- --template react
|
||||
```
|
||||
|
||||
#### Установка зависимостей:
|
||||
|
||||
```commandline
|
||||
npm install
|
||||
```
|
||||
|
||||
#### Запуск проекта:
|
||||
|
||||
```commandline
|
||||
npm run dev
|
||||
```
|
||||
|
||||
#### Сборка проекта:
|
||||
|
||||
```commandline
|
||||
npm run build
|
||||
```
|
88
laba5/site/data.json
Normal file
BIN
laba5/site/image.jpg
Normal file
After Width: | Height: | Size: 115 KiB |
17
laba5/site/index.html
Normal file
@ -0,0 +1,17 @@
|
||||
<html lang="ru">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>unreal tests</title>
|
||||
</head>
|
||||
|
||||
<body class="d-flex flex-column" style="height: auto; min-height: 100%">
|
||||
<div id="root" class="d-flex flex-column" style="height: auto; min-height: 100%">
|
||||
|
||||
</div>
|
||||
<script type="module" src="/src/main.jsx"></script>
|
||||
</body>
|
||||
|
||||
</html>
|
14
laba5/site/jsconfig.json
Normal file
@ -0,0 +1,14 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "ESNext",
|
||||
"moduleResolution": "Node",
|
||||
"target": "ES2020",
|
||||
"jsx": "react",
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true
|
||||
},
|
||||
"exclude": [
|
||||
"node_modules",
|
||||
"**/node_modules/*"
|
||||
]
|
||||
}
|
5
laba5/site/json-server.json
Normal file
@ -0,0 +1,5 @@
|
||||
{
|
||||
"static": "./node_modules/json-server/public",
|
||||
"port": 8081,
|
||||
"watch": "true"
|
||||
}
|
5936
laba5/site/package-lock.json
generated
Normal file
39
laba5/site/package.json
Normal file
@ -0,0 +1,39 @@
|
||||
{
|
||||
"name": "site",
|
||||
"private": true,
|
||||
"version": "0.0.0",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"vite": "vite",
|
||||
"serve": "http-server -p 3000 ./dist/",
|
||||
"build": "vite build",
|
||||
"rest": "json-server --watch data.json -p 8081",
|
||||
"dev": "npm-run-all --parallel rest vite",
|
||||
"prod": "npm-run-all build --parallel serve rest"
|
||||
},
|
||||
"dependencies": {
|
||||
"react": "^18.2.0",
|
||||
"react-dom": "^18.2.0",
|
||||
"react-router-dom": "^6.18.0",
|
||||
"react-hot-toast": "^2.4.1",
|
||||
"axios": "^1.6.1",
|
||||
"bootstrap": "^5.3.2",
|
||||
"react-bootstrap": "^2.9.1",
|
||||
"react-bootstrap-icons": "^1.10.3",
|
||||
"prop-types": "^15.8.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/react": "^18.2.15",
|
||||
"@types/react-dom": "^18.2.15",
|
||||
"@vitejs/plugin-react": "^4.0.3",
|
||||
"eslint": "^8.45.0",
|
||||
"eslint-config-airbnb-base": "^15.0.0",
|
||||
"eslint-plugin-import": "^2.29.0",
|
||||
"eslint-plugin-react": "^7.32.2",
|
||||
"eslint-plugin-react-hooks": "^4.6.0",
|
||||
"eslint-plugin-react-refresh": "^0.4.3",
|
||||
"json-server": "^0.17.4",
|
||||
"npm-run-all": "^4.1.5",
|
||||
"vite": "^4.4.5"
|
||||
}
|
||||
}
|
3
laba5/site/public/favicon.svg
Normal file
@ -0,0 +1,3 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-cart2" viewBox="0 0 16 16">
|
||||
<path d="M0 2.5A.5.5 0 0 1 .5 2H2a.5.5 0 0 1 .485.379L2.89 4H14.5a.5.5 0 0 1 .485.621l-1.5 6A.5.5 0 0 1 13 11H4a.5.5 0 0 1-.485-.379L1.61 3H.5a.5.5 0 0 1-.5-.5zM3.14 5l1.25 5h8.22l1.25-5H3.14zM5 13a1 1 0 1 0 0 2 1 1 0 0 0 0-2zm-2 1a2 2 0 1 1 4 0 2 2 0 0 1-4 0zm9-1a1 1 0 1 0 0 2 1 1 0 0 0 0-2zm-2 1a2 2 0 1 1 4 0 2 2 0 0 1-4 0z"/>
|
||||
</svg>
|
After Width: | Height: | Size: 463 B |
22
laba5/site/src/App.jsx
Normal file
@ -0,0 +1,22 @@
|
||||
import PropTypes from 'prop-types';
|
||||
import { Outlet } from 'react-router-dom';
|
||||
import Footer from './components/footer/Footer.jsx';
|
||||
import Header from './components/navigation/Header.jsx';
|
||||
|
||||
const App = ({ routes }) => {
|
||||
return (
|
||||
<>
|
||||
<Header routes={routes}></Header>
|
||||
<main>
|
||||
<Outlet />
|
||||
</main>
|
||||
<Footer />
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
App.propTypes = {
|
||||
routes: PropTypes.array,
|
||||
};
|
||||
|
||||
export default App;
|
BIN
laba5/site/src/assets/200.png
Normal file
After Width: | Height: | Size: 1.5 KiB |
BIN
laba5/site/src/assets/icon-994c7fa6.png
Normal file
After Width: | Height: | Size: 5.1 KiB |
BIN
laba5/site/src/assets/image-cd5bd8e6.jpg
Normal file
After Width: | Height: | Size: 115 KiB |
40
laba5/site/src/components/api/ApiClient.js
Normal file
@ -0,0 +1,40 @@
|
||||
import axios from 'axios';
|
||||
import { Toast } from 'react-bootstrap';
|
||||
|
||||
export class HttpError extends Error {
|
||||
constructor(message = '') {
|
||||
super(message);
|
||||
this.name = 'HttpError';
|
||||
Object.setPrototypeOf(this, new.target.prototype);
|
||||
Toast.error(message, { id: 'HttpError' });
|
||||
}
|
||||
}
|
||||
|
||||
function responseHandler(response) {
|
||||
if (response.status === 200 || response.status === 201) {
|
||||
const data = response?.data;
|
||||
if (!data) {
|
||||
throw new HttpError('API Error. No data!');
|
||||
}
|
||||
return data;
|
||||
}
|
||||
throw new HttpError(`API Error! Invalid status code ${response.status}!`);
|
||||
}
|
||||
|
||||
function responseErrorHandler(error) {
|
||||
if (error === null) {
|
||||
throw new Error('Unrecoverable error!! Error is null!');
|
||||
}
|
||||
Toast.error(error.message, { id: 'AxiosError' });
|
||||
return Promise.reject(error.message);
|
||||
}
|
||||
|
||||
export const ApiClient = axios.create({
|
||||
baseURL: 'http://localhost:8081/',
|
||||
timeout: '3000',
|
||||
headers: {
|
||||
Accept: 'application/json',
|
||||
},
|
||||
});
|
||||
|
||||
ApiClient.interceptors.response.use(responseHandler, responseErrorHandler);
|
34
laba5/site/src/components/api/ApiService.js
Normal file
@ -0,0 +1,34 @@
|
||||
import { ApiClient } from './ApiClient';
|
||||
|
||||
class ApiService {
|
||||
constructor(url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
async getAll() {
|
||||
return ApiClient.get(`${this.url}`);
|
||||
}
|
||||
|
||||
// eslint-disable-next-line no-dupe-class-members
|
||||
async getAll(expand) {
|
||||
return ApiClient.get(`${this.url}${expand || ''}`);
|
||||
}
|
||||
|
||||
async get(id, expand) {
|
||||
return ApiClient.get(`${this.url}/${id}${expand || ''}`);
|
||||
}
|
||||
|
||||
async create(body) {
|
||||
return ApiClient.post(this.url, body);
|
||||
}
|
||||
|
||||
async update(id, body) {
|
||||
return ApiClient.put(`${this.url}/${id}`, body);
|
||||
}
|
||||
|
||||
async delete(id) {
|
||||
return ApiClient.delete(`${this.url}/${id}`);
|
||||
}
|
||||
}
|
||||
|
||||
export default ApiService;
|
16
laba5/site/src/components/caroucele/Caroucele.css
Normal file
@ -0,0 +1,16 @@
|
||||
.carousel-item{
|
||||
height: 30rem !important;
|
||||
background-repeat: no-repeat;
|
||||
background-size:cover;
|
||||
background-position: center;
|
||||
}
|
||||
|
||||
.carouselItem1{
|
||||
background-image: url("image.jpg");
|
||||
}
|
||||
.carouselItem2{
|
||||
background-image: url("image.jpg");
|
||||
}
|
||||
.carouselItem3{
|
||||
background-image: url("image.jpg");
|
||||
}
|
32
laba5/site/src/components/caroucele/Caroucele.jsx
Normal file
@ -0,0 +1,32 @@
|
||||
import PropTypes from 'prop-types';
|
||||
import './Caroucele.css';
|
||||
|
||||
const Caroucele = ({ children }) => {
|
||||
return (
|
||||
<>
|
||||
<div style={{ marginTop: '1rem', backgroundColor: '#252b48' }}>
|
||||
<div id="carouselExample" style={{ maxWidth: '30rem' }} className="carousel slide w-50 mx-auto">
|
||||
<div className="carousel-inner">
|
||||
{
|
||||
children
|
||||
}
|
||||
</div>
|
||||
<button className="carousel-control-prev" type="button" data-bs-target="#carouselExample" data-bs-slide="prev">
|
||||
<span className="carousel-control-prev-icon" aria-hidden="true"></span>
|
||||
<span className="visually-hidden">Previous</span>
|
||||
</button>
|
||||
<button className="carousel-control-next" type="button" data-bs-target="#carouselExample" data-bs-slide="next">
|
||||
<span className="carousel-control-next-icon" aria-hidden="true"></span>
|
||||
<span className="visually-hidden">Next</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
Caroucele.propTypes = {
|
||||
children: PropTypes.node,
|
||||
};
|
||||
|
||||
export default Caroucele;
|
26
laba5/site/src/components/caroucele/CarouseleItem.jsx
Normal file
@ -0,0 +1,26 @@
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import PropTypes from 'prop-types';
|
||||
import './Caroucele.css';
|
||||
|
||||
const CarouceleItem = ({ line, className }) => {
|
||||
const navigate = useNavigate();
|
||||
return (
|
||||
<>
|
||||
<div className={`carousel-item ${className || ''}`} style={{ backgroundImage: 'url("image.jpg")' }} >
|
||||
<div style={{ position: 'absolute', top: '50%', transform: 'translateY(-50%)', textAlign: 'center', width: '100%' }}>
|
||||
<h2>{line.description}</h2>
|
||||
</div>
|
||||
<div style={{ position: 'absolute', bottom: '2', transform: 'translateY(-50%)', textAlign: 'center', width: '100%' }}>
|
||||
<a href="#" onClick={ () => { navigate(`/TestPage/${line.id}`); } } className="btn btn-primary startButton" >Начать</a>
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
CarouceleItem.propTypes = {
|
||||
line: PropTypes.object,
|
||||
className: PropTypes.string,
|
||||
};
|
||||
|
||||
export default CarouceleItem;
|
29
laba5/site/src/components/createdTest/CreatedTest.jsx
Normal file
@ -0,0 +1,29 @@
|
||||
import PropTypes from 'prop-types';
|
||||
|
||||
const CreatedTest = ({
|
||||
line, onOpen, onEdit, onDelete,
|
||||
}) => {
|
||||
const handleAnchorClick = (event, action) => {
|
||||
event.preventDefault();
|
||||
action();
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="row justify-content-center align-items-center g-2 mt-1 mb-1">
|
||||
<div className="col-2">{line.name}</div>
|
||||
<div className="col">{line.description}</div>
|
||||
<a href="#" onClick={(event) => handleAnchorClick(event, onOpen)} className="col-2 btn btn-primary startButton">открыть тест</a>
|
||||
<a href="#" onClick={(event) => handleAnchorClick(event, onEdit)} className="col-2 btn btn-secondary startButton">изменить</a>
|
||||
<a href="#" onClick={(event) => handleAnchorClick(event, onDelete)} className="col-2 btn btn-danger startButton">удалить</a>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
CreatedTest.propTypes = {
|
||||
line: PropTypes.object,
|
||||
onOpen: PropTypes.func,
|
||||
onEdit: PropTypes.func,
|
||||
onDelete: PropTypes.func,
|
||||
};
|
||||
|
||||
export default CreatedTest;
|
15
laba5/site/src/components/endOfTest/EndOfTest.jsx
Normal file
@ -0,0 +1,15 @@
|
||||
const EndOfTest = () => {
|
||||
const result = 1;
|
||||
return (
|
||||
<>
|
||||
<div className="row justify-content-center align-items-center g-2 m-3 w-100 h-100">
|
||||
<div className="col justify-content-center align-items-center" style={{ width: 'auto', fontSize: '5em' }}>
|
||||
<h3 className="row justify-content-center">Это конец теста</h3>
|
||||
<h3 className="row justify-content-center">ваш результат: {result}</h3>
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default EndOfTest;
|
5
laba5/site/src/components/footer/Footer.css
Normal file
@ -0,0 +1,5 @@
|
||||
footer {
|
||||
background-color: #f7e987;
|
||||
height: 32px;
|
||||
color: #5b9a8b;
|
||||
}
|
11
laba5/site/src/components/footer/Footer.jsx
Normal file
@ -0,0 +1,11 @@
|
||||
import './Footer.css';
|
||||
|
||||
const Footer = () => {
|
||||
return (
|
||||
<footer className="footer d-flex flex-shrink-0 justify-content-center align-items-center">
|
||||
Timour, 2023
|
||||
</footer>
|
||||
);
|
||||
};
|
||||
|
||||
export default Footer;
|
34
laba5/site/src/components/hooks/LinesDeleteModalHook.js
Normal file
@ -0,0 +1,34 @@
|
||||
import { useState } from 'react';
|
||||
import { Toast } from 'react-bootstrap';
|
||||
import useModal from '../modal/ModalHook';
|
||||
import LinesApiService from '../service/LinesApiService';
|
||||
|
||||
const useLinesDeleteModal = (linesChangeHandle) => {
|
||||
const { isModalShow, showModal, hideModal } = useModal();
|
||||
const [currentId, setCurrentId] = useState(0);
|
||||
|
||||
const showModalDialog = (id) => {
|
||||
showModal();
|
||||
setCurrentId(id);
|
||||
};
|
||||
|
||||
const onClose = () => {
|
||||
hideModal();
|
||||
};
|
||||
|
||||
const onDelete = async () => {
|
||||
await LinesApiService.delete(currentId);
|
||||
linesChangeHandle();
|
||||
Toast.success('Элемент успешно удален', { id: 'LinesTable' });
|
||||
onClose();
|
||||
};
|
||||
|
||||
return {
|
||||
isDeleteModalShow: isModalShow,
|
||||
showDeleteModal: showModalDialog,
|
||||
handleDeleteConfirm: onDelete,
|
||||
handleDeleteCancel: onClose,
|
||||
};
|
||||
};
|
||||
|
||||
export default useLinesDeleteModal;
|
26
laba5/site/src/components/hooks/LinesHook.js
Normal file
@ -0,0 +1,26 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import LinesApiService from '../service/LinesApiService';
|
||||
|
||||
const useLines = () => {
|
||||
const [linesRefresh, setLinesRefresh] = useState(false);
|
||||
const [lines, setLines] = useState([]);
|
||||
const handleLinesChange = () => setLinesRefresh(!linesRefresh);
|
||||
|
||||
const getLines = async () => {
|
||||
const expand = '?_expand=type';
|
||||
const data = await LinesApiService.getAll();
|
||||
setLines(data ?? []);
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
getLines();
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [linesRefresh]);
|
||||
|
||||
return {
|
||||
lines,
|
||||
handleLinesChange,
|
||||
};
|
||||
};
|
||||
|
||||
export default useLines;
|
77
laba5/site/src/components/hooks/LinesItemFormHook.js
Normal file
@ -0,0 +1,77 @@
|
||||
import { useState } from 'react';
|
||||
import toast from 'react-hot-toast';
|
||||
import getBase64FromFile from '../utils/Base64';
|
||||
import LinesApiService from '../service/LinesApiService';
|
||||
import useLinesItem from './LinesItemHook';
|
||||
|
||||
const useLinesItemForm = (id, linesChangeHandle) => {
|
||||
const { item, setItem } = useLinesItem(id);
|
||||
|
||||
const [validated, setValidated] = useState(false);
|
||||
|
||||
const resetValidity = () => {
|
||||
setValidated(false);
|
||||
};
|
||||
|
||||
const getLineObject = (formData) => {
|
||||
const { name } = formData;
|
||||
const { description } = formData;
|
||||
const image = formData.image.startsWith('data:image') ? formData.image : '';
|
||||
return {
|
||||
name,
|
||||
description,
|
||||
image,
|
||||
};
|
||||
};
|
||||
|
||||
const handleImageChange = async (event) => {
|
||||
const { files } = event.target;
|
||||
const file = await getBase64FromFile(files.item(0));
|
||||
setItem({
|
||||
...item,
|
||||
image: file,
|
||||
});
|
||||
};
|
||||
|
||||
const handleChange = (event) => {
|
||||
if (event.target.type === 'file') {
|
||||
handleImageChange(event);
|
||||
return;
|
||||
}
|
||||
const inputName = event.target.name;
|
||||
const inputValue = event.target.type === 'checkbox' ? event.target.checked : event.target.value;
|
||||
setItem({
|
||||
...item,
|
||||
[inputName]: inputValue,
|
||||
});
|
||||
};
|
||||
|
||||
const handleSubmit = async (event) => {
|
||||
const form = event.currentTarget;
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
const body = getLineObject(item);
|
||||
if (form.checkValidity()) {
|
||||
if (id === undefined) {
|
||||
await LinesApiService.create(body);
|
||||
} else {
|
||||
await LinesApiService.update(id, body);
|
||||
}
|
||||
if (linesChangeHandle) linesChangeHandle();
|
||||
toast.success('Элемент успешно сохранен', { id: 'LinesTable' });
|
||||
return true;
|
||||
}
|
||||
setValidated(true);
|
||||
return false;
|
||||
};
|
||||
|
||||
return {
|
||||
item,
|
||||
validated,
|
||||
handleSubmit,
|
||||
handleChange,
|
||||
resetValidity,
|
||||
};
|
||||
};
|
||||
|
||||
export default useLinesItemForm;
|
32
laba5/site/src/components/hooks/LinesItemHook.js
Normal file
@ -0,0 +1,32 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import LinesApiService from '../service/LinesApiService';
|
||||
|
||||
const useLinesItem = (id) => {
|
||||
const emptyItem = {
|
||||
name: '',
|
||||
description: '',
|
||||
image: '',
|
||||
};
|
||||
const [item, setItem] = useState({ ...emptyItem });
|
||||
|
||||
const getItem = async (itemId = undefined) => {
|
||||
if (itemId && itemId > 0) {
|
||||
const data = await LinesApiService.get(itemId);
|
||||
setItem(data);
|
||||
} else {
|
||||
setItem({ ...emptyItem });
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
getItem(id);
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [id]);
|
||||
|
||||
return {
|
||||
item,
|
||||
setItem,
|
||||
};
|
||||
};
|
||||
|
||||
export default useLinesItem;
|
25
laba5/site/src/components/hooks/QuestionsHook.js
Normal file
@ -0,0 +1,25 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import QuestionsApiService from '../service/QuestionsApiService';
|
||||
|
||||
const useQuestions = (idTest) => {
|
||||
const [questionsRefresh, setQuestionsRefresh] = useState(false);
|
||||
const [questions, setQuestions] = useState([]);
|
||||
const handleQuestionsChange = () => setQuestionsRefresh(!questionsRefresh);
|
||||
|
||||
const getQuestions = async () => {
|
||||
const data = await QuestionsApiService.getAll(`?testId=${idTest}`);
|
||||
setQuestions(data ?? []);
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
getQuestions();
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [questionsRefresh]);
|
||||
|
||||
return {
|
||||
questions,
|
||||
handleQuestionsChange,
|
||||
};
|
||||
};
|
||||
|
||||
export default useQuestions;
|
84
laba5/site/src/components/hooks/QuestionsItemFormHook.js
Normal file
@ -0,0 +1,84 @@
|
||||
import { useState } from 'react';
|
||||
import toast from 'react-hot-toast';
|
||||
import getBase64FromFile from '../utils/Base64';
|
||||
import useQuestionsItem from './QuestionsItemHook';
|
||||
import QuestionsApiService from '../service/QuestionsApiService';
|
||||
|
||||
const useQuestionsItemForm = (id, testId, questionsChangeHandle) => {
|
||||
const { item, setItem } = useQuestionsItem(id, testId);
|
||||
|
||||
const [validated, setValidated] = useState(false);
|
||||
|
||||
const resetValidity = () => {
|
||||
setValidated(false);
|
||||
};
|
||||
|
||||
const getQuestionObject = (formData) => {
|
||||
const { text } = formData;
|
||||
const { variant1 } = formData;
|
||||
const { variant2 } = formData;
|
||||
const { variant3 } = formData;
|
||||
const { variant4 } = formData;
|
||||
const image = formData.image.startsWith('data:image') ? formData.image : '';
|
||||
return {
|
||||
testId,
|
||||
text,
|
||||
variant1,
|
||||
variant2,
|
||||
variant3,
|
||||
variant4,
|
||||
image,
|
||||
};
|
||||
};
|
||||
|
||||
const handleImageChange = async (event) => {
|
||||
const { files } = event.target;
|
||||
const file = await getBase64FromFile(files.item(0));
|
||||
setItem({
|
||||
...item,
|
||||
image: file,
|
||||
});
|
||||
};
|
||||
|
||||
const handleChange = (event) => {
|
||||
if (event.target.type === 'file') {
|
||||
handleImageChange(event);
|
||||
return;
|
||||
}
|
||||
const inputName = event.target.name;
|
||||
const inputValue = event.target.type === 'checkbox' ? event.target.checked : event.target.value;
|
||||
setItem({
|
||||
...item,
|
||||
[inputName]: inputValue,
|
||||
});
|
||||
};
|
||||
|
||||
const handleSubmit = async (event) => {
|
||||
const form = event.currentTarget;
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
const body = getQuestionObject(item);
|
||||
if (form.checkValidity()) {
|
||||
if (id === undefined) {
|
||||
await QuestionsApiService.create(body);
|
||||
} else {
|
||||
await QuestionsApiService.update(id, body);
|
||||
}
|
||||
if (questionsChangeHandle) questionsChangeHandle();
|
||||
toast.success('Элемент успешно сохранен', { id: 'LinesTable' });
|
||||
return true;
|
||||
}
|
||||
setValidated(true);
|
||||
return false;
|
||||
};
|
||||
|
||||
return {
|
||||
item,
|
||||
validated,
|
||||
handleSubmit,
|
||||
handleChange,
|
||||
resetValidity,
|
||||
};
|
||||
};
|
||||
|
||||
export default useQuestionsItemForm;
|
36
laba5/site/src/components/hooks/QuestionsItemHook.js
Normal file
@ -0,0 +1,36 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import QuestionsApiService from '../service/QuestionsApiService';
|
||||
|
||||
const useQuestionsItem = (id) => {
|
||||
const emptyItem = {
|
||||
testId: '',
|
||||
text: '',
|
||||
variant1: '',
|
||||
variant2: '',
|
||||
variant3: '',
|
||||
variant4: '',
|
||||
image: '',
|
||||
};
|
||||
const [item, setItem] = useState({ ...emptyItem });
|
||||
|
||||
const getItem = async (itemId = undefined) => {
|
||||
if (itemId && itemId > 0) {
|
||||
const data = await QuestionsApiService.get(id);
|
||||
setItem(data);
|
||||
} else {
|
||||
setItem({ ...emptyItem });
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
getItem(id);
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [id]);
|
||||
|
||||
return {
|
||||
item,
|
||||
setItem,
|
||||
};
|
||||
};
|
||||
|
||||
export default useQuestionsItem;
|
3
laba5/site/src/components/modal/Modal.css
Normal file
@ -0,0 +1,3 @@
|
||||
.modal-title {
|
||||
font-size: 1.2rem;
|
||||
}
|
42
laba5/site/src/components/modal/ModalConfirm.jsx
Normal file
@ -0,0 +1,42 @@
|
||||
import PropTypes from 'prop-types';
|
||||
import { Button, Modal } from 'react-bootstrap';
|
||||
import { createPortal } from 'react-dom';
|
||||
import './Modal.css';
|
||||
|
||||
const ModalConfirm = ({
|
||||
show, title, message, onConfirm, onClose,
|
||||
}) => {
|
||||
return createPortal(
|
||||
<Modal show={show} backdrop='static' onHide={() => onClose()}>
|
||||
<Modal.Header className='pt-2 pb-2 ps-3 pe-3' closeButton>
|
||||
<Modal.Title>{title}</Modal.Title>
|
||||
</Modal.Header>
|
||||
|
||||
<Modal.Body>
|
||||
{message}
|
||||
</Modal.Body>
|
||||
|
||||
<Modal.Footer className='m-0 pt-2 pb-2 ps-3 pe-3 row justify-content-center'>
|
||||
<Button variant='secondary' className='col-5 m-0 me-2'
|
||||
onClick={() => onClose()}>
|
||||
Нет
|
||||
</Button>
|
||||
<Button variant='primary' className='col-5 m-0 ms-2'
|
||||
onClick={() => onConfirm()}>
|
||||
Да
|
||||
</Button>
|
||||
</Modal.Footer>
|
||||
</Modal>,
|
||||
document.body,
|
||||
);
|
||||
};
|
||||
|
||||
ModalConfirm.propTypes = {
|
||||
show: PropTypes.bool,
|
||||
title: PropTypes.string,
|
||||
message: PropTypes.string,
|
||||
onConfirm: PropTypes.func,
|
||||
onClose: PropTypes.func,
|
||||
};
|
||||
|
||||
export default ModalConfirm;
|
43
laba5/site/src/components/modal/ModalForm.jsx
Normal file
@ -0,0 +1,43 @@
|
||||
import PropTypes from 'prop-types';
|
||||
import { Button, Form, Modal } from 'react-bootstrap';
|
||||
import { createPortal } from 'react-dom';
|
||||
import './Modal.css';
|
||||
|
||||
const ModalForm = ({
|
||||
show, title, validated, onSubmit, onClose, children,
|
||||
}) => {
|
||||
return createPortal(
|
||||
<Modal show={show} backdrop='static' onHide={() => onClose()}>
|
||||
<Modal.Header className='pt-2 pb-2 ps-3 pe-3' closeButton>
|
||||
<Modal.Title>{title}</Modal.Title>
|
||||
</Modal.Header>
|
||||
<Form className='m-0' noValidate validated={validated} onSubmit={onSubmit}>
|
||||
<Modal.Body>
|
||||
{children}
|
||||
</Modal.Body>
|
||||
|
||||
<Modal.Footer className='m-0 pt-2 pb-2 ps-3 pe-3 row justify-content-center'>
|
||||
<Button variant='secondary' className='col-5 m-0 me-2'
|
||||
onClick={() => onClose()}>
|
||||
Отмена
|
||||
</Button>
|
||||
<Button variant='primary' className='col-5 m-0 ms-2' type='submit'>
|
||||
Сохранить
|
||||
</Button>
|
||||
</Modal.Footer>
|
||||
</Form>
|
||||
</Modal>,
|
||||
document.body,
|
||||
);
|
||||
};
|
||||
|
||||
ModalForm.propTypes = {
|
||||
show: PropTypes.bool,
|
||||
title: PropTypes.string,
|
||||
validated: PropTypes.bool,
|
||||
onSubmit: PropTypes.func,
|
||||
onClose: PropTypes.func,
|
||||
children: PropTypes.node,
|
||||
};
|
||||
|
||||
export default ModalForm;
|
21
laba5/site/src/components/modal/ModalHook.js
Normal file
@ -0,0 +1,21 @@
|
||||
import { useState } from 'react';
|
||||
|
||||
const useModal = () => {
|
||||
const [showModal, setShowModal] = useState(false);
|
||||
|
||||
const showModalDialog = () => {
|
||||
setShowModal(true);
|
||||
};
|
||||
|
||||
const hideModalDialog = () => {
|
||||
setShowModal(false);
|
||||
};
|
||||
|
||||
return {
|
||||
isModalShow: showModal,
|
||||
showModal: showModalDialog,
|
||||
hideModal: hideModalDialog,
|
||||
};
|
||||
};
|
||||
|
||||
export default useModal;
|
26
laba5/site/src/components/navigation/Header.css
Normal file
@ -0,0 +1,26 @@
|
||||
header nav {
|
||||
background-color: #f7e987;
|
||||
color: #5b9a8b !important;
|
||||
}
|
||||
|
||||
@media (min-width: 768px) {
|
||||
header nav {
|
||||
height: 64px;
|
||||
}
|
||||
}
|
||||
header nav a:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
header nav a {
|
||||
text-decoration: underline;
|
||||
color: #5b9a8b !important;
|
||||
font-size: 1.5rem !important;
|
||||
}
|
||||
header nav name {
|
||||
color: #5b9a8b !important;
|
||||
font-size: 2rem !important;
|
||||
}
|
||||
|
||||
header nav img{
|
||||
height: 3rem !important;
|
||||
}
|
32
laba5/site/src/components/navigation/Header.jsx
Normal file
@ -0,0 +1,32 @@
|
||||
import './Header.css';
|
||||
import { Link } from 'react-router-dom';
|
||||
import icon from '../../assets/icon-994c7fa6.png';
|
||||
|
||||
const Header = () => {
|
||||
return (
|
||||
<header>
|
||||
<nav className="navbar navbar-expand-md navbar-dark">
|
||||
<div className="container-fluid">
|
||||
<Link className="navbar-brand" to="/">
|
||||
<div>
|
||||
<img src={icon} className="img-fluid" alt={'...'}/>
|
||||
Нереальные тесты
|
||||
</div>
|
||||
</Link>
|
||||
<button className="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav"
|
||||
aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
|
||||
<span className="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
<div className="navbar-collapse collapse justify-content-end" id="navbarNav">
|
||||
<div className="navbar-nav">
|
||||
<Link className="nav-link active" to="/LogIn">Вход</Link>
|
||||
<Link className="nav-link" to="/SignIn">Регистрация</Link>
|
||||
<Link className="nav-link" to="/Profile">Профиль</Link>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
</header>
|
||||
);
|
||||
};
|
||||
export default Header;
|
62
laba5/site/src/components/question/Question.jsx
Normal file
@ -0,0 +1,62 @@
|
||||
import { Form, Button } from 'react-bootstrap';
|
||||
import PropTypes from 'prop-types';
|
||||
import useQuestionsItemForm from '../hooks/QuestionsItemFormHook';
|
||||
import imgPlaceholder from '../../assets/200.png';
|
||||
|
||||
const Question = ({ id, idTest }) => {
|
||||
const {
|
||||
item,
|
||||
handleSubmit,
|
||||
handleChange,
|
||||
} = useQuestionsItemForm(id, idTest);
|
||||
|
||||
const onSubmit = async (event) => {
|
||||
await handleSubmit(event);
|
||||
};
|
||||
return (
|
||||
<>
|
||||
<div className="mb-2" style={{ backgroundColor: '#445069', display: 'flex', flexDirection: 'column' }}>
|
||||
<div className="p-2">
|
||||
<Form.Label className="form-label" htmlFor="file">Файл картинки</Form.Label>
|
||||
<Form.Control type="file" className="form-control" id="file" onChange={handleChange} accept='image/*' />
|
||||
</div>
|
||||
<div className="p-2 w-100" style={{ height: '500px' }}>
|
||||
<img src={item.image || imgPlaceholder} className="h-100 w-100" style={{ objectFit: 'cover' }} alt="" />
|
||||
</div>
|
||||
<div className="p-2">
|
||||
<Form.Label className="form-label" htmlFor="taskText">Текст вопроса</Form.Label>
|
||||
<Form.Control id="taskText" name="text" className="form-control" type="text" value={item.text} onChange={handleChange} required />
|
||||
</div>
|
||||
<div className="p-2">
|
||||
Ответы на вопрос:
|
||||
<div className="form-check me-3">
|
||||
<Form.Check className="" id="checkbox1" name="checkbox1" type="checkbox" />
|
||||
<Form.Control id="checkbox1text" name="variant1" className="form-control" type="text" placeholder="ответ 1" value={item.variant1} onChange={handleChange} />
|
||||
</div>
|
||||
<div className="form-check me-3">
|
||||
<Form.Check className="" id="checkbox2" name="checkbox2" type="checkbox" />
|
||||
<Form.Control id="checkbox2text" name="variant2" className="form-control" type="text" placeholder="ответ 2" value={item.variant2} onChange={handleChange} />
|
||||
</div>
|
||||
<div className="form-check me-3">
|
||||
<Form.Check className="" id="checkbox3" name="checkbox3" type="checkbox" />
|
||||
<Form.Control id="checkbox3text" name="variant3" className="form-control" type="text" placeholder="ответ 3" value={item.variant3} onChange={handleChange} />
|
||||
</div>
|
||||
<div className="form-check me-3">
|
||||
<Form.Check className="" id="checkbox4" name="checkbox4" type="checkbox" />
|
||||
<Form.Control id="checkbox4text" name="variant4" className="form-control" type="text" placeholder="ответ 4" value={item.variant4} onChange={handleChange} />
|
||||
</div>
|
||||
</div>
|
||||
<div className="text-center m-3">
|
||||
<Button className="btn btn-primary w-50 startButton" onClick={ onSubmit }>Готово</Button>
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
Question.propTypes = {
|
||||
id: PropTypes.number,
|
||||
idTest: PropTypes.string,
|
||||
};
|
||||
|
||||
export default Question;
|
31
laba5/site/src/components/rowTest/RowTest.jsx
Normal file
@ -0,0 +1,31 @@
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import PropTypes from 'prop-types';
|
||||
import imgPlaceholder from '../../assets/200.png';
|
||||
|
||||
const RowTest = ({ line }) => {
|
||||
const navigate = useNavigate();
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="row justify-content-center align-items-center g-2 mt-3 mb-3" style={{ height: '10rem' }}>
|
||||
<div className="col-3 h-100">
|
||||
<img src={line.image || imgPlaceholder} className="w-100 h-100" style={{ objectFit: 'cover' }} />
|
||||
</div>
|
||||
<div className="col justify-content-between h-100" style={{ position: 'relative', width: '70%' }}>
|
||||
<div className="row-10 justify-content-center align-items-center g-2">
|
||||
<h3 className="w-100 mx-auto text-left">{ line.description }</h3>
|
||||
</div>
|
||||
<div className="row-2 justify-content-left align-items-left g-2" style={{ position: 'absolute', bottom: '2', left: '2', width: '100%' }}>
|
||||
<a href="#" onClick={ () => { navigate(`/TestPage/${line.id}`); } } className="btn btn-primary startButton">Начать</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
RowTest.propTypes = {
|
||||
line: PropTypes.object,
|
||||
};
|
||||
|
||||
export default RowTest;
|
5
laba5/site/src/components/service/LinesApiService.js
Normal file
@ -0,0 +1,5 @@
|
||||
import ApiService from '../api/ApiService';
|
||||
|
||||
const LinesApiService = new ApiService('lines');
|
||||
|
||||
export default LinesApiService;
|
5
laba5/site/src/components/service/QuestionsApiService.js
Normal file
@ -0,0 +1,5 @@
|
||||
import ApiService from '../api/ApiService';
|
||||
|
||||
const QuestionsApiService = new ApiService('questions');
|
||||
|
||||
export default QuestionsApiService;
|
15
laba5/site/src/components/utils/Base64.js
Normal file
@ -0,0 +1,15 @@
|
||||
const getBase64FromFile = async (file) => {
|
||||
const reader = new FileReader();
|
||||
return new Promise((resolve, reject) => {
|
||||
reader.onloadend = () => {
|
||||
const fileContent = reader.result;
|
||||
resolve(fileContent);
|
||||
};
|
||||
reader.onerror = () => {
|
||||
reject(new Error('Oops, something went wrong with the file reader.'));
|
||||
};
|
||||
reader.readAsDataURL(file);
|
||||
});
|
||||
};
|
||||
|
||||
export default getBase64FromFile;
|
45
laba5/site/src/index.css
Normal file
@ -0,0 +1,45 @@
|
||||
h1 {
|
||||
font-size: 1.5em;
|
||||
color: #f7e987;
|
||||
text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
|
||||
}
|
||||
|
||||
h2 {
|
||||
font-size: 1.25em;
|
||||
color: #f7e987;
|
||||
text-shadow: -1px -1px 0 #000, 1px -1px 0 #000, -1px 1px 0 #000, 3px 3px 0 #000;
|
||||
}
|
||||
|
||||
h3 {
|
||||
font-size: 1.1em;
|
||||
color: #f7e987;
|
||||
}
|
||||
|
||||
.startButton{
|
||||
color: #f7e987;
|
||||
font-size: 1.1em;
|
||||
background-color: #252b48;
|
||||
}
|
||||
|
||||
main{
|
||||
background-color: #5b9a8b;
|
||||
color: #f7e987;
|
||||
height: auto;
|
||||
min-height: 90%;
|
||||
}
|
||||
|
||||
body{
|
||||
height: auto;
|
||||
min-height: 100%;
|
||||
}
|
||||
|
||||
.form-check-input{
|
||||
border: none;
|
||||
border-radius: 0px !important;
|
||||
background-clip: padding-box;
|
||||
}
|
||||
|
||||
.form-control{
|
||||
padding-top: 0;
|
||||
padding-bottom: 0;
|
||||
}
|
61
laba5/site/src/main.jsx
Normal file
@ -0,0 +1,61 @@
|
||||
import 'bootstrap/dist/css/bootstrap.min.css';
|
||||
import React from 'react';
|
||||
import ReactDOM from 'react-dom/client';
|
||||
import { RouterProvider, createBrowserRouter } from 'react-router-dom';
|
||||
import App from './App.jsx';
|
||||
import './index.css';
|
||||
import ErrorPage from './pages/ErrorPage.jsx';
|
||||
import MainPage from './pages/MainPage.jsx';
|
||||
import LogIn from './pages/LogInInIn.jsx';
|
||||
import SignIn from './pages/SignInInIn.jsx';
|
||||
import Profile from './pages/Profile.jsx';
|
||||
import TestInProcess from './pages/TestInProcess.jsx';
|
||||
import TestPage from './pages/TestPage.jsx';
|
||||
import CreateTest from './pages/CreateTest.jsx';
|
||||
|
||||
const routes = [
|
||||
{
|
||||
index: true,
|
||||
path: '/',
|
||||
element: <MainPage />,
|
||||
},
|
||||
{
|
||||
path: '/LogIn',
|
||||
element: <LogIn />,
|
||||
},
|
||||
{
|
||||
path: '/SignIn',
|
||||
element: <SignIn />,
|
||||
},
|
||||
{
|
||||
path: '/Profile',
|
||||
element: <Profile />,
|
||||
},
|
||||
{
|
||||
path: '/TestInProcess/:id?/:idQ?',
|
||||
element: <TestInProcess />,
|
||||
},
|
||||
{
|
||||
path: '/TestPage/:id?',
|
||||
element: <TestPage />,
|
||||
},
|
||||
{
|
||||
path: '/CreateTest/:id?',
|
||||
element: <CreateTest />,
|
||||
},
|
||||
];
|
||||
|
||||
const router = createBrowserRouter([
|
||||
{
|
||||
path: '/',
|
||||
element: <App routes={routes} />,
|
||||
children: routes,
|
||||
errorElement: <ErrorPage />,
|
||||
},
|
||||
]);
|
||||
|
||||
ReactDOM.createRoot(document.getElementById('root')).render(
|
||||
<React.StrictMode>
|
||||
<RouterProvider router={router} />
|
||||
</React.StrictMode>,
|
||||
);
|
81
laba5/site/src/pages/CreateTest.jsx
Normal file
@ -0,0 +1,81 @@
|
||||
import { Button, Form } from 'react-bootstrap';
|
||||
import { useParams, useNavigate } from 'react-router-dom';
|
||||
import Question from '../components/question/Question.jsx';
|
||||
import useLinesItemForm from '../components/hooks/LinesItemFormHook';
|
||||
import imgPlaceholder from '../assets/200.png';
|
||||
import useQuestions from '../components/hooks/QuestionsHook';
|
||||
import QuestionsApiService from '../components/service/QuestionsApiService';
|
||||
|
||||
const CreateTest = () => {
|
||||
const { id } = useParams();
|
||||
|
||||
const navigate = useNavigate();
|
||||
|
||||
const {
|
||||
item,
|
||||
validated,
|
||||
handleSubmit,
|
||||
handleChange,
|
||||
} = useLinesItemForm(id);
|
||||
|
||||
const onBack = () => {
|
||||
navigate(-1);
|
||||
};
|
||||
|
||||
const onSubmit = async (event) => {
|
||||
if (await handleSubmit(event)) {
|
||||
onBack();
|
||||
}
|
||||
};
|
||||
|
||||
const { questions, handleQuestionsChange } = useQuestions(id);
|
||||
|
||||
const newQuest = () => {
|
||||
QuestionsApiService.create({
|
||||
testId: id,
|
||||
text: '',
|
||||
variant1: '',
|
||||
variant2: '',
|
||||
variant3: '',
|
||||
variant4: '',
|
||||
image: '',
|
||||
});
|
||||
handleQuestionsChange();
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="row justify-content-center">
|
||||
<Form className="col-md-6 m-0" noValidate validated={validated} onSubmit={onSubmit}>
|
||||
<div className="mb-2">
|
||||
<Form.Label className="form-label" htmlFor="testName">Название теста</Form.Label>
|
||||
<Form.Control id="testName" name="name" className="form-control" type="text" value={item.name} onChange={handleChange} required />
|
||||
</div>
|
||||
<div className="mb-2">
|
||||
<Form.Label className='form-label' htmlFor='testDescription'>Описание</Form.Label>
|
||||
<Form.Control id='testDescription' name='description' className='form-control' type='text' value={item.description} onChange={handleChange} required />
|
||||
</div>
|
||||
<div className="mb-2">
|
||||
<Form.Label className="form-label" htmlFor="image">Файл картинки</Form.Label>
|
||||
<Form.Control id = "image" type='file' className="form-control" onChange={handleChange} accept='image/*' />
|
||||
</div>
|
||||
<div className="mb-2 w-100" style={{ height: '500px' }} >
|
||||
<img id="image-preview" src={item.image || imgPlaceholder} className="h-100 w-100" style={{ objectFit: 'cover' }} alt=""/>
|
||||
</div>
|
||||
{
|
||||
questions
|
||||
.map((question) => {
|
||||
return <Question key={question.id} id = {question.id} idTest={id} />;
|
||||
})
|
||||
}
|
||||
<div onClick={ newQuest } id="btAddTask" className="btn btn-primary startButton" style={{ backgroundColor: '#445069' }}>Добавить вопрос</div>
|
||||
<div className="text-center m-3">
|
||||
<Button className="btn btn-primary w-50 startButton" type="submit">Готово</Button>
|
||||
</div>
|
||||
</Form>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default CreateTest;
|
19
laba5/site/src/pages/ErrorPage.jsx
Normal file
@ -0,0 +1,19 @@
|
||||
import { Alert, Button, Container } from 'react-bootstrap';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
|
||||
const ErrorPage = () => {
|
||||
const navigate = useNavigate();
|
||||
|
||||
return (
|
||||
<Container fluid className="p-2 row justify-content-center">
|
||||
<Container className='col-md-6'>
|
||||
<Alert variant="danger">
|
||||
Страница не найдена
|
||||
</Alert>
|
||||
<Button className="w-25 mt-2" variant="primary" onClick={() => navigate(-1)}>Назад</Button>
|
||||
</Container>
|
||||
</Container>
|
||||
);
|
||||
};
|
||||
|
||||
export default ErrorPage;
|
23
laba5/site/src/pages/LogInInIn.jsx
Normal file
@ -0,0 +1,23 @@
|
||||
import { Button, Form } from 'react-bootstrap';
|
||||
|
||||
const LogIn = () => {
|
||||
return (
|
||||
<>
|
||||
<Form className="col-md-6 mx-auto mt-3" action="./profile.html" method="get">
|
||||
<Form.Group className="mb-2">
|
||||
<Form.Label className="form-label" htmlFor="email">E-mail</Form.Label>
|
||||
<Form.Control id="email" name="email" className="form-control" type="email" placeholder="name@example.ru" required/>
|
||||
</Form.Group>
|
||||
<Form.Group className="mb-2">
|
||||
<Form.Label className="form-label" htmlFor="password">Пароль</Form.Label>
|
||||
<Form.Control id="password" name="password" className="form-control" type="password" required/>
|
||||
</Form.Group>
|
||||
<Form.Group className="text-center">
|
||||
<Button className="btn btn-primary w-50 startButton" type="submit">Войти</Button>
|
||||
</Form.Group>
|
||||
</Form>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default LogIn;
|
30
laba5/site/src/pages/MainPage.jsx
Normal file
@ -0,0 +1,30 @@
|
||||
import RowTest from '../components/rowTest/RowTest.jsx';
|
||||
import Caroucele from '../components/caroucele/Caroucele.jsx';
|
||||
import useLines from '../components/hooks/LinesHook';
|
||||
import CarouceleItem from '../components/caroucele/CarouseleItem.jsx';
|
||||
|
||||
const MainPage = () => {
|
||||
const { lines } = useLines();
|
||||
|
||||
return (
|
||||
<>
|
||||
<Caroucele>
|
||||
{
|
||||
lines.map((line, index) => {
|
||||
if (index === 0) return (<CarouceleItem key={line.id} line={line} className = {'active'}/>);
|
||||
|
||||
return (<CarouceleItem key={line.id} line={line}/>);
|
||||
})
|
||||
}
|
||||
</Caroucele>
|
||||
<div className="container mt-3 mx-auto" style={{ width: '70%' }}>
|
||||
{
|
||||
lines.map((line) =>
|
||||
<RowTest key={line.id} line={line}/>)
|
||||
}
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default MainPage;
|
60
laba5/site/src/pages/Profile.jsx
Normal file
@ -0,0 +1,60 @@
|
||||
import { Link, useNavigate } from 'react-router-dom';
|
||||
import CreatedTest from '../components/createdTest/CreatedTest.jsx';
|
||||
import useLines from '../components/hooks/LinesHook';
|
||||
import ModalConfirm from '../components/modal/ModalConfirm.jsx';
|
||||
import useLinesDeleteModal from '../components/hooks/LinesDeleteModalHook';
|
||||
|
||||
const Profile = () => {
|
||||
const { lines, handleLinesChange } = useLines();
|
||||
|
||||
const navigate = useNavigate();
|
||||
|
||||
const showOpen = (id) => {
|
||||
navigate(`/TestPage/${id}`);
|
||||
};
|
||||
const showEdit = (id) => {
|
||||
navigate(`/CreateTest/${id}`);
|
||||
};
|
||||
|
||||
const {
|
||||
isDeleteModalShow,
|
||||
showDeleteModal,
|
||||
handleDeleteConfirm,
|
||||
handleDeleteCancel,
|
||||
} = useLinesDeleteModal(handleLinesChange);
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="row w-100" style={{ minHeight: '100%' }}>
|
||||
<div className="" style={{ width: 'auto' }}>
|
||||
<h1>Порофиль</h1>
|
||||
</div>
|
||||
<div className="p-0" style={{ backgroundColor: 'black', width: '5px' }}></div>
|
||||
<div className="col">
|
||||
<h3>Созданные тесты</h3>
|
||||
<div className="row justify-content-center align-items-center g-2 mt-1 mb-1">
|
||||
<h3 className="col-2">навзвание</h3>
|
||||
<h3 className="col">описание</h3>
|
||||
</div>
|
||||
<div id = "items-table">
|
||||
{
|
||||
lines.map((line, index) =>
|
||||
<CreatedTest key={line.id}
|
||||
index={index} line={line}
|
||||
onOpen={() => showOpen(line.id)}
|
||||
onEdit={() => showEdit(line.id)}
|
||||
onDelete={() => showDeleteModal(line.id)}
|
||||
/>)
|
||||
}
|
||||
</div>
|
||||
<Link to="/CreateTest" className="btn btn-primary startButton" >Создать тест</Link>
|
||||
</div>
|
||||
</div>
|
||||
<ModalConfirm show={isDeleteModalShow}
|
||||
onConfirm={handleDeleteConfirm} onClose={handleDeleteCancel}
|
||||
title='Удаление' message='Удалить элемент?' />
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default Profile;
|
31
laba5/site/src/pages/SignInInIn.jsx
Normal file
@ -0,0 +1,31 @@
|
||||
import { Button, Form } from 'react-bootstrap';
|
||||
|
||||
const SignIn = () => {
|
||||
return (
|
||||
<>
|
||||
<Form className="col-md-6 mx-auto mt-3" action="./profile.html" method="get">
|
||||
<Form.Group className="mb-2">
|
||||
<Form.Label className="form-label" htmlFor="firstname">Логин</Form.Label>
|
||||
<Form.Control id="firstname" name="firstname" className="form-control" type="text" placeholder="login" required/>
|
||||
</Form.Group>
|
||||
<Form.Group className="mb-2">
|
||||
<Form.Label className="form-label" htmlFor="email">E-mail</Form.Label>
|
||||
<Form.Control id="email" name="email" className="form-control" type="email" placeholder="name@example.ru" required/>
|
||||
</Form.Group>
|
||||
<Form.Group className="mb-2">
|
||||
<Form.Label className="form-label" htmlFor="password">Пароль</Form.Label>
|
||||
<Form.Control id="password" name="password" className="form-control" type="password" required/>
|
||||
</Form.Group>
|
||||
<Form.Group className="mb-2">
|
||||
<Form.Label className="form-label" htmlFor="passwordAgain">Повторите ароль</Form.Label>
|
||||
<Form.Control id="passwordAgain" name="passwordAgain" className="form-control" type="password" required/>
|
||||
</Form.Group>
|
||||
<Form.Group className="text-center">
|
||||
<Button className="btn btn-primary w-50 startButton" type="submit">Зарегестрироваться</Button>
|
||||
</Form.Group>
|
||||
</Form>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default SignIn;
|
51
laba5/site/src/pages/TestInProcess.jsx
Normal file
@ -0,0 +1,51 @@
|
||||
import { Button, Form } from 'react-bootstrap';
|
||||
import { useParams, useNavigate } from 'react-router-dom';
|
||||
import useQuestions from '../components/hooks/QuestionsHook';
|
||||
import imgPlaceholder from '../assets/200.png';
|
||||
import EndOfTest from '../components/endOfTest/EndOfTest.jsx';
|
||||
|
||||
const TestInProcess = () => {
|
||||
const { id, idQ } = useParams();
|
||||
|
||||
const { questions } = useQuestions(id);
|
||||
|
||||
const navigate = useNavigate();
|
||||
console.log(parseInt(idQ, 10) === questions.length);
|
||||
if (parseInt(idQ, 10) === questions.length) return <EndOfTest></EndOfTest>;
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="row w-100 d-flex justify-content-center m-3">
|
||||
<img src={questions.at(idQ).image || imgPlaceholder} style={{ objectFit: 'cover', width: '50%', height: '500px' }} />
|
||||
</div>
|
||||
|
||||
<h3 className="row w-100 d-flex justify-content-center m-1">{questions.at(idQ).text}</h3>
|
||||
|
||||
<div className="row w-100 justify-content-center m-3">
|
||||
<Form className="col-6 m-0">
|
||||
<Form.Group className="form-check me-md-3">
|
||||
<Form.Check className="" id="checkbox1" name="checkbox1" type="checkbox" />
|
||||
<Form.Label className="form-check-label" htmlFor="checkbox1">{questions.at(idQ).variant1}</Form.Label>
|
||||
</Form.Group>
|
||||
<Form.Group className="form-check me-md-3">
|
||||
<Form.Check className="" id="checkbox2" name="checkbox2" type="checkbox" />
|
||||
<Form.Label className="form-check-label" htmlFor="checkbox2">{questions.at(idQ).variant2}</Form.Label>
|
||||
</Form.Group>
|
||||
<Form.Group className="form-check me-md-3">
|
||||
<Form.Check className="" id="checkbox3" name="checkbox3" type="checkbox" />
|
||||
<Form.Label className="form-check-label" htmlFor="checkbox3">{questions.at(idQ).variant3}</Form.Label>
|
||||
</Form.Group>
|
||||
<Form.Group className="form-check me-md-3">
|
||||
<Form.Check className="" id="checkbox4" name="checkbox4" type="checkbox" />
|
||||
<Form.Label className="form-check-label" htmlFor="checkbox4">{questions.at(idQ).variant4}</Form.Label>
|
||||
</Form.Group>
|
||||
<Form.Group className="text-center">
|
||||
<Button className="btn btn-primary w-2 startButton" onClick={() => { navigate(`/TestInProcess/${id}/${1 + parseInt(idQ, 10)}`); }}>Отправить</Button>
|
||||
</Form.Group>
|
||||
</Form>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default TestInProcess;
|
31
laba5/site/src/pages/TestPage.jsx
Normal file
@ -0,0 +1,31 @@
|
||||
import { useParams, useNavigate } from 'react-router-dom';
|
||||
import imgPlaceholder from '../assets/200.png';
|
||||
import useLinesItem from '../components/hooks/LinesItemHook';
|
||||
|
||||
const TestPage = () => {
|
||||
const { id } = useParams();
|
||||
|
||||
const navigate = useNavigate();
|
||||
|
||||
const { item } = useLinesItem(id);
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="row justify-content-center align-items-center g-2 h-100 m-3 w-100">
|
||||
<div className="h-100" style={{ width: '40%' }}>
|
||||
<div className="w-100 d-flex justify-content-center" style={{ height: '70%' }}>
|
||||
<img src={item.image || imgPlaceholder} className="row w-100" style={{ objectFit: 'contain' }}/>
|
||||
</div>
|
||||
<div className="w-100 d-flex justify-content-center">
|
||||
<a onClick={ () => { navigate(`/TestInProcess/${id}/0`); } } className="row btn btn-primary startButton m-3 w-50" >Начать тест</a>
|
||||
</div>
|
||||
</div>
|
||||
<div className="h-100 d-flex align-items-center m-3" style={{ width: '40%' }}>
|
||||
<h3>{item.description}</h3>
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default TestPage;
|
13
laba5/site/vite.config.js
Normal file
@ -0,0 +1,13 @@
|
||||
/* eslint-disable import/no-extraneous-dependencies */
|
||||
import react from '@vitejs/plugin-react';
|
||||
import { defineConfig } from 'vite';
|
||||
|
||||
// https://vitejs.dev/config/
|
||||
export default defineConfig({
|
||||
plugins: [react()],
|
||||
build: {
|
||||
sourcemap: true,
|
||||
chunkSizeWarningLimit: 1024,
|
||||
emptyOutDir: true,
|
||||
},
|
||||
});
|
BIN
laba5/testInProcess1.jpg
Normal file
After Width: | Height: | Size: 295 KiB |
BIN
laba5/testInProcess1.psd
Normal file
BIN
laba5/testPage.jpg
Normal file
After Width: | Height: | Size: 280 KiB |
BIN
laba5/testPage.psd
Normal file
17
laba5/Заказ.txt
Normal file
@ -0,0 +1,17 @@
|
||||
___Дизайн для сайта с тестами___
|
||||
Необходимо сделать современный дизайн + вёрстка.
|
||||
Экраны:
|
||||
– главная страница
|
||||
– страница с кнопкой начать тест
|
||||
– страница прохождения теста в двух видах(ответ картинкой, ответ текстом и прогрессс барами).
|
||||
– страница создания теста(выбор картинки(как при прохождении) и формы ввода ответа(примеры покажу).
|
||||
– Страница со ссылкой на этот тест(поделиться в соц тетях) и рейтинговая таблица
|
||||
– Страница с результатами ответов на тест.
|
||||
Дополнительно:
|
||||
– Всплывающие окна подтверждения действия
|
||||
– Всплывающие уведомления
|
||||
|
||||
Аудитория преимущественно детская, дизайн должен быть понятным.
|
||||
Необходимо предусмотреть места под рекламу.
|
||||
|
||||
Остальные детали и ссылку на сайт, для которого нужен дизайн, пришлю в сообщениях.
|