Lab5 thinks done
This commit is contained in:
parent
f1f2120b97
commit
c5a6b732e3
159
db-1703437805205.json
Normal file
159
db-1703437805205.json
Normal file
File diff suppressed because one or more lines are too long
159
db-1703437814950.json
Normal file
159
db-1703437814950.json
Normal file
File diff suppressed because one or more lines are too long
667
package-lock.json
generated
667
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
29
package.json
29
package.json
@ -1,33 +1,38 @@
|
|||||||
{
|
{
|
||||||
"name": "internet-programming-pibd-23-tikhonenkov-alexey-ulstu",
|
"name": "lec4",
|
||||||
"private": true,
|
"private": true,
|
||||||
"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 --port 8081",
|
||||||
|
"vite": "vite",
|
||||||
|
"dev": "npm-run-all --parallel rest vite",
|
||||||
|
"prod": "npm-run-all lint 'vite build' --parallel rest 'vite preview'"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"bootstrap": "^5.3.2",
|
|
||||||
"json-server": "^0.17.4",
|
|
||||||
"prop-types": "^15.8.1",
|
|
||||||
"react": "^18.2.0",
|
"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": "^2.9.1",
|
||||||
"react-bootstrap-icons": "^1.10.3",
|
"react-bootstrap-icons": "^1.10.3",
|
||||||
"react-dom": "^18.2.0",
|
"prop-types": "^15.8.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",
|
||||||
"vite": "^4.5.1"
|
"json-server": "^0.17.4",
|
||||||
|
"npm-run-all": "^4.1.5",
|
||||||
|
"vite": "^4.4.5"
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,21 +1,21 @@
|
|||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
|
|
||||||
const MovieCard = ({ title, description, imageUrl }) => {
|
const MovieCard = ({ name, rating, image }) => {
|
||||||
return (
|
return (
|
||||||
<div className="movie-card">
|
<div className="movie-card">
|
||||||
<img src={imageUrl || "https://via.placeholder.com/300x400"} alt="Movie Image" />
|
<img src={image || "https://via.placeholder.com/300x400"} alt="Movie Image" />
|
||||||
<div className="movie-card-content">
|
<div className="movie-card-content">
|
||||||
<h2>{title}</h2>
|
<h2>{name}</h2>
|
||||||
<p>{description}</p>
|
<p>Рейтинг: {rating}</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
MovieCard.propTypes = {
|
MovieCard.propTypes = {
|
||||||
title: PropTypes.string.isRequired,
|
name: PropTypes.string.isRequired,
|
||||||
description: PropTypes.string.isRequired,
|
rating: PropTypes.string.isRequired,
|
||||||
imageUrl: PropTypes.string,
|
image: PropTypes.string,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default MovieCard;
|
export default MovieCard;
|
||||||
|
25
src/Moviecard/MovieList.jsx
Normal file
25
src/Moviecard/MovieList.jsx
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
// MovieList.jsx
|
||||||
|
|
||||||
|
import MovieCard from './MovieCard.jsx';
|
||||||
|
import useLines from '../components/lines/hooks/LinesHook.js';
|
||||||
|
|
||||||
|
const MovieList = () => {
|
||||||
|
// Вызовите useLines без фильтра, чтобы получить все фильмы
|
||||||
|
const { lines } = useLines();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
|
||||||
|
{lines.map((movieData) => (
|
||||||
|
<MovieCard key={movieData.id} {...movieData} />
|
||||||
|
))}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default MovieList;
|
33
src/Moviecard/useMovieFilter.jsx
Normal file
33
src/Moviecard/useMovieFilter.jsx
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
import MovieCard from './MovieCard.jsx';
|
||||||
|
import useTypes from '../components/types/hooks/TypesHook.js';
|
||||||
|
import useLines from '../components/lines/hooks/LinesHook.js';
|
||||||
|
|
||||||
|
const useMovieFilter = () => {
|
||||||
|
const { types } = useTypes();
|
||||||
|
const { lines } = useLines();
|
||||||
|
|
||||||
|
console.log("All lines:", lines);
|
||||||
|
|
||||||
|
const filterMoviesByType = (typeId) => {
|
||||||
|
const filteredMovies = lines.filter((line) => line.typeId === typeId);
|
||||||
|
console.log(`Type ID: ${typeId}, Filtered Movies:`, filteredMovies);
|
||||||
|
return filteredMovies;
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
{types.map((type) => (
|
||||||
|
<div className="movie-container" key={type.id}>
|
||||||
|
<h1>{type.name}</h1>
|
||||||
|
{filterMoviesByType(type.id.toString()).map((filteredMovie) => (
|
||||||
|
<MovieCard key={filteredMovie.id} {...filteredMovie} />
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
export default useMovieFilter;
|
BIN
src/assets/300x400.png
Normal file
BIN
src/assets/300x400.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.0 KiB |
40
src/components/api/ApiClient.js
Normal file
40
src/components/api/ApiClient.js
Normal 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:8081/',
|
||||||
|
timeout: '3000',
|
||||||
|
headers: {
|
||||||
|
Accept: 'application/json',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
ApiClient.interceptors.response.use(responseHandler, responseErrorHandler);
|
29
src/components/api/ApiService.js
Normal file
29
src/components/api/ApiService.js
Normal 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;
|
26
src/components/input/Input.jsx
Normal file
26
src/components/input/Input.jsx
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
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>{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,
|
||||||
|
type: PropTypes.string,
|
||||||
|
className: PropTypes.string,
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
export default Input;
|
29
src/components/input/Select.jsx
Normal file
29
src/components/input/Select.jsx
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
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'>{label}</Form.Label>
|
||||||
|
<Form.Select name={name || ''} value={value || ''} onChange={onChange} {...rest}>
|
||||||
|
<option value=''>Выберите значение</option>
|
||||||
|
{
|
||||||
|
values.map((type) => <option key={type.id} value={type.id}>{type.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;
|
48
src/components/lines/form/LinesForm.jsx
Normal file
48
src/components/lines/form/LinesForm.jsx
Normal 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='col-5 col-lg-2 m-0 me-2' variant='secondary' onClick={() => onBack()}>
|
||||||
|
Назад
|
||||||
|
</Button>
|
||||||
|
<Button className='col-5 col-lg-2 m-0 ms-2' type='submit' variant='primary'>
|
||||||
|
Сохранить
|
||||||
|
</Button>
|
||||||
|
</Form.Group>
|
||||||
|
</Form>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
LinesForm.propTypes = {
|
||||||
|
id: PropTypes.string,
|
||||||
|
};
|
||||||
|
|
||||||
|
export default LinesForm;
|
3
src/components/lines/form/LinesItemForm.css
Normal file
3
src/components/lines/form/LinesItemForm.css
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
#image-preview {
|
||||||
|
width: 200px;
|
||||||
|
}
|
40
src/components/lines/form/LinesItemForm.jsx
Normal file
40
src/components/lines/form/LinesItemForm.jsx
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
import PropTypes from 'prop-types';
|
||||||
|
import imgPlaceholder from '../../../assets/300x400.png';
|
||||||
|
import Input from '../../input/Input.jsx';
|
||||||
|
import Select from '../../input/Select.jsx';
|
||||||
|
import useTypes from '../../types/hooks/TypesHook';
|
||||||
|
import './LinesItemForm.css';
|
||||||
|
|
||||||
|
const LinesItemForm = ({ item, handleChange }) => {
|
||||||
|
const { types } = useTypes();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<div className='text-center'>
|
||||||
|
<img id='image-preview' className='rounded' alt='placeholder'
|
||||||
|
src={item.image || imgPlaceholder} />
|
||||||
|
</div>
|
||||||
|
<Select values={types} name='typeId' label='Жанр' value={item.typeId} onChange={handleChange}
|
||||||
|
required />
|
||||||
|
<Input name='name' label='Название фильма' value={item.name} onChange={handleChange}
|
||||||
|
type='text' required />
|
||||||
|
<Input name='rating' label='Рейтинг' value={item.rating} onChange={handleChange}
|
||||||
|
type='number' min="0" max="10" required />
|
||||||
|
<Input name='release_date' label='Дата производства' value={item.release_date} onChange={handleChange}
|
||||||
|
type='date' required />
|
||||||
|
|
||||||
|
<Input name='director' label='Режиссер' value={item.director} onChange={handleChange}
|
||||||
|
type='text' required />
|
||||||
|
<Input name='image' label='Изображение' onChange={handleChange}
|
||||||
|
type='file' accept='image/*' />
|
||||||
|
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
LinesItemForm.propTypes = {
|
||||||
|
item: PropTypes.object,
|
||||||
|
handleChange: PropTypes.func,
|
||||||
|
};
|
||||||
|
|
||||||
|
export default LinesItemForm;
|
34
src/components/lines/hooks/LinesDeleteModalHook.js
Normal file
34
src/components/lines/hooks/LinesDeleteModalHook.js
Normal 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;
|
28
src/components/lines/hooks/LinesFilterHook.js
Normal file
28
src/components/lines/hooks/LinesFilterHook.js
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
import { useSearchParams } from 'react-router-dom';
|
||||||
|
import useTypes from '../../types/hooks/TypesHook';
|
||||||
|
|
||||||
|
const useTypeFilter = () => {
|
||||||
|
const filterName = 'type';
|
||||||
|
|
||||||
|
const [searchParams, setSearchParams] = useSearchParams();
|
||||||
|
|
||||||
|
const { types } = useTypes();
|
||||||
|
|
||||||
|
const handleFilterChange = (event) => {
|
||||||
|
const type = event.target.value;
|
||||||
|
if (type) {
|
||||||
|
searchParams.set(filterName, event.target.value);
|
||||||
|
} else {
|
||||||
|
searchParams.delete(filterName);
|
||||||
|
}
|
||||||
|
setSearchParams(searchParams);
|
||||||
|
};
|
||||||
|
|
||||||
|
return {
|
||||||
|
types,
|
||||||
|
currentFilter: searchParams.get(filterName) || '',
|
||||||
|
handleFilterChange,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
export default useTypeFilter;
|
45
src/components/lines/hooks/LinesFormModalHook.js
Normal file
45
src/components/lines/hooks/LinesFormModalHook.js
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
import { useState } from 'react';
|
||||||
|
import useModal from '../../modal/ModalHook';
|
||||||
|
import useLinesItemForm from './LinesItemFormHook';
|
||||||
|
|
||||||
|
const useLinesFormModal = (linesChangeHandle) => {
|
||||||
|
const { isModalShow, showModal, hideModal } = useModal();
|
||||||
|
const [currentId, setCurrentId] = useState(0);
|
||||||
|
|
||||||
|
const {
|
||||||
|
item,
|
||||||
|
validated,
|
||||||
|
handleSubmit,
|
||||||
|
handleChange,
|
||||||
|
resetValidity,
|
||||||
|
} = useLinesItemForm(currentId, linesChangeHandle);
|
||||||
|
|
||||||
|
const showModalDialog = (id) => {
|
||||||
|
setCurrentId(id);
|
||||||
|
resetValidity();
|
||||||
|
showModal();
|
||||||
|
};
|
||||||
|
|
||||||
|
const onClose = () => {
|
||||||
|
setCurrentId(-1);
|
||||||
|
hideModal();
|
||||||
|
};
|
||||||
|
|
||||||
|
const onSubmit = async (event) => {
|
||||||
|
if (await handleSubmit(event)) {
|
||||||
|
onClose();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return {
|
||||||
|
isFormModalShow: isModalShow,
|
||||||
|
isFormValidated: validated,
|
||||||
|
showFormModal: showModalDialog,
|
||||||
|
currentItem: item,
|
||||||
|
handleItemChange: handleChange,
|
||||||
|
handleFormSubmit: onSubmit,
|
||||||
|
handleFormClose: onClose,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
export default useLinesFormModal;
|
29
src/components/lines/hooks/LinesHook.js
Normal file
29
src/components/lines/hooks/LinesHook.js
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
import { useEffect, useState } from 'react';
|
||||||
|
import LinesApiService from '../service/LinesApiService';
|
||||||
|
|
||||||
|
const useLines = (typeFilter) => {
|
||||||
|
const [linesRefresh, setLinesRefresh] = useState(false);
|
||||||
|
const [lines, setLines] = useState([]);
|
||||||
|
const handleLinesChange = () => setLinesRefresh(!linesRefresh);
|
||||||
|
|
||||||
|
const getLines = async () => {
|
||||||
|
let expand = '?_expand=type';
|
||||||
|
if (typeFilter) {
|
||||||
|
expand = `${expand}&typeId=${typeFilter}`;
|
||||||
|
}
|
||||||
|
const data = await LinesApiService.getAll(expand);
|
||||||
|
setLines(data ?? []);
|
||||||
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
getLines();
|
||||||
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
|
}, [linesRefresh, typeFilter]);
|
||||||
|
|
||||||
|
return {
|
||||||
|
lines,
|
||||||
|
handleLinesChange,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
export default useLines;
|
91
src/components/lines/hooks/LinesItemFormHook.js
Normal file
91
src/components/lines/hooks/LinesItemFormHook.js
Normal file
@ -0,0 +1,91 @@
|
|||||||
|
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 typeId = formData.typeId;
|
||||||
|
const name = formData.name;
|
||||||
|
const rating = formData.rating;
|
||||||
|
const release_date = formData.release_date;
|
||||||
|
const director = formData.director;
|
||||||
|
const image = formData.image.startsWith('data:image') ? formData.image : '';
|
||||||
|
return {
|
||||||
|
typeId: typeId,
|
||||||
|
name: name,
|
||||||
|
rating: rating,
|
||||||
|
release_date: release_date,
|
||||||
|
director: director,
|
||||||
|
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;
|
||||||
|
let inputValue = event.target.type === 'checkbox' ? event.target.checked : event.target.value;
|
||||||
|
console.log(inputName, inputValue);
|
||||||
|
|
||||||
|
|
||||||
|
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;
|
36
src/components/lines/hooks/LinesItemHook.js
Normal file
36
src/components/lines/hooks/LinesItemHook.js
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
import { useEffect, useState } from 'react';
|
||||||
|
import LinesApiService from '../service/LinesApiService';
|
||||||
|
|
||||||
|
const useLinesItem = (id) => {
|
||||||
|
const emptyItem = {
|
||||||
|
itemsId: "",
|
||||||
|
name: '',
|
||||||
|
rating: '',
|
||||||
|
release_date: '',
|
||||||
|
director: '',
|
||||||
|
image: '',
|
||||||
|
id: '',
|
||||||
|
};
|
||||||
|
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;
|
5
src/components/lines/service/LinesApiService.js
Normal file
5
src/components/lines/service/LinesApiService.js
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
import ApiService from '../../api/ApiService';
|
||||||
|
|
||||||
|
const LinesApiService = new ApiService('lines');
|
||||||
|
|
||||||
|
export default LinesApiService;
|
72
src/components/lines/table/Lines.jsx
Normal file
72
src/components/lines/table/Lines.jsx
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
import { Button } from 'react-bootstrap';
|
||||||
|
import { Link, useNavigate } from 'react-router-dom';
|
||||||
|
import Select from '../../input/Select.jsx';
|
||||||
|
import ModalConfirm from '../../modal/ModalConfirm.jsx';
|
||||||
|
import ModalForm from '../../modal/ModalForm.jsx';
|
||||||
|
import LinesItemForm from '../form/LinesItemForm.jsx';
|
||||||
|
import useLinesDeleteModal from '../hooks/LinesDeleteModalHook';
|
||||||
|
import useTypeFilter from '../hooks/LinesFilterHook';
|
||||||
|
import useLinesFormModal from '../hooks/LinesFormModalHook';
|
||||||
|
import useLines from '../hooks/LinesHook';
|
||||||
|
import LinesTable from './LinesTable.jsx';
|
||||||
|
import LinesTableRow from './LinesTableRow.jsx';
|
||||||
|
|
||||||
|
const Lines = () => {
|
||||||
|
const { types, currentFilter, handleFilterChange } = useTypeFilter();
|
||||||
|
|
||||||
|
const { lines, handleLinesChange } = useLines(currentFilter);
|
||||||
|
|
||||||
|
const {
|
||||||
|
isDeleteModalShow,
|
||||||
|
showDeleteModal,
|
||||||
|
handleDeleteConfirm,
|
||||||
|
handleDeleteCancel,
|
||||||
|
} = useLinesDeleteModal(handleLinesChange);
|
||||||
|
|
||||||
|
const {
|
||||||
|
isFormModalShow,
|
||||||
|
isFormValidated,
|
||||||
|
showFormModal,
|
||||||
|
currentItem,
|
||||||
|
handleItemChange,
|
||||||
|
handleFormSubmit,
|
||||||
|
handleFormClose,
|
||||||
|
} = useLinesFormModal(handleLinesChange);
|
||||||
|
|
||||||
|
const navigate = useNavigate();
|
||||||
|
|
||||||
|
const showEditPage = (id) => {
|
||||||
|
navigate(`/page-edit/${id}`);
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Button as={Link} to='/page-edit' variant='success'>
|
||||||
|
Добавить фильм
|
||||||
|
</Button>
|
||||||
|
<Select className='mt-2' values={types} label='Фильтр по жанрам'
|
||||||
|
value={currentFilter} onChange={handleFilterChange} />
|
||||||
|
<LinesTable>
|
||||||
|
{
|
||||||
|
lines.map((line, index) =>
|
||||||
|
<LinesTableRow key={line.id}
|
||||||
|
index={index} line={line}
|
||||||
|
onDelete={() => showDeleteModal(line.id)}
|
||||||
|
onEdit={() => showFormModal(line.id)}
|
||||||
|
onEditInPage={() => showEditPage(line.id)}
|
||||||
|
/>)
|
||||||
|
}
|
||||||
|
</LinesTable>
|
||||||
|
<ModalConfirm show={isDeleteModalShow}
|
||||||
|
onConfirm={handleDeleteConfirm} onClose={handleDeleteCancel}
|
||||||
|
title='Удаление' message='Удалить элемент?' />
|
||||||
|
<ModalForm show={isFormModalShow} validated={isFormValidated}
|
||||||
|
onSubmit={handleFormSubmit} onClose={handleFormClose}
|
||||||
|
title='Редактирование'>
|
||||||
|
<LinesItemForm item={currentItem} handleChange={handleItemChange} />
|
||||||
|
</ModalForm>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default Lines;
|
30
src/components/lines/table/LinesTable.jsx
Normal file
30
src/components/lines/table/LinesTable.jsx
Normal 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>
|
||||||
|
<tr>
|
||||||
|
<th scope="col">№</th>
|
||||||
|
<th scope="col" className="w-25">Фильм</th>
|
||||||
|
<th scope="col" className="w-25">Жанр</th>
|
||||||
|
<th scope="col" className="w-15">Рейтинг</th>
|
||||||
|
<th scope="col" className="w-25">Дата производства</th>
|
||||||
|
<th scope="col" className="w-25">Режиссер</th>
|
||||||
|
<th scope="col"></th>
|
||||||
|
<th scope="col"></th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{children}
|
||||||
|
</tbody >
|
||||||
|
</Table >
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
LinesTable.propTypes = {
|
||||||
|
children: PropTypes.node,
|
||||||
|
};
|
||||||
|
|
||||||
|
export default LinesTable;
|
36
src/components/lines/table/LinesTableRow.jsx
Normal file
36
src/components/lines/table/LinesTableRow.jsx
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
import PropTypes from 'prop-types';
|
||||||
|
import { PencilFill, PencilSquare, Trash3 } from 'react-bootstrap-icons';
|
||||||
|
|
||||||
|
const LinesTableRow = ({
|
||||||
|
index, line, onDelete, onEdit, onEditInPage,
|
||||||
|
}) => {
|
||||||
|
const handleAnchorClick = (event, action) => {
|
||||||
|
event.preventDefault();
|
||||||
|
action();
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<tr>
|
||||||
|
<th scope="row">{index + 1}</th>
|
||||||
|
<td>{line.name}</td>
|
||||||
|
<td>{line.type.name}</td>
|
||||||
|
<td>{parseInt(line.rating)}</td>
|
||||||
|
<td>{line.release_date}</td>
|
||||||
|
<td>{line.director}</td>
|
||||||
|
|
||||||
|
<td><a href="#" onClick={(event) => handleAnchorClick(event, onEdit)}><PencilFill /></a></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;
|
3
src/components/modal/Modal.css
Normal file
3
src/components/modal/Modal.css
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
.modal-title {
|
||||||
|
font-size: 1.2rem;
|
||||||
|
}
|
42
src/components/modal/ModalConfirm.jsx
Normal file
42
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
src/components/modal/ModalForm.jsx
Normal file
43
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
src/components/modal/ModalHook.js
Normal file
21
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;
|
21
src/components/types/hooks/TypesHook.js
Normal file
21
src/components/types/hooks/TypesHook.js
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
import { useEffect, useState } from 'react';
|
||||||
|
import TypesApiService from '../service/TypesApiService';
|
||||||
|
|
||||||
|
const useTypes = () => {
|
||||||
|
const [types, setTypes] = useState([]);
|
||||||
|
|
||||||
|
const getTypes = async () => {
|
||||||
|
const data = await TypesApiService.getAll();
|
||||||
|
setTypes(data ?? []);
|
||||||
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
getTypes();
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
return {
|
||||||
|
types,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
export default useTypes;
|
5
src/components/types/service/TypesApiService.js
Normal file
5
src/components/types/service/TypesApiService.js
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
import ApiService from '../../api/ApiService';
|
||||||
|
|
||||||
|
const TypesApiService = new ApiService('types');
|
||||||
|
|
||||||
|
export default TypesApiService;
|
15
src/components/utils/Base64.js
Normal file
15
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,7 +45,7 @@ const routes = [
|
|||||||
element: <AdminPage />,
|
element: <AdminPage />,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: '/page-edit',
|
path: '/page-edit/:id?',
|
||||||
element: <PageEdit />,
|
element: <PageEdit />,
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
@ -1,32 +1,10 @@
|
|||||||
import { Button, ButtonGroup, Table } from 'react-bootstrap';
|
|
||||||
import { Link } from 'react-router-dom';
|
|
||||||
|
|
||||||
|
import Lines from '../components/lines/table/Lines.jsx';
|
||||||
const AdminPage = () => {
|
const AdminPage = () => {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<h1 className="text-Gray text-center font-weight-bold">Панель администратора</h1>
|
|
||||||
<div className="d-flex justify-content-center">
|
<Lines />
|
||||||
<ButtonGroup>
|
|
||||||
<Button as={Link} to="/page-edit" variant="secondary">Добавить фильм</Button>
|
|
||||||
</ButtonGroup>
|
|
||||||
</div>
|
|
||||||
<h2 className="text-Gray text-center font-weight-bold">Таблица данных</h2>
|
|
||||||
<Table className="mt-2" striped>
|
|
||||||
|
|
||||||
<thead>
|
|
||||||
<tr>
|
|
||||||
<th scope="col">№</th>
|
|
||||||
<th scope="col" className="w-25">Фильм</th>
|
|
||||||
<th scope="col" className="w-25">Жанр</th>
|
|
||||||
<th scope="col" className="w-15">Рейтинг</th>
|
|
||||||
<th scope="col" className="w-25">Дата производства</th>
|
|
||||||
<th scope="col" className="w-25">Режиссер</th>
|
|
||||||
<th scope="col"></th>
|
|
||||||
<th scope="col"></th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody></tbody>
|
|
||||||
</Table>
|
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@ -1,59 +1,26 @@
|
|||||||
import MovieCard from '../Moviecard/MovieCard';
|
import MovieList from '../Moviecard/MovieList.jsx';
|
||||||
import Banner from '../components/banner/Banner.jsx';
|
import Banner from '../components/banner/Banner.jsx';
|
||||||
|
|
||||||
const MainPage = () => {
|
const MainPage = () => {
|
||||||
const movieData = {
|
|
||||||
title: 'Название фильма 1',
|
|
||||||
description: 'Описание фильма 1.',
|
|
||||||
imageUrl: 'https://via.placeholder.com/300x400',
|
|
||||||
};
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Banner />
|
<Banner />
|
||||||
<>
|
<h1>Популярное</h1>
|
||||||
<div className="movie-container">
|
<div className="movie-container">
|
||||||
<h1>Наиболее Популярное</h1>
|
<MovieList />
|
||||||
<MovieCard {...movieData} />
|
</div>
|
||||||
<MovieCard {...movieData} />
|
<h1>Может быть интересно</h1>
|
||||||
<MovieCard {...movieData} />
|
<div className="movie-container">
|
||||||
<MovieCard {...movieData} />
|
<MovieList />
|
||||||
<MovieCard {...movieData} />
|
|
||||||
<MovieCard {...movieData} />
|
|
||||||
<MovieCard {...movieData} />
|
|
||||||
<MovieCard {...movieData} />
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<h1>Лучшие отзывы</h1>
|
||||||
<div className="movie-container">
|
<div className="movie-container">
|
||||||
<h1>Может быть интересно</h1>
|
<MovieList />
|
||||||
<MovieCard {...movieData} />
|
|
||||||
<MovieCard {...movieData} />
|
|
||||||
<MovieCard {...movieData} />
|
|
||||||
<MovieCard {...movieData} />
|
|
||||||
<MovieCard {...movieData} />
|
|
||||||
<MovieCard {...movieData} />
|
|
||||||
<MovieCard {...movieData} />
|
|
||||||
<MovieCard {...movieData} />
|
|
||||||
<MovieCard {...movieData} />
|
|
||||||
<MovieCard {...movieData} />
|
|
||||||
<MovieCard {...movieData} />
|
|
||||||
<MovieCard {...movieData} />
|
|
||||||
</div>
|
</div>
|
||||||
<div className="movie-container">
|
|
||||||
<h1>Лучшие отзывы</h1>
|
|
||||||
<MovieCard {...movieData} />
|
|
||||||
<MovieCard {...movieData} />
|
|
||||||
<MovieCard {...movieData} />
|
|
||||||
<MovieCard {...movieData} />
|
|
||||||
<MovieCard {...movieData} />
|
|
||||||
<MovieCard {...movieData} />
|
|
||||||
<MovieCard {...movieData} />
|
|
||||||
<MovieCard {...movieData} />
|
|
||||||
<MovieCard {...movieData} />
|
|
||||||
<MovieCard {...movieData} />
|
|
||||||
<MovieCard {...movieData} />
|
|
||||||
<MovieCard {...movieData} />
|
|
||||||
</div>
|
|
||||||
</>
|
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@ -1,36 +1,13 @@
|
|||||||
import MovieCard from '../Moviecard/MovieCard';
|
import MovieList from '../Moviecard/MovieList.jsx';
|
||||||
|
|
||||||
const Page1 = () => {
|
const Page1 = () => {
|
||||||
const movieData = {
|
|
||||||
title: 'Название фильма 1',
|
|
||||||
description: 'Описание фильма 1.',
|
|
||||||
imageUrl: 'https://via.placeholder.com/300x400',
|
|
||||||
};
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<h1>Каталог</h1>
|
<h1>Каталог</h1>
|
||||||
|
|
||||||
<div id="movie-container">
|
<div id="movie-container">
|
||||||
<MovieCard {...movieData} />
|
<MovieList />
|
||||||
<MovieCard {...movieData} />
|
|
||||||
<MovieCard {...movieData} />
|
|
||||||
<MovieCard {...movieData} />
|
|
||||||
<MovieCard {...movieData} />
|
|
||||||
<MovieCard {...movieData} />
|
|
||||||
<MovieCard {...movieData} />
|
|
||||||
<MovieCard {...movieData} />
|
|
||||||
<MovieCard {...movieData} />
|
|
||||||
<MovieCard {...movieData} />
|
|
||||||
<MovieCard {...movieData} />
|
|
||||||
<MovieCard {...movieData} />
|
|
||||||
<MovieCard {...movieData} />
|
|
||||||
<MovieCard {...movieData} />
|
|
||||||
<MovieCard {...movieData} />
|
|
||||||
<MovieCard {...movieData} />
|
|
||||||
<MovieCard {...movieData} />
|
|
||||||
<MovieCard {...movieData} />
|
|
||||||
<MovieCard {...movieData} />
|
|
||||||
<MovieCard {...movieData} />
|
|
||||||
</div>
|
</div>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
@ -1,83 +1,16 @@
|
|||||||
import MovieCard from '../Moviecard/MovieCard';
|
import MovieList from '../Moviecard/useMovieFilter.jsx';
|
||||||
|
|
||||||
const Page2 = () => {
|
const Page1 = () => {
|
||||||
const movieData = {
|
|
||||||
title: 'Название фильма 1',
|
|
||||||
description: 'Описание фильма 1.',
|
|
||||||
imageUrl: 'https://via.placeholder.com/300x400',
|
|
||||||
};
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<div className="movie-container">
|
<h1>Категории</h1>
|
||||||
<h1>Фантастика</h1>
|
|
||||||
<MovieCard {...movieData} />
|
<div id="movie-container">
|
||||||
<MovieCard {...movieData} />
|
<MovieList />
|
||||||
<MovieCard {...movieData} />
|
|
||||||
<MovieCard {...movieData} />
|
|
||||||
<MovieCard {...movieData} />
|
|
||||||
<MovieCard {...movieData} />
|
|
||||||
<MovieCard {...movieData} />
|
|
||||||
<MovieCard {...movieData} />
|
|
||||||
<MovieCard {...movieData} />
|
|
||||||
<MovieCard {...movieData} />
|
|
||||||
</div>
|
</div>
|
||||||
|
</>
|
||||||
<div className="movie-container">
|
|
||||||
<h1>Фэнтези</h1>
|
|
||||||
<MovieCard {...movieData} />
|
|
||||||
<MovieCard {...movieData} />
|
|
||||||
<MovieCard {...movieData} />
|
|
||||||
<MovieCard {...movieData} />
|
|
||||||
<MovieCard {...movieData} />
|
|
||||||
|
|
||||||
</div>
|
|
||||||
<div className="movie-container">
|
|
||||||
<h1>Романтика</h1>
|
|
||||||
<MovieCard {...movieData} />
|
|
||||||
<MovieCard {...movieData} />
|
|
||||||
<MovieCard {...movieData} />
|
|
||||||
<MovieCard {...movieData} />
|
|
||||||
<MovieCard {...movieData} />
|
|
||||||
<MovieCard {...movieData} />
|
|
||||||
</div>
|
|
||||||
<div className="movie-container">
|
|
||||||
<h1>Экшн</h1>
|
|
||||||
<MovieCard {...movieData} />
|
|
||||||
<MovieCard {...movieData} />
|
|
||||||
<MovieCard {...movieData} />
|
|
||||||
<MovieCard {...movieData} />
|
|
||||||
<MovieCard {...movieData} />
|
|
||||||
<MovieCard {...movieData} />
|
|
||||||
</div>
|
|
||||||
<div className="movie-container">
|
|
||||||
<h1>Драма</h1>
|
|
||||||
<MovieCard {...movieData} />
|
|
||||||
<MovieCard {...movieData} />
|
|
||||||
<MovieCard {...movieData} />
|
|
||||||
<MovieCard {...movieData} />
|
|
||||||
<MovieCard {...movieData} />
|
|
||||||
<MovieCard {...movieData} />
|
|
||||||
</div>
|
|
||||||
<div className="movie-container">
|
|
||||||
<h1>Боевик</h1>
|
|
||||||
<MovieCard {...movieData} />
|
|
||||||
<MovieCard {...movieData} />
|
|
||||||
<MovieCard {...movieData} />
|
|
||||||
<MovieCard {...movieData} />
|
|
||||||
<MovieCard {...movieData} />
|
|
||||||
<MovieCard {...movieData} />
|
|
||||||
</div>
|
|
||||||
<div className="movie-container">
|
|
||||||
<h1>Научная фантастика</h1>
|
|
||||||
<MovieCard {...movieData} />
|
|
||||||
<MovieCard {...movieData} />
|
|
||||||
<MovieCard {...movieData} />
|
|
||||||
<MovieCard {...movieData} />
|
|
||||||
<MovieCard {...movieData} />
|
|
||||||
<MovieCard {...movieData} />
|
|
||||||
</div>
|
|
||||||
</>
|
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default Page2;
|
export default Page1;
|
||||||
|
@ -1,33 +1,12 @@
|
|||||||
import MovieCard from '../Moviecard/MovieCard';
|
import MovieList from '../Moviecard/MovieList.jsx';
|
||||||
|
|
||||||
const Page4 = () => {
|
const Page4 = () => {
|
||||||
const movieData = {
|
|
||||||
title: 'Название фильма 1',
|
|
||||||
description: 'Описание фильма 1.',
|
|
||||||
imageUrl: 'https://via.placeholder.com/300x400',
|
|
||||||
};
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<h1>Топ фильмов</h1>
|
<h1>Топ фильмов</h1>
|
||||||
<div id="movie-container">
|
<div id="movie-container">
|
||||||
<MovieCard {...movieData} />
|
<MovieList />
|
||||||
<MovieCard {...movieData} />
|
|
||||||
<MovieCard {...movieData} />
|
|
||||||
<MovieCard {...movieData} />
|
|
||||||
<MovieCard {...movieData} />
|
|
||||||
<MovieCard {...movieData} />
|
|
||||||
<MovieCard {...movieData} />
|
|
||||||
<MovieCard {...movieData} />
|
|
||||||
<MovieCard {...movieData} />
|
|
||||||
<MovieCard {...movieData} />
|
|
||||||
<MovieCard {...movieData} />
|
|
||||||
<MovieCard {...movieData} />
|
|
||||||
<MovieCard {...movieData} />
|
|
||||||
<MovieCard {...movieData} />
|
|
||||||
<MovieCard {...movieData} />
|
|
||||||
<MovieCard {...movieData} />
|
|
||||||
<MovieCard {...movieData} />
|
|
||||||
<MovieCard {...movieData} />
|
|
||||||
</div>
|
</div>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
59
src/pages/PageEdit copy.jsx
Normal file
59
src/pages/PageEdit copy.jsx
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
import { useState } from 'react';
|
||||||
|
import { Button, Form } from 'react-bootstrap';
|
||||||
|
import { Link } from 'react-router-dom';
|
||||||
|
|
||||||
|
const PageEdit = () => {
|
||||||
|
const [validated, setValidated] = useState(false);
|
||||||
|
|
||||||
|
const handleSubmit = (event) => {
|
||||||
|
const form = event.currentTarget;
|
||||||
|
if (form.checkValidity() === false) {
|
||||||
|
event.preventDefault();
|
||||||
|
event.stopPropagation();
|
||||||
|
}
|
||||||
|
|
||||||
|
setValidated(true);
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<div className="text-center">
|
||||||
|
<img id="image-preview" src="https://via.placeholder.com/300x400"
|
||||||
|
alt="placeholder" />
|
||||||
|
</div>
|
||||||
|
<Form id="items-form" noValidate validated={validated} onSubmit={handleSubmit}>
|
||||||
|
<Form.Group className="mb-3" htmlFor="item">
|
||||||
|
<Form.Label htmlFor="item" className="form-label">Жанр</Form.Label>
|
||||||
|
<Form.Select name='selected' required>
|
||||||
|
</Form.Select>
|
||||||
|
</Form.Group>
|
||||||
|
<Form.Group className="mb-3" htmlFor="name">
|
||||||
|
<Form.Label>Название фильма</Form.Label>
|
||||||
|
<Form.Control type="text" name="name" required />
|
||||||
|
</Form.Group>
|
||||||
|
<Form.Group className="mb-3" htmlFor="rating">
|
||||||
|
<Form.Label>Рейтинг</Form.Label>
|
||||||
|
<Form.Control type="number" name="rating" min="1" max="10" required />
|
||||||
|
</Form.Group>
|
||||||
|
<Form.Group className="mb-3" htmlFor="releaseDate">
|
||||||
|
<Form.Label>Дата создания</Form.Label>
|
||||||
|
<Form.Control type="date" name="releaseDate" required />
|
||||||
|
</Form.Group>
|
||||||
|
<Form.Group className="mb-3" htmlFor="director">
|
||||||
|
<Form.Label>Режиссер</Form.Label>
|
||||||
|
<Form.Control type="text" name="director" required />
|
||||||
|
</Form.Group>
|
||||||
|
<Form.Group className="mb-3" htmlFor="image">
|
||||||
|
<Form.Label>Обложка</Form.Label>
|
||||||
|
<Form.Control type="file" name="image" accept="image/*" />
|
||||||
|
</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="/adminpage" variant="secondary">Назад</Button>
|
||||||
|
<Button className="btn-mw me-md-3" type="submit" variant="primary">Сохранить</Button>
|
||||||
|
</Form.Group>
|
||||||
|
</Form>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default PageEdit;
|
@ -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 PageEdit = () => {
|
const PageEdit = () => {
|
||||||
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/300x400"
|
|
||||||
alt="placeholder" />
|
|
||||||
</div>
|
|
||||||
<Form id="items-form" noValidate validated={validated} onSubmit={handleSubmit}>
|
|
||||||
<Form.Group className="mb-3" htmlFor="item">
|
|
||||||
<Form.Label htmlFor="item" className="form-label">Жанр</Form.Label>
|
|
||||||
<Form.Select name='selected' required>
|
|
||||||
</Form.Select>
|
|
||||||
</Form.Group>
|
|
||||||
<Form.Group className="mb-3" htmlFor="name">
|
|
||||||
<Form.Label>Название фильма</Form.Label>
|
|
||||||
<Form.Control type="text" name="name" required />
|
|
||||||
</Form.Group>
|
|
||||||
<Form.Group className="mb-3" htmlFor="rating">
|
|
||||||
<Form.Label>Рейтинг</Form.Label>
|
|
||||||
<Form.Control type="number" name="rating" min="1" max="10" required />
|
|
||||||
</Form.Group>
|
|
||||||
<Form.Group className="mb-3" htmlFor="releaseDate">
|
|
||||||
<Form.Label>Дата создания</Form.Label>
|
|
||||||
<Form.Control type="date" name="releaseDate" required />
|
|
||||||
</Form.Group>
|
|
||||||
<Form.Group className="mb-3" htmlFor="director">
|
|
||||||
<Form.Label>Режиссер</Form.Label>
|
|
||||||
<Form.Control type="text" name="director" required />
|
|
||||||
</Form.Group>
|
|
||||||
<Form.Group className="mb-3" htmlFor="image">
|
|
||||||
<Form.Label>Обложка</Form.Label>
|
|
||||||
<Form.Control type="file" name="image" accept="image/*" />
|
|
||||||
</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="/adminpage" variant="secondary">Назад</Button>
|
|
||||||
<Button className="btn-mw me-md-3" type="submit" variant="primary">Сохранить</Button>
|
|
||||||
</Form.Group>
|
|
||||||
</Form>
|
|
||||||
</>
|
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user