This commit is contained in:
Дмитрий Блохин 2024-01-10 21:52:37 +04:00
parent 6063b1cd56
commit 24adbfec1a
56 changed files with 3236 additions and 241 deletions

145
data.json

File diff suppressed because one or more lines are too long

1674
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -4,29 +4,36 @@
"version": "0.0.0", "version": "0.0.0",
"type": "module", "type": "module",
"scripts": { "scripts": {
"dev": "vite",
"build": "vite build",
"lint": "eslint . --ext js,jsx --report-unused-disable-directives --max-warnings 0", "lint": "eslint . --ext js,jsx --report-unused-disable-directives --max-warnings 0",
"preview": "vite preview" "rest": "json-server data.json",
"vite": "vite",
"dev": "npm-run-all --parallel rest vite",
"prod": "npm-run-all lint 'vite build' --parallel rest 'vite preview'"
}, },
"dependencies": { "dependencies": {
"react": "^18.2.0", "axios": "^1.6.1",
"react-dom": "^18.2.0",
"react-router-dom": "^6.18.0",
"bootstrap": "^5.3.2", "bootstrap": "^5.3.2",
"fast-levenshtein": "^3.0.0",
"prop-types": "^15.8.1",
"react": "^18.2.0",
"react-bootstrap": "^2.9.1", "react-bootstrap": "^2.9.1",
"react-bootstrap-icons": "^1.10.3", "react-bootstrap-icons": "^1.10.3",
"prop-types": "^15.8.1" "react-dom": "^18.2.0",
"react-hot-toast": "^2.4.1",
"react-router-dom": "^6.18.0"
}, },
"devDependencies": { "devDependencies": {
"@types/react": "^18.2.15", "@types/react": "^18.2.15",
"@types/react-dom": "^18.2.7", "@types/react-dom": "^18.2.15",
"@vitejs/plugin-react": "^4.0.3", "@vitejs/plugin-react": "^4.0.3",
"eslint": "^8.45.0", "eslint": "^8.45.0",
"eslint-config-airbnb-base": "^15.0.0", "eslint-config-airbnb-base": "^15.0.0",
"eslint-plugin-import": "^2.29.0",
"eslint-plugin-react": "^7.32.2", "eslint-plugin-react": "^7.32.2",
"eslint-plugin-react-hooks": "^4.6.0", "eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-react-refresh": "^0.4.3", "eslint-plugin-react-refresh": "^0.4.3",
"json-server": "^0.17.4",
"npm-run-all": "^4.1.5",
"vite": "^4.4.5" "vite": "^4.4.5"
} }
} }

BIN
src/assets/200.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

@ -0,0 +1,12 @@
const AddExpected = () => {
return (
<>
<span className='mr-2'>Добавить в ожидаемое</span>
<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" fill="red" className="bi bi-archive-fill" viewBox="0 0 16 16">
<path d="M12.643 15C13.979 15 15 13.845 15 12.5V5H1v7.5C1 13.845 2.021 15 3.357 15zM5.5 7h5a.5.5 0 0 1 0 1h-5a.5.5 0 0 1 0-1M.8 1a.8.8 0 0 0-.8.8V3a.8.8 0 0 0 .8.8h14.4A.8.8 0 0 0 16 3V1.8a.8.8 0 0 0-.8-.8z"/>
</svg>
</>
);
};
export default AddExpected;

View File

@ -1,19 +1,24 @@
import { Button } from 'react-bootstrap'; import { Button } from 'react-bootstrap';
import { Link } from 'react-router-dom'; import { Link } from 'react-router-dom';
import { PropTypes } from 'prop-types';
const createCard = ({ Title, Description, Image }) => { const CreateCard = ({ line }) => {
return ( return (
<> <>
<Button className="prev" as={Link} to="/Film" style={{ backgroundColor: '#03001F', border: 'none', marginLeft: '1%' }}> <Button className="prev" as={Link} to={`/Film/${line.id}`} style={{ backgroundColor: '#03001F', border: 'none', marginLeft: '1%' }}>
<div className="card text-bg-dark" style={{ maxWidth: '20rem' }}> <div className="card image-container text-bg-dark" style={{ maxWidth: '20rem' }}>
<img src={Image.img} className="card-img" alt="превью" /> <img src={line.image} className="card-img" alt="превью" />
<div className="card-img-overlay"> <div className="card-img-overlay overlay">
<h5 className="card-title">${Title}</h5> <h5 className="card-title">{line.title}</h5>
<p className="card-text">${Description}</p> <p className="card-text">{line.description}</p>
</div> </div>
</div> </div>
</Button> </Button>
</> </>
); );
}; };
export default createCard; CreateCard.propTypes = {
line: PropTypes.object,
Button: PropTypes.func,
};
export default CreateCard;

View File

@ -0,0 +1,21 @@
import PropTypes from 'prop-types';
import Input from './input/Input.jsx';
const UserPhoto = ({ item, handleChange }) => {
return (
<div style={{
display: 'flex', flexDirection: 'column', alignItems: 'center', justifyContent: 'center', width: '250px', height: '300px',
}}>
<img src={ item.photo } style={{ height: '300px', width: '250px', позиция: 'абсолютная' }}/>
<Input type='file' accept='image/*' style ={{
border: '1px пунктирная черная', backgroundColor: 'grey',
}} onChange={handleChange}/>
</div>
);
};
UserPhoto.propTypes = {
item: PropTypes.object,
handleChange: PropTypes.func,
handleSubmit: PropTypes.func,
};
export default UserPhoto;

View File

@ -0,0 +1,40 @@
import axios from 'axios';
import toast from 'react-hot-toast';
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:3000/',
timeout: '3000',
headers: {
Accept: 'application/json',
},
});
ApiClient.interceptors.response.use(responseHandler, responseErrorHandler);

View File

@ -0,0 +1,29 @@
import { ApiClient } from './ApiClient';
class ApiService {
constructor(url) {
this.url = url;
}
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;

View File

@ -0,0 +1,19 @@
import { Link } from 'react-router-dom';
const CreateAdmin = () => {
let id = '';
try {
id = localStorage.getItem('EnabledUser');
} catch (error) {
id = null;
}
if (id === '1') {
return (
<>
<button className="btn btn-outline-warning button_add"><Link className="nav-link" to="/Admin" style={{ textDecoration: 'none' }}>Панель администратора</Link></button>
</>
);
}
return (<> </>);
};
export default CreateAdmin;

View File

@ -0,0 +1,39 @@
import { Button } from 'react-bootstrap';
import { Link, useNavigate } from 'react-router-dom';
const CreateButton = () => {
const navigator = useNavigate();
let id = '';
try {
id = localStorage.getItem('EnabledUser');
} catch (error) {
id = null;
}
if (id === null) {
return (
<>
<Button className="btn nav-link" variant="outline-info" style={{
borderWidth: '2px', borderColor: '#0dcaf0', borderStyle: 'solid', marginRight: '10px', marginLeft: '20px',
}}><Link to="/Join" style={{ color: 'white', textDecoration: 'none' }}>Вход</Link></Button>{' '}
<Button className="btn nav-link" variant="outline-info" style={{
borderWidth: '2px', borderColor: '#0dcaf0', borderStyle: 'solid', marginRight: '10px', marginLeft: '20px',
}}><Link to="/Register" style={{ color: 'white', textDecoration: 'none' }}>Регистрация</Link></Button>{' '}
</>
);
}
const leave = () => {
localStorage.removeItem('EnabledUser');
navigator('/');
};
return (
<>
<Button className="btn nav-link" variant="outline-info" style={{
borderWidth: '2px', borderColor: '#0dcaf0', borderStyle: 'solid', marginRight: '10px', marginLeft: '20px',
}}><Link to={`/LK/${id}`} style={{ color: 'white', textDecoration: 'none' }}>Личный кабинет</Link></Button>{' '}
<Button className="btn nav-link" variant="outline-danger" style={{
borderWidth: '2px', borderColor: '#0dcaf0', borderStyle: 'solid', marginRight: '10px', marginLeft: '20px',
}} onClick={ (leave) }>Выйти</Button>{' '}
</>
);
};
export default CreateButton;

View File

@ -0,0 +1,23 @@
import PropTypes from 'prop-types';
import { Form } from 'react-bootstrap';
const Input = ({
name, label, value, onChange, className, ...rest
}) => {
return (
<Form.Group className={`mb-2 ${className || ''}`} controlId={name}>
<Form.Label style={{ color: 'white' }}>{label}</Form.Label>
<Form.Control name={name || ''} value={value || ''} onChange={onChange} {...rest} />
</Form.Group>
);
};
Input.propTypes = {
name: PropTypes.string,
label: PropTypes.string,
value: PropTypes.string,
onChange: PropTypes.func,
className: PropTypes.string,
};
export default Input;

View File

@ -0,0 +1,30 @@
import PropTypes from 'prop-types';
import { Form } from 'react-bootstrap';
const Select = ({
values, name, label, value, onChange, className, ...rest
}) => {
return (
<Form.Group className={`mb-2 ${className || ''}`} controlId={name}>
<Form.Label className='form-label' style={{ color: 'white' }}>{label}</Form.Label>
<Form.Select name={name || ''} value={value || ''} onChange={onChange} {...rest}>
<option value=''>Выберите значение</option>
{
// eslint-disable-next-line max-len
values.map((genre) => <option key={genre.id} value={genre.id}>{genre.name}</option>)
}
</Form.Select>
</Form.Group>
);
};
Select.propTypes = {
values: PropTypes.array,
name: PropTypes.string,
label: PropTypes.string,
value: PropTypes.string,
onChange: PropTypes.func,
className: PropTypes.string,
};
export default Select;

View File

@ -0,0 +1,48 @@
import PropTypes from 'prop-types';
import { Button, Form } from 'react-bootstrap';
import { useNavigate } from 'react-router-dom';
import useLinesItemForm from '../hooks/LinesItemFormHook';
import LinesItemForm from './LinesItemForm.jsx';
const LinesForm = ({ id }) => {
const navigate = useNavigate();
const {
item,
validated,
handleSubmit,
handleChange,
} = useLinesItemForm(id);
const onBack = () => {
navigate(-1);
};
const onSubmit = async (event) => {
if (await handleSubmit(event)) {
onBack();
}
};
return (
<>
<Form className='m-0 p-2' noValidate validated={validated} onSubmit={onSubmit}>
<LinesItemForm item={item} handleChange={handleChange} />
<Form.Group className='row justify-content-center m-0 mt-3'>
<Button className='btn-mw me-md-3 mb-md-0 mb-2' variant='secondary' style={{ height: '7%', fontSize: '16px' }} onClick={() => onBack()}>
Назад
</Button>
<Button className='btn-mw me-md-3' type='submit' variant='primary' style={{ height: '7%', fontSize: '16px' }}>
Сохранить
</Button>
</Form.Group>
</Form>
</>
);
};
LinesForm.propTypes = {
id: PropTypes.string,
};
export default LinesForm;

View File

@ -0,0 +1,7 @@
#image-preview {
width: 200px;
}
.Input > label {
color: white;
background-color: white;
}

View File

@ -0,0 +1,40 @@
import PropTypes from 'prop-types';
import imgPlaceholder from '../../../assets/200.png';
import Input from '../../input/Input.jsx';
import Select from '../../input/Select.jsx';
import useGenres from '../../types/hooks/GenresHook';
import './LinesItemForm.css';
const LinesItemForm = ({ item, handleChange }) => {
const { genres } = useGenres();
return (
<>
<div className='text-center'>
<img id='image-preview' className='rounded' alt='placeholder' style={{ marginTop: '30px' }}
src={item.image || imgPlaceholder} />
</div>
<Select values={genres} name='genreId' label='Жанр' value={item.genreId} onChange={handleChange}
required />
<Input name='title' label='Название продукта' value={item.title} onChange={handleChange}
type='text' required />
<Input name='cast' label='Актерский состав' value={item.cast} onChange={handleChange}
type='text' required />
<Input name='description' label='Описание' value={item.description} onChange={handleChange}
type='text' required />
<Input name='rating' label={`Рейтинг ${item.rating}`} value={item.rating} onChange={handleChange}
type='range' min={0} max={10} step={1} required />
<Input name='image' label='Превью' onChange={handleChange}
type='file' accept='image/*' />
<Input name='video' label='Видеофайл' onChange={handleChange}
type='file' accept='video/*' />
</>
);
};
LinesItemForm.propTypes = {
item: PropTypes.object,
handleChange: PropTypes.func,
};
export default LinesItemForm;

View File

@ -0,0 +1,34 @@
import { useState } from 'react';
import toast from 'react-hot-toast';
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;

View File

@ -0,0 +1,28 @@
import { useSearchParams } from 'react-router-dom';
import useGenres from '../../types/hooks/GenresHook';
const useGenreFilter = () => {
const filterName = 'genre';
const [searchParams, setSearchParams] = useSearchParams();
const { genres } = useGenres();
const handleFilterChange = (event) => {
const genre = event.target.value;
if (genre) {
searchParams.set(filterName, event.target.value);
} else {
searchParams.delete(filterName);
}
setSearchParams(searchParams);
};
return {
genres,
currentFilter: searchParams.get(filterName) || '',
handleFilterChange,
};
};
export default useGenreFilter;

View File

@ -0,0 +1,29 @@
import { useEffect, useState } from 'react';
import LinesApiService from '../service/LinesApiService';
const useLines = (genreFilter) => {
const [linesRefresh, setLinesRefresh] = useState(false);
const [lines, setLines] = useState([]);
const handleLinesChange = () => setLinesRefresh(!linesRefresh);
const getLines = async () => {
let expand = '?_expand=genres';
if (genreFilter) {
expand = `${expand}&genresId=${genreFilter}`;
}
const data = await LinesApiService.getAll(expand);
setLines(data ?? []);
};
useEffect(() => {
getLines();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [linesRefresh, genreFilter]);
return {
lines,
handleLinesChange,
};
};
export default useLines;

View File

@ -0,0 +1,92 @@
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 genresId = parseInt(formData.genreId, 10);
const title = formData.title.toString();
const cast = formData.cast.toString();
const description = formData.description.toString();
const rating = parseInt(formData.rating, 10);
const image = formData.image.startsWith('data:image') ? formData.image : '';
const video = formData.video.startsWith('data:video') ? formData.video : '';
return {
genresId: genresId.toString(),
title,
cast,
description,
rating,
image,
video,
};
};
const handleImageChange = async (event) => {
const { files } = event.target;
const file = await getBase64FromFile(files.item(0));
if (event.target.name === 'image') {
setItem({
...item,
image: file,
});
} else {
setItem({
...item,
video: 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;

View File

@ -0,0 +1,36 @@
import { useEffect, useState } from 'react';
import LinesApiService from '../service/LinesApiService';
const useLinesItem = (id) => {
const emptyItem = {
genresId: '',
title: '',
cast: '',
description: '',
rating: '',
image: '',
video: '',
};
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;

View File

@ -0,0 +1,83 @@
import { useState } from 'react';
import toast from 'react-hot-toast';
import UserApiService from '../../types/service/UserApiService';
import useLinesUser from './LinesUserHook';
import getBase64FromFile from '../../utils/Base64';
const useLinesUserForm = (id, linesChangeHandle) => {
const { item, setItem } = useLinesUser(id);
const [validated, setValidated] = useState(false);
const resetValidity = () => {
setValidated(false);
};
const getLineObject = (formData) => {
const name = formData.name.toString();
const login = formData.login.toString();
const mail = formData.mail.toString();
const password = formData.password.toString();
const photo = formData.photo.startsWith('data:image') ? formData.photo : '';
return {
name,
login,
mail,
password,
photo,
};
};
const handleImageChange = async (event) => {
const { files } = event.target;
const file = await getBase64FromFile(files.item(0));
if (event.target.name === 'photo') {
setItem({
...item,
photo: 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 UserApiService.create(body);
} else {
await UserApiService.update(id, body);
}
if (linesChangeHandle) linesChangeHandle();
toast.success('Элемент успешно сохранен', { id: 'LinesTable' });
return true;
}
setValidated(true);
return false;
};
return {
item,
validated,
handleSubmit,
handleChange,
resetValidity,
};
};
export default useLinesUserForm;

View File

@ -0,0 +1,35 @@
import { useEffect, useState } from 'react';
import UserApiService from '../../types/service/UserApiService';
const useLinesUser = (id) => {
const emptyItem = {
id: '',
name: '',
login: '',
mail: '',
password: '',
photo: '',
};
const [item, setItem] = useState({ ...emptyItem });
const getItem = async (itemId = undefined) => {
if (itemId && itemId > 0) {
const data = await UserApiService.get(itemId);
setItem(data);
} else {
setItem({ ...emptyItem });
}
};
useEffect(() => {
getItem(id);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [id]);
return {
item,
setItem,
};
};
export default useLinesUser;

View File

@ -0,0 +1,33 @@
import PropTypes from 'prop-types';
import { Button, Form, FormGroup } from 'react-bootstrap';
import { Link } from 'react-router-dom';
import titleBlack from '../../../assets/Title_black.png';
const FormRegister = ({ item, handleChange }) => {
return (
<>
<center><Button as={Link} to="/" style={{ backgroundColor: 'white', borderColor: 'white' }}><img id="image_title" src={titleBlack} alt="название" className="Title"/></Button></center>
<FormGroup className="reg_name" controlId="userName">
<Form.Label className="form-label"></Form.Label>
<Form.Control type="text" name="name" className="form-control" placeholder="Имя" value={item.name} onChange={handleChange} required />
</FormGroup>
<FormGroup className="reg_login" controlId="Login">
<Form.Label className="form-label"></Form.Label>
<Form.Control type="text" name="login" className="form-control" placeholder="Логин" value={item.login} onChange={handleChange} required />
</FormGroup>
<FormGroup className="reg_mail" controlId="Mail">
<Form.Label className="form-label"></Form.Label>
<Form.Control type="email" name="mail" className="form-control" placeholder="Почта пользователя" value={item.mail} onChange={handleChange} required />
</FormGroup>
<FormGroup className="reg_pass" controlId="regPassword">
<Form.Label className="form-label"></Form.Label>
<Form.Control type="password" name="password" className="form-control" placeholder="Пароль" value={item.password} onChange={handleChange} required />
</FormGroup>
</>
);
};
FormRegister.propTypes = {
item: PropTypes.object,
handleChange: PropTypes.func,
};
export default FormRegister;

View File

@ -0,0 +1,5 @@
import ApiService from '../../api/ApiService';
const LinesApiService = new ApiService('lines');
export default LinesApiService;

View File

@ -0,0 +1,55 @@
import { Button, ButtonGroup } from 'react-bootstrap';
import { Link, useNavigate } from 'react-router-dom';
import Select from '../../input/Select.jsx';
import ModalConfirm from '../../modal/ModalConfirm.jsx';
import useLinesDeleteModal from '../hooks/LinesDeleteModalHook';
import useGenreFilter from '../hooks/LinesFilterHook';
import useLines from '../hooks/LinesHook';
import LinesTable from './LinesTable.jsx';
import LinesTableRow from './LinesTableRow.jsx';
const Lines = () => {
const { genres, currentFilter, handleFilterChange } = useGenreFilter();
const { lines, handleLinesChange } = useLines(currentFilter);
const {
isDeleteModalShow,
showDeleteModal,
handleDeleteConfirm,
handleDeleteCancel,
} = useLinesDeleteModal(handleLinesChange);
const navigate = useNavigate();
const showEditPage = (id) => {
navigate(`/Input/${id}`);
};
return (
<>
<ButtonGroup>
<Button as={Link} to='/Input' variant='outline-warning' style={{ marginTop: '40px' }}>
Добавить товар
</Button>
</ButtonGroup>
<Select className='mt-2' values={genres} label='Фильтр по жанрам'
value={currentFilter} onChange={handleFilterChange} />
<LinesTable>
{
lines.map((line, index) =>
<LinesTableRow key={line.id}
index={index} line={line}
onDelete={() => showDeleteModal(line.id)}
onEditInPage={() => showEditPage(line.id)}
/>)
}
</LinesTable>
<ModalConfirm show={isDeleteModalShow}
onConfirm={handleDeleteConfirm} onClose={handleDeleteCancel}
title='Удаление' message='Удалить элемент?' />
</>
);
};
export default Lines;

View File

@ -0,0 +1,30 @@
import PropTypes from 'prop-types';
import { Table } from 'react-bootstrap';
const LinesTable = ({ children }) => {
return (
<Table className='mt-2' striped responsive>
<thead style={{ backgroundColor: '#03001F' }}>
<tr>
<th scope="col" className="colums" style={{ color: 'white' }}></th>
<th scope="col" className="w-25 colums" style={{ color: 'white' }}>Жанр</th>
<th scope="col" className="w-25 colums" style={{ color: 'white' }}>Название</th>
<th scope="col" className="w-25 colums" style={{ color: 'white' }}>Актерский состав</th>
<th scope="col" className="w-25 colums" style={{ color: 'white' }}>Описание</th>
<th scope="col" className="w-25 colums" style={{ color: 'white' }}>Рейтинг</th>
<th scope="col"></th>
<th scope="col"></th>
</tr>
</thead>
<tbody>
{children}
</tbody >
</Table >
);
};
LinesTable.propTypes = {
children: PropTypes.node,
};
export default LinesTable;

View File

@ -0,0 +1,34 @@
import PropTypes from 'prop-types';
import { PencilSquare, Trash3 } from 'react-bootstrap-icons';
const LinesTableRow = ({
index, line, onDelete, onEditInPage,
}) => {
const handleAnchorClick = (event, action) => {
event.preventDefault();
action();
};
return (
<tr>
<th scope="row">{index + 1}</th>
<td>{line.genres.name}</td>
<td>{line.title}</td>
<td>{line.cast}</td>
<td>{line.description}</td>
<td>{line.rating}</td>
<td><a href="#" onClick={(event) => handleAnchorClick(event, onEditInPage)}><PencilSquare /></a></td>
<td><a href="#" onClick={(event) => handleAnchorClick(event, onDelete)}><Trash3 /></a></td>
</tr>
);
};
LinesTableRow.propTypes = {
index: PropTypes.number,
line: PropTypes.object,
onDelete: PropTypes.func,
onEdit: PropTypes.func,
onEditInPage: PropTypes.func,
};
export default LinesTableRow;

View File

@ -0,0 +1,3 @@
.modal-title {
font-size: 1.2rem;
}

View 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;

View 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;

View 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;

View File

@ -1,13 +1,13 @@
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { import {
Container, Nav, Navbar, Button, Container, Nav, Navbar,
} from 'react-bootstrap'; } from 'react-bootstrap';
import { Link } from 'react-router-dom'; import { Link } from 'react-router-dom';
import title from '../../assets/Title.png'; import title from '../../assets/Title.png';
import NavButton from '../button/NavButton.jsx';
const Navigation = ({ routes }) => { const Navigation = ({ routes }) => {
const indexPageLink = routes.filter((route) => route.index === false).shift(); const indexPageLink = routes.filter((route) => route.index === false).shift();
return ( return (
<header> <header>
<Navbar expand='md' className='my-navbar fixed-top' style={{ backgroundColor: '#03001F' }}> <Navbar expand='md' className='my-navbar fixed-top' style={{ backgroundColor: '#03001F' }}>
@ -18,15 +18,7 @@ const Navigation = ({ routes }) => {
<Navbar.Toggle aria-controls='main-navbar' /> <Navbar.Toggle aria-controls='main-navbar' />
<Navbar.Collapse id='main-navbar' style={{ flexGrow: '0' }}> <Navbar.Collapse id='main-navbar' style={{ flexGrow: '0' }}>
<Nav className="navbar-nav"> <Nav className="navbar-nav">
<Button className="btn nav-link" variant="outline-info" style={{ <NavButton></NavButton>
borderWidth: '2px', borderColor: '#0dcaf0', borderStyle: 'solid',
}}><Link to="/Join" style={{ color: 'white', textDecoration: 'none' }}>Вход</Link></Button>{' '}
<Button className="btn nav-link" variant="outline-info" style={{
borderWidth: '2px', borderColor: '#0dcaf0', borderStyle: 'solid',
}}><Link to="/Register" style={{ color: 'white', textDecoration: 'none' }}>Регистрация</Link></Button>{' '}
<Button className="btn nav-link" variant="outline-info" style={{
borderWidth: '2px', borderColor: '#0dcaf0', borderStyle: 'solid',
}}><Link to="/LK" style={{ color: 'white', textDecoration: 'none' }}>Личный кабинет</Link></Button>{' '}
</Nav> </Nav>
</Navbar.Collapse> </Navbar.Collapse>
</Container> </Container>

View File

@ -0,0 +1,15 @@
import { PropTypes } from 'prop-types';
import Input from '../input/Input.jsx';
const SearchButton = (props) => {
return (
<div className="col col-sm-4">
<Input className="form-control" value={props.value} onChange={(event) => props.setSearchValue(event.target.value)} placeholder="Type to search..."/>
</div>
);
};
SearchButton.propTypes = {
value: PropTypes.object,
setSearchValue: PropTypes.func,
};
export default SearchButton;

View File

@ -0,0 +1,29 @@
import { useEffect, useState } from 'react';
import LinesApiService from '../lines/service/LinesApiService';
const useHookSearch = (genreFilter) => {
const [linesRefresh, setLinesRefresh] = useState(false);
const [lines, setLines] = useState([]);
const handleLinesChange = () => setLinesRefresh(!linesRefresh);
const getLines = async () => {
let expand = '?_expand=genres';
if (genreFilter) {
expand = `${expand}&title_like=${genreFilter}`;
}
const data = await LinesApiService.getAll(expand);
setLines(data ?? []);
};
useEffect(() => {
getLines();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [linesRefresh, genreFilter]);
return {
lines,
handleLinesChange,
};
};
export default useHookSearch;

View File

@ -0,0 +1,22 @@
import { useLocation } from 'react-router-dom';
import useHookSearch from './SearchHook';
const useQuery = () => {
return new URLSearchParams(useLocation().search);
};
const SearchMovies = () => {
const query = useQuery();
const searchText = query.get('find')?.toLowerCase() || '';
const { lines } = useHookSearch(searchText);
const files = lines.filter((line) => (
line.title.toLowerCase().includes(searchText.toLowerCase())
));
return {
files,
};
};
export default SearchMovies;

View File

@ -0,0 +1,30 @@
import { useEffect, useState } from 'react';
import GenreApiService from '../service/GenreApiService';
const useGenre = (id) => {
const emptyItem = {
name: '',
};
const [genres, setGenre] = useState({ ...emptyItem });
const getGenre = async (Tid = undefined) => {
if (Tid && Tid > 0) {
const data = await GenreApiService.get(Tid);
setGenre(data);
} else {
setGenre({ ...emptyItem });
}
};
useEffect(() => {
getGenre(id);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [id]);
return {
genres,
setGenre,
};
};
export default useGenre;

View File

@ -0,0 +1,21 @@
import { useEffect, useState } from 'react';
import GenreApiService from '../service/GenreApiService';
const useGenres = () => {
const [genres, setTypes] = useState([]);
const getTypes = async () => {
const data = await GenreApiService.getAll();
setTypes(data ?? []);
};
useEffect(() => {
getTypes();
}, []);
return {
genres,
};
};
export default useGenres;

View File

@ -0,0 +1,5 @@
import ApiService from '../../api/ApiService';
const GenreApiService = new ApiService('genres');
export default GenreApiService;

View File

@ -0,0 +1,5 @@
import ApiService from '../../api/ApiService';
const UserApiService = new ApiService('user');
export default UserApiService;

View File

@ -0,0 +1,69 @@
import toast from 'react-hot-toast';
import UserApiService from '../types/service/UserApiService';
import useLinesUser from '../lines/hooks/LinesUserHook';
import getBase64FromFile from '../utils/Base64';
const usePhoto = (id, linesChangeHandle) => {
const { item, setItem } = useLinesUser(id);
const getLineObject = (formData) => {
const name = formData.name.toString();
const login = formData.login.toString();
const mail = formData.mail.toString();
const password = formData.password.toString();
const photo = formData.photo.startsWith('data:image') ? formData.photo : '';
return {
name,
login,
mail,
password,
photo,
};
};
const handleImageChange = async (event) => {
const { files } = event.target;
const file = await getBase64FromFile(files.item(0));
setItem({
...item,
photo: file,
});
};
const handleSubmit = async (event) => {
const form = event.currentTarget;
event.preventDefault();
event.stopPropagation();
const body = getLineObject(item);
if (form.checkValidity()) {
if (id === undefined) {
await UserApiService.create(body);
} else {
await UserApiService.update(id, body);
}
if (linesChangeHandle) linesChangeHandle();
toast.success('Элемент успешно сохранен', { id: 'LinesTable' });
return true;
}
return false;
};
const handleChange = (event) => {
if (event.target.type === 'file') {
handleImageChange(event);
handleSubmit(event);
return;
}
const inputName = event.target.name;
const inputValue = event.target.type === 'checkbox' ? event.target.checked : event.target.value;
setItem({
...item,
[inputName]: inputValue,
});
};
return {
item,
handleSubmit,
handleChange,
};
};
export default usePhoto;

View File

@ -0,0 +1,21 @@
import { useEffect, useState } from 'react';
import UserApiService from '../types/service/UserApiService';
const useUsers = () => {
const [user, setTypes] = useState([]);
const getTypes = async () => {
const data = await UserApiService.getAll();
setTypes(data ?? []);
};
useEffect(() => {
getTypes();
}, []);
return {
user,
};
};
export default useUsers;

View File

@ -0,0 +1,33 @@
import { useEffect, useState } from 'react';
import UserApiService from '../types/service/UserApiService';
const useJoinUser = (loginEnter) => {
let login = loginEnter;
const [user, setUser] = useState(null);
const getUser = async () => {
const data = await UserApiService.getAll(`?login=${login}`);
if (data && data.length > 0) {
setUser(data[0]);
} else {
setUser(null);
}
};
useEffect(() => {
getUser(login);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
const handlerLoginChanged = (newLogin) => {
login = newLogin;
getUser();
};
return {
user,
handlerLoginChanged,
};
};
export default useJoinUser;

View 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;

View File

@ -18,6 +18,31 @@ h3 {
--bs-table-color: white; --bs-table-color: white;
--bs-table-striped-color: white; --bs-table-striped-color: white;
} }
.card-text{
font-size: 14px;
}
.image-container{
position: relative;
transition: transform 0.2s;
}
.image-container:hover{
cursor: pointer;
transform: scale(1.1);
}
.image-container:hover .overlay{
opacity: 1;
}
.overlay{
position: absolute;
background: rgba(0,0,0, 0.8);
width: 100%;
transition: 0.5s ease;
opacity: 0;
bottom: 0;
font-size: 20px;
padding: 20px;
text-align: center;
}
@media (min-width: 768px) { @media (min-width: 768px) {
.btn-mw { .btn-mw {
width: 30%; width: 30%;
@ -80,9 +105,6 @@ header nav a:hover {
width: 15rem; width: 15rem;
margin: 0 0 0 0.5%; margin: 0 0 0 0.5%;
} }
.btn-outline-info{
margin-right: 10px;
}
.btn-light{ .btn-light{
max-width: 50rem; max-width: 50rem;
width: 50rem; width: 50rem;
@ -301,7 +323,7 @@ header nav a:hover {
@media (min-width: 615px) { @media (min-width: 615px) {
.DobPhoto { .DobPhoto {
padding: 0; padding: 0;
margin: 8% 0 0 2%; margin: 4% 0 0 2%;
display: flex; display: flex;
justify-content: left; justify-content: left;
align-items: center; align-items: center;
@ -336,36 +358,36 @@ header nav a:hover {
margin-left: 10%; margin-left: 10%;
} }
.description{ .description{
width: 250px; width: 400px;
height: 500px;
margin-left: 5%; margin-left: 5%;
} }
.description_info{ .description_info{
background-color: #414141; background-color: #414141;
color: white; color: white;
border-radius: 15px; border-radius: 15px;
width: 90%; width: 100%;
height: 100%; height: 100%;
text-align: center; text-align: center;
margin-top: 5%; margin-top: 5%;
margin-left: 5%; margin-left: 5%;
font-size: 20px; font-size: 20px;
overflow: auto;
} }
.actorList{ .actorList{
margin: 20px 0 0 100px;
width: 250px; width: 250px;
margin-left: 2%; height: 90%;
} }
.actor{ .actor{
background-color: #414141; background-color: #414141;
color: white; color: white;
border-radius: 15px; border-radius: 15px;
width: 100%; width: 80%;
height: 140%; height: 100%;
text-align: center; text-align: center;
margin-top: 15%; margin-top: 15%;
margin-left: 5%; margin-left: 5%;
font-size: 20px; font-size: 20px;
overflow: auto;
} }
@media (min-width: 990px){ @media (min-width: 990px){
.MainTitle{ .MainTitle{
@ -386,7 +408,7 @@ header nav a:hover {
width: 70%; width: 70%;
} }
.actor{ .actor{
width: 250px; width: 80%;
} }
} }
@media (max-width: 770px) { @media (max-width: 770px) {
@ -415,12 +437,11 @@ header nav a:hover {
} }
.description_info{ .description_info{
width: 138%; width: 138%;
height: 100px; height: 300px;
} }
.actor{ .actor{
height: 100px; height: 100px;
width: 200%; width: 200%;
margin-left: 9%;
} }
} }
@ -432,6 +453,7 @@ header nav a:hover {
width: 100%; width: 100%;
} }
.actorList{ .actorList{
margin: 0 0 0 0;
width: 90%; width: 90%;
} }
.actor{ .actor{

View File

@ -13,6 +13,8 @@ import Input from './pages/Input.jsx';
import Join from './pages/Join.jsx'; import Join from './pages/Join.jsx';
import Register from './pages/Register.jsx'; import Register from './pages/Register.jsx';
import Media from './pages/Media.jsx'; import Media from './pages/Media.jsx';
import Genre from './pages/Genre.jsx';
import Search from './pages/Search.jsx';
const routes = [ const routes = [
{ {
@ -22,12 +24,12 @@ const routes = [
title: 'Главная страница', title: 'Главная страница',
}, },
{ {
path: '/LK', path: '/LK/:id?',
element: <LK />, element: <LK />,
title: 'Личный кабинет', title: 'Личный кабинет',
}, },
{ {
path: '/Film', path: '/Film/:id?',
element: <Film />, element: <Film />,
title: 'Страница фильма', title: 'Страница фильма',
}, },
@ -42,7 +44,7 @@ const routes = [
title: 'Страница регистрации', title: 'Страница регистрации',
}, },
{ {
path: '/Media', path: '/Media/:id?',
element: <Media />, element: <Media />,
title: 'Страница видеоплеера', title: 'Страница видеоплеера',
}, },
@ -52,9 +54,19 @@ const routes = [
title: 'Админ-панель', title: 'Админ-панель',
}, },
{ {
path: '/Input', path: '/Input/:id?',
element: <Input />, element: <Input />,
}, },
{
path: '/Genre/:id?',
element: <Genre />,
title: 'Страница Жанра',
},
{
path: '/Search',
element: <Search />,
title: 'Страница поиска',
},
]; ];
const router = createBrowserRouter([ const router = createBrowserRouter([

View File

@ -1,27 +1,8 @@
import { Button, ButtonGroup, Table } from 'react-bootstrap'; import Lines from '../components/lines/table/Lines.jsx';
import { Link } from 'react-router-dom';
const Admin = () => { const Admin = () => {
return ( return (
<> <Lines />
<ButtonGroup className="button_input">
<Button as={Link} to="/Input" variant="outline-warning" className="btn AdminPanel" >Добавить фильм</Button>
</ButtonGroup>
<Table className="mt-2" striped id="items-table">
<thead style={{ backgroundColor: '#03001F' }}>
<tr>
<th scope="col" className="colums" style={{ color: 'white' }}></th>
<th scope="col" className="w-25 colums" style={{ color: 'white' }}>Жанр</th>
<th scope="col" className="w-25 colums" style={{ color: 'white' }}>Название</th>
<th scope="col" className="w-25 colums" style={{ color: 'white' }}>Актерский состав</th>
<th scope="col" className="w-25 colums" style={{ color: 'white' }}>Описание</th>
<th scope="col"></th>
<th scope="col"></th>
</tr>
</thead>
<tbody></tbody>
</Table>
</>
); );
}; };

View File

@ -1,31 +1,42 @@
import { useParams, Link } from 'react-router-dom';
import useLinesItemForm from '../components/lines/hooks/LinesItemFormHook';
const Film = () => { const Film = () => {
const { id } = useParams();
const { item } = useLinesItemForm(id);
return ( return (
<div className="film rows container item"> <div className="film rows container item">
<div className="Rating" style=""> <div className="Rating">
<div> <div>
<img className="prevFilm" src="img/Prev.png" alt="превью"/> <img className="prevFilm" src={ item.image } alt="превью"/>
</div> </div>
<div className="rat"> <div className="rat">
Рейтинг Рейтинг
</div> </div>
<div className="rat"> <div className="rat">
10 из 10 { item.rating } из 10
</div> </div>
</div> </div>
<div className="description"> <div className="description">
<div className="rat"> <div className="rat">
Название фильма { item.title }
</div> </div>
<div> <div>
<button className="btn btn-warning watch" type="button"><a className="nav-link" aria-current="page" href="media.html" style={{ textDecoration: 'none' }}>Просмотр</a></button> <button className="btn btn-warning watch"><Link className="nav-link" aria-current="page" to={`/Media/${item.id}`} style={{ textDecoration: 'none' }}>Просмотр</Link></button>
</div> </div>
<div className="description_info"> <div className="description_info">
Описание фильма Описание
<div>
{ item.description }
</div>
</div> </div>
</div> </div>
<div className="actorList"> <div className="actorList">
<div style={{ color: 'white', margin: '40px 0 0 30px', fontSize: '20px' }}>
Актерский состав
</div>
<div className="actor"> <div className="actor">
Актерский состав { item.cast }
</div> </div>
</div> </div>
</div> </div>

21
src/pages/Genre.jsx Normal file
View File

@ -0,0 +1,21 @@
import { useParams } from 'react-router-dom';
import useLines from '../components/lines/hooks/LinesHook';
import CreateCard from '../components/Card/Cards.jsx';
import useGenre from '../components/types/hooks/GenreHook';
const Genre = () => {
const { id } = useParams();
const { lines } = useLines(id);
const { genres } = useGenre(id);
return (
<>
<span className="text">{ genres.name }</span>
<div className="card-group rows images">
{
lines.map((el) => <CreateCard key={el.id} line={el}/>)
}
</div>
</>
);
};
export default Genre;

View File

@ -1,33 +1,48 @@
import { Button } from 'react-bootstrap'; import { Button, Dropdown } from 'react-bootstrap';
import { Link } from 'react-router-dom'; import { useNavigate } from 'react-router-dom';
import useLines from '../components/lines/hooks/LinesHook';
import CreateCard from '../components/Card/Cards.jsx';
import useGenres from '../components/types/hooks/GenresHook';
const Index = () => { const Index = () => {
const { lines } = useLines();
const { genres } = useGenres();
const navigate = useNavigate();
const RedirectSearch = (event) => {
event.preventDefault();
const searchText = document.getElementById('search').value;
navigate(`/search?find=${encodeURIComponent(searchText)}`);
};
return ( return (
<> <>
<span className="text">Рекомендуемое</span> <right><div style={{ marginTop: '50px' }}>
<div className="card-group rows images"> <input type="search" id="search" style={{
<Link to='/'>Заглушка</Link> borderRadius: '15px', borderColor: '#0dcaf0', backgroundColor: '#03001F', marginLeft: '20px', color: 'white',
</div> }} placeholder="Поиск" aria-label="Search" />
<span className="text">Жанры</span> <button onClick={RedirectSearch} className="btn" style={{ borderColor: '#0dcaf0', borderRadius: '50px', marginTop: '-3px' }} type="submit" >
<svg xmlns="http://www.w3.org/2000/svg" width="15" height="15" fill="currentColor" className="bi bi-search" viewBox="0 0 16 16">
<path d="M11.742 10.344a6.5 6.5 0 1 0-1.397 1.398h-.001q.044.06.098.115l3.85 3.85a1 1 0 0 0 1.415-1.414l-3.85-3.85a1 1 0 0 0-.115-.1zM12 6.5a5.5 5.5 0 1 1-11 0 5.5 5.5 0 0 1 11 0"/>
</svg>
</button>
</div></right>
<span className="text">Жанры</span>
<div className="genreselection"> <div className="genreselection">
<Button className="btn" variant="secondary" style={{ width: '17rem', margin: '0 0 0 0.5%' }}>Комедия</Button> { genres.map((ge) => <Button className="btn" variant="secondary" style={{ width: '17rem', margin: '0 0 0 1%' }} key={ge.id} onClick={() => navigate(`/Genre/${ge.id}`)} >{ge.name}</Button>) }
<Button className="btn" variant="secondary" style={{ width: '17rem', margin: '0 0 0 2%' }}>Боевик</Button>
<Button className="btn" variant="secondary" style={{ width: '17rem', margin: '0 0 0 2%' }}>Фэнтези</Button>
<Button className="btn" variant="secondary" style={{ width: '17rem', margin: '0 0 0 2%' }}>Романтика</Button>
<Button className="btn" variant="secondary" style={{ width: '17rem', margin: '0 0 0 2%' }}>Драма</Button>
</div> </div>
<div className="btn-groups dropup"> <Dropdown className="btn-groups dropup" style={{ height: '50' }}>
<Button className="btn dropbutton dropdown-toggle" variant="info" data-bs-toggle="dropdown" aria-expanded="false" style={{ fontSize: '20px' }}> <Dropdown.Toggle className="btn dropbutton dropdown-toggle" variant="info" data-bs-toggle="dropdown" aria-expanded="false" style={{ fontSize: '20px' }}>
Жанры Жанры
</Button> </Dropdown.Toggle>
<ul className="dropdown-menu"> <Dropdown.Menu>
<li><Button className="btn" variant="secondary" >Комедия</Button></li> { genres.map((ge) => <Button className="btn" flexWrap="wrap" variant="secondary" style={{ width: '10rem', margin: '0 0 0 1%' }} key={ge.id} onClick={() => navigate(`/Genre/${ge.id}`)} >{ge.name}</Button>) }
<li><Button className="btn" variant="secondary" >Боевик</Button></li> </Dropdown.Menu>
<li><Button className="btn" variant="secondary" >Фэнтези</Button></li> </Dropdown>
<li><Button className="btn" variant="secondary" >Романтика</Button></li> <span className="text">Рекомендуемое</span>
<li><Button className="btn" variant="secondary" >Драма</Button></li> <div className="card-group rows images">
</ul> {
lines.map((el) => <CreateCard key={el.id} line={el}/>)
}
</div> </div>
</> </>
); );

View File

@ -1,58 +1,11 @@
import { useState } from 'react'; import { useParams } from 'react-router-dom';
import { Button, Form } from 'react-bootstrap'; import LinesForm from '../components/lines/form/LinesForm.jsx';
import { Link } from 'react-router-dom';
const Input = () => { const Input = () => {
const [validated, setValidated] = useState(false); const { id } = useParams();
const handleSubmit = (event) => {
const form = event.currentTarget;
if (form.checkValidity() === false) {
event.preventDefault();
event.stopPropagation();
}
setValidated(true);
};
return ( return (
<> <LinesForm id={id} />
<div className="text-center">
<img id="image-preview" src="https://via.placeholder.com/200" className="rounded rounded-circle"
alt="placeholder" style={{ maxWidth: '200px', maxHeight: '200px' }}/>
</div>
<Form id="items-form" noValidate validated={validated} onSubmit={handleSubmit}>
<Form.Group className="mb-2" controlId="Genre">
<Form.Label className="form-label" style={{ color: 'white' }}>Жанр</Form.Label>
<Form.Select id="Genre" className="form-select" name='selected' required>
</Form.Select>
</Form.Group>
<Form.Group className="mb-2" controlId="Title">
<Form.Label className="form-label" style={{ color: 'white' }}>Название продукта</Form.Label>
<Form.Control type="text" name="Title" className="form-control" required />
</Form.Group>
<Form.Group className="mb-2" controlId="Cast">
<Form.Label className="form-label" style={{ color: 'white' }}>Актерский состав</Form.Label>
<Form.Control type="text" name="Cast" className="form-control" required />
</Form.Group>
<Form.Group className="mb-2" controlId="Description">
<Form.Label className="form-label" style={{ color: 'white' }}>Описание</Form.Label>
<Form.Control type="text" name="Description" className="form-control" required />
</Form.Group>
<Form.Group className="mb-2" controlId="Image">
<Form.Label className="form-label" style={{ color: 'white' }}>Изображение</Form.Label>
<Form.Control type="file" name="Image" className="form-control" accept="image/*" />
</Form.Group>
<Form.Group className="mb-2" controlId="Video">
<Form.Label className="form-label" style={{ color: 'white' }}>Видеофайл</Form.Label>
<Form.Control type="file" name="Video" className="form-control" accept="video/*" />
</Form.Group>
<Form.Group className="d-flex flex-md-row flex-column justify-content-center">
<Button className="btn-mw me-md-3 mb-md-0 mb-2" as={Link} to="/Admin" style={{ height: '7%', fontSize: '16px' }} variant="secondary">Назад</Button>
<Button className="btn-mw me-md-3" type="submit" variant="primary">Сохранить</Button>
</Form.Group>
</Form>
</>
); );
}; };

View File

@ -1,37 +1,65 @@
import { useState } from 'react'; import { useState } from 'react';
import { useNavigate, Link } from 'react-router-dom';
import { Button, Form, FormGroup } from 'react-bootstrap'; import { Button, Form, FormGroup } from 'react-bootstrap';
import { Link } from 'react-router-dom';
import titleBlack from '../assets/Title_black.png'; import titleBlack from '../assets/Title_black.png';
import useJoinUser from '../components/user/UserJoinHook';
const Join = () => { const Join = () => {
const navigator = useNavigate();
const [validated, setValidated] = useState(false); const [validated, setValidated] = useState(false);
const [formData, setFormData] = useState({
login: '',
password: '',
});
const { user, handlerLoginChanged } = useJoinUser(formData.email);
const handleSubmit = (event) => { const handleSubmit = (event) => {
const form = event.currentTarget; const form = event.currentTarget;
if (form.checkValidity() === false) { event.preventDefault();
event.preventDefault(); event.stopPropagation();
event.stopPropagation(); if (form.checkValidity() !== false) {
console.log(formData);
}
if (user === null) {
return;
}
if (user.password === formData.password) {
const ind = user.id;
localStorage.setItem('EnabledUser', JSON.stringify(user.id));
navigator(`/LK/${ind}`);
} }
setValidated(true); setValidated(true);
}; };
const handleChange = (event) => {
const inputName = event.target.name;
const inputValue = event.target.type === 'checkbox' ? event.target.checked : event.target.value;
setFormData({
...formData,
[inputName]: inputValue,
});
if (inputName === 'login') {
handlerLoginChanged(inputValue);
}
};
return ( return (
<> <>
<Form className="Join" noValidate validated={validated} onSubmit={handleSubmit}> <Form className="Join" noValidate validated={validated} onSubmit={handleSubmit}>
<center><Button as={Link} to="/Index" style={{ backgroundColor: 'white', borderColor: 'white', marginTop: '20px' }}><img id="image_title" src={titleBlack} alt="название" className="Title"/></Button></center> <center><Button as={Link} to="/" style={{ backgroundColor: 'white', borderColor: 'white', marginTop: '20px' }}><img id="image_title" src={titleBlack} alt="название" className="Title"/></Button></center>
<FormGroup className="name" controlId="userName"> <FormGroup className="name">
<Form.Label className="form-label"></Form.Label> <Form.Label className="form-label"></Form.Label>
<Form.Control type="text" name="userName" className="form-control" placeholder="Логин / почта пользователя" required /> <Form.Control type="text" name="login" className="form-control" placeholder="Логин" value={formData.login} onChange={handleChange} required />
</FormGroup> </FormGroup>
<FormGroup className="pass" controlId="Password"> <FormGroup className="pass">
<Form.Label className="form-label"></Form.Label> <Form.Label className="form-label"></Form.Label>
<Form.Control type="password" name="Password" placeholder="Пароль" className="form-control" required /> <Form.Control type="password" name="password" placeholder="Пароль" className="form-control" value={formData.password} onChange={handleChange} required />
</FormGroup> </FormGroup>
<Button className="ButtonJoin" as={Link} to="/" type="submit">Войти</Button> <Button className="ButtonJoin" type="submit">Войти</Button>
</Form> </Form>
</> </>
); );
}; };
export default Join; export default Join;

View File

@ -1,24 +1,23 @@
import { Link } from 'react-router-dom'; import { useParams } from 'react-router-dom';
import icons from '../assets/icons8-загрузить-64.png'; import AdminButton from '../components/button/AdminButton.jsx';
import UserPhoto from '../components/UserPhoto.jsx';
import usePhoto from '../components/user/PhotoHook';
const LK = () => { const LK = () => {
const { id } = useParams();
const { item, handleChange } = usePhoto(id);
const onSubmit = async (event) => {
await handleChange(event);
};
return ( return (
<> <>
<div className="DobPhoto rows"> <div className="DobPhoto rows">
<form id="upload-container" className="upload-container" method="POST" action="send.php"> <UserPhoto item={ item } handleChange={ onSubmit } />
<img id="upload-image" src={icons} alt=''/>
<div>
<input id="file-input" type="file" name="file" style={{ fontSize: '10px' }} multiple/>
<label style={{ marginLeft: '10px' }}>Выберите файл</label>
<div style={{ paddingLeft: '10px' }}> или перетащите его <br/> сюда</div>
</div>
</form>
<div className="info"> <div className="info">
<div className="FIO">Иван Иванов</div> <div className="FIO">{ item.name }</div>
<div className="info_list-item" style={{ marginTop: '5%' }}>Дата рождения - 25.09.2018</div> <div className="info_list-item" style={{ marginTop: '5%' }}>Ваш логин: { item.login }</div>
<div className="info_list-item" style={{ marginTop: '5%' }}>Просмотрено фильмов - 123</div> <div className="info_list-item" style={{ marginTop: '5%', marginBottom: '5%' }}>Ваша почта: { item.mail }</div>
<div className="info_list-item" style={{ marginTop: '5%', marginBottom: '5%' }}>Просмотрено сериалов - 123</div> <AdminButton></AdminButton>
<button className="btn btn-outline-warning button_add"><Link className="nav-link" to="/Admin" style={{ textDecoration: 'none' }}>Панель администратора</Link></button>
</div> </div>
</div> </div>
</> </>

View File

@ -1,11 +1,14 @@
import sobaka from '../../media/sobaka-letit_(VIDEOMIN.NET).mp4'; import { useParams } from 'react-router-dom';
import useLinesItemForm from '../components/lines/hooks/LinesItemFormHook';
const Media = () => { const Media = () => {
const { id } = useParams();
const { item } = useLinesItemForm(id);
return ( return (
<> <>
<main className="h-100 d-flex flex-column" style={{ backgroundColor: '#03001F' }}> <main className="h-100 d-flex flex-column" style={{ backgroundColor: '#03001F' }}>
<div className='video-container'> <div className='video-container'>
<video controls src={sobaka} className='video-player' id='video-player' preload='metadata'></video> <video controls src={ item.video } className='video-player' id='video-player' preload='metadata'></video>
</div> </div>
</main> </main>
</> </>

View File

@ -1,42 +1,29 @@
import { useState } from 'react'; import { Button, Form } from 'react-bootstrap';
import { Button, Form, FormGroup } from 'react-bootstrap'; import { useNavigate, useParams } from 'react-router-dom';
import { Link } from 'react-router-dom'; import useLinesUserForm from '../components/lines/hooks/LinesUserFormHook';
import titleBlack from '../assets/Title_black.png'; import FormRegister from '../components/lines/register/FormReg.jsx';
const Register = () => { const Register = () => {
const [validated, setValidated] = useState(false); const { id } = useParams();
const navigate = useNavigate();
const {
item,
validated,
handleSubmit,
handleChange,
} = useLinesUserForm(id);
const handleSubmit = (event) => { const onSubmit = async (event) => {
const form = event.currentTarget; if (await handleSubmit(event)) {
if (form.checkValidity() === false) { navigate(-1);
event.preventDefault();
event.stopPropagation();
} }
setValidated(true);
}; };
return ( return (
<> <>
<Form className="Join" noValidate validated={validated} onSubmit={handleSubmit}> <Form className="Join" noValidate validated={validated} onSubmit={onSubmit}>
<center><Button as={Link} to="/Index" style={{ backgroundColor: 'white', borderColor: 'white' }}><img id="image_title" src={titleBlack} alt="название" className="Title"/></Button></center> <FormRegister item = {item} handleChange={handleChange}></FormRegister>
<FormGroup className="reg_name" controlId="userName"> <Button className="reg_ButtonJoin" type="submit">Регистрация</Button>
<Form.Label className="form-label"></Form.Label>
<Form.Control type="text" name="userName" className="form-control" placeholder="Имя" required />
</FormGroup>
<FormGroup className="reg_login" controlId="Login">
<Form.Label className="form-label"></Form.Label>
<Form.Control type="text" name="Login" className="form-control" placeholder="Логин" required />
</FormGroup>
<FormGroup className="reg_mail" controlId="Mail">
<Form.Label className="form-label"></Form.Label>
<Form.Control type="email" name="Mail" className="form-control" placeholder="Почта пользователя" required />
</FormGroup>
<FormGroup className="reg_pass" controlId="regPassword">
<Form.Label className="form-label"></Form.Label>
<Form.Control type="password" name="regPassword" className="form-control" placeholder="Пароль" required />
</FormGroup>
<Button className="reg_ButtonJoin" as={Link} to="/" type="submit">Регистрация</Button>
</Form> </Form>
</> </>
); );

34
src/pages/Search.jsx Normal file
View File

@ -0,0 +1,34 @@
import { useNavigate } from 'react-router-dom';
import SearchMovies from '../components/search/SearchMovie';
import CreateCard from '../components/Card/Cards.jsx';
const Search = () => {
const { files } = SearchMovies();
const navigate = useNavigate();
const RedirectSearch = (event) => {
event.preventDefault();
const searchText = document.getElementById('search').value;
navigate(`/search?find=${encodeURIComponent(searchText)}`);
};
return (
<>
<center><div style={{ marginTop: '20px', marginBottom: '20px' }}>
<input type="search" id="search" style={{
borderRadius: '15px', borderColor: '#0dcaf0', backgroundColor: '#03001F', marginLeft: '20px', color: 'white',
}} placeholder="Поиск" aria-label="Search" />
<button onClick={RedirectSearch} className="btn" style={{ borderColor: '#0dcaf0', borderRadius: '50px', marginTop: '-3px' }} type="submit" >
<svg xmlns="http://www.w3.org/2000/svg" width="15" height="15" fill="currentColor" className="bi bi-search" viewBox="0 0 16 16">
<path d="M11.742 10.344a6.5 6.5 0 1 0-1.397 1.398h-.001q.044.06.098.115l3.85 3.85a1 1 0 0 0 1.415-1.414l-3.85-3.85a1 1 0 0 0-.115-.1zM12 6.5a5.5 5.5 0 1 1-11 0 5.5 5.5 0 0 1 11 0"/>
</svg>
</button>
</div></center>
<div className="card-group rows images">
{
files.map((el) => <CreateCard key={el.id} line={el}/>)
}
</div>
</>
);
};
export default Search;