Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 56788f23d6 | |||
| ac00619fa6 | |||
| 93b5b8dd85 |
@@ -0,0 +1,18 @@
|
|||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2026 laktionov-as
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
||||||
|
associated documentation files (the "Software"), to deal in the Software without restriction, including
|
||||||
|
without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the
|
||||||
|
following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all copies or substantial
|
||||||
|
portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
|
||||||
|
LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO
|
||||||
|
EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||||
|
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
||||||
|
USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
@@ -1,55 +0,0 @@
|
|||||||
{
|
|
||||||
"products": [
|
|
||||||
{
|
|
||||||
"id": 1,
|
|
||||||
"name": "Sneakers Red & White 2025",
|
|
||||||
"brand": "NIKE",
|
|
||||||
"price": 38.0,
|
|
||||||
"imageUrl": "./src/assets/images/sneakers-image.jpg"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": 2,
|
|
||||||
"name": "Sneakers Red & White 2025",
|
|
||||||
"brand": "NIKE",
|
|
||||||
"price": 38.0,
|
|
||||||
"imageUrl": "./src/assets/images/sneakers-image.jpg"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": 3,
|
|
||||||
"name": "Sneakers Red & White 2025",
|
|
||||||
"brand": "NIKE",
|
|
||||||
"price": 38.0,
|
|
||||||
"imageUrl": "./src/assets/images/sneakers-image.jpg"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"articles": [
|
|
||||||
{
|
|
||||||
"id": 1,
|
|
||||||
"title": "Статья 1",
|
|
||||||
"author": "Иванов Иван Иванович",
|
|
||||||
"createDate": "2020-01-15",
|
|
||||||
"content": "Основной текст статьи"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"projects": [
|
|
||||||
{
|
|
||||||
"id":1,
|
|
||||||
"name": "Project 1",
|
|
||||||
"status": "work",
|
|
||||||
"description": "Very important!",
|
|
||||||
"tasks": [
|
|
||||||
{
|
|
||||||
"id":1,
|
|
||||||
"title":"Task 1",
|
|
||||||
"description": "Описание задачи"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id":2,
|
|
||||||
"title":"Task 2",
|
|
||||||
"description": "Описание задачи 2"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
|
|
||||||
}
|
|
||||||
+9
-13
@@ -2,11 +2,17 @@ import js from '@eslint/js'
|
|||||||
import globals from 'globals'
|
import globals from 'globals'
|
||||||
import reactHooks from 'eslint-plugin-react-hooks'
|
import reactHooks from 'eslint-plugin-react-hooks'
|
||||||
import reactRefresh from 'eslint-plugin-react-refresh'
|
import reactRefresh from 'eslint-plugin-react-refresh'
|
||||||
|
import { defineConfig, globalIgnores } from 'eslint/config'
|
||||||
|
|
||||||
export default [
|
export default defineConfig([
|
||||||
{ ignores: ['dist'] },
|
globalIgnores(['dist']),
|
||||||
{
|
{
|
||||||
files: ['**/*.{js,jsx}'],
|
files: ['**/*.{js,jsx}'],
|
||||||
|
extends: [
|
||||||
|
js.configs.recommended,
|
||||||
|
reactHooks.configs['recommended-latest'],
|
||||||
|
reactRefresh.configs.vite,
|
||||||
|
],
|
||||||
languageOptions: {
|
languageOptions: {
|
||||||
ecmaVersion: 2020,
|
ecmaVersion: 2020,
|
||||||
globals: globals.browser,
|
globals: globals.browser,
|
||||||
@@ -16,18 +22,8 @@ export default [
|
|||||||
sourceType: 'module',
|
sourceType: 'module',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
plugins: {
|
|
||||||
'react-hooks': reactHooks,
|
|
||||||
'react-refresh': reactRefresh,
|
|
||||||
},
|
|
||||||
rules: {
|
rules: {
|
||||||
...js.configs.recommended.rules,
|
|
||||||
...reactHooks.configs.recommended.rules,
|
|
||||||
'no-unused-vars': ['error', { varsIgnorePattern: '^[A-Z_]' }],
|
'no-unused-vars': ['error', { varsIgnorePattern: '^[A-Z_]' }],
|
||||||
'react-refresh/only-export-components': [
|
|
||||||
'warn',
|
|
||||||
{ allowConstantExport: true },
|
|
||||||
],
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
]
|
])
|
||||||
|
|||||||
+11
-24
@@ -1,26 +1,13 @@
|
|||||||
<!DOCTYPE html>
|
<!doctype html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8" />
|
<meta charset="UTF-8" />
|
||||||
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
<title>Vite + React</title>
|
<title>Vite + React</title>
|
||||||
<style>
|
</head>
|
||||||
* {
|
<body>
|
||||||
margin: 0;
|
<div id="root"></div>
|
||||||
padding: 0;
|
<script type="module" src="/src/main.jsx"></script>
|
||||||
box-sizing: border-box;
|
</body>
|
||||||
|
|
||||||
font-family: Arial, Helvetica, sans-serif;
|
|
||||||
}
|
|
||||||
|
|
||||||
body {
|
|
||||||
background-color: rgb(249, 249, 249);
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<div id="root"></div>
|
|
||||||
<script type="module" src="/src/main.jsx"></script>
|
|
||||||
</body>
|
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
Generated
+434
-770
File diff suppressed because it is too large
Load Diff
+26
-28
@@ -1,30 +1,28 @@
|
|||||||
{
|
{
|
||||||
"name": "store-client",
|
"name": "router-middleware-practice",
|
||||||
"private": true,
|
"private": true,
|
||||||
"version": "0.0.0",
|
"version": "0.0.0",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite",
|
"dev": "vite",
|
||||||
"server": "json-server --watch db.json --port 8000",
|
"build": "vite build",
|
||||||
"build": "vite build",
|
"lint": "eslint .",
|
||||||
"lint": "eslint .",
|
"preview": "vite preview"
|
||||||
"preview": "vite preview"
|
},
|
||||||
},
|
"dependencies": {
|
||||||
"dependencies": {
|
"react": "^19.1.0",
|
||||||
"react": "^19.1.0",
|
"react-dom": "^19.1.0",
|
||||||
"react-dom": "^19.1.0",
|
"react-router-dom": "^7.7.1"
|
||||||
"react-icons": "^5.5.0",
|
},
|
||||||
"sass-embedded": "^1.89.2"
|
"devDependencies": {
|
||||||
},
|
"@eslint/js": "^9.30.1",
|
||||||
"devDependencies": {
|
"@types/react": "^19.1.8",
|
||||||
"@eslint/js": "^9.25.0",
|
"@types/react-dom": "^19.1.6",
|
||||||
"@types/react": "^19.1.2",
|
"@vitejs/plugin-react": "^4.6.0",
|
||||||
"@types/react-dom": "^19.1.2",
|
"eslint": "^9.30.1",
|
||||||
"@vitejs/plugin-react": "^4.4.1",
|
"eslint-plugin-react-hooks": "^5.2.0",
|
||||||
"eslint": "^9.25.0",
|
"eslint-plugin-react-refresh": "^0.4.20",
|
||||||
"eslint-plugin-react-hooks": "^5.2.0",
|
"globals": "^16.3.0",
|
||||||
"eslint-plugin-react-refresh": "^0.4.19",
|
"vite": "^7.0.4"
|
||||||
"globals": "^16.0.0",
|
}
|
||||||
"vite": "^6.3.5"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
+30
-238
@@ -1,243 +1,35 @@
|
|||||||
import styles from './App.module.scss'
|
import { useState } from 'react'
|
||||||
import { FaRegUser } from 'react-icons/fa'
|
import reactLogo from './assets/react.svg'
|
||||||
import React, { useState, useEffect } from 'react'
|
import viteLogo from '/vite.svg'
|
||||||
|
import './App.css'
|
||||||
function Header() {
|
|
||||||
const handleChange = event => {
|
|
||||||
const newValue = event.target.value
|
|
||||||
console.log('Новое значение:', newValue)
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<header className={styles.header}>
|
|
||||||
<div>
|
|
||||||
<h2>Store</h2>
|
|
||||||
<input type='text ' placeholder='Search...' onChange={handleChange} />
|
|
||||||
</div>
|
|
||||||
<UserMenu isLoggedin={true} userName="Bob" role="user" />
|
|
||||||
</header>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
function UserMenu({ userName }) {
|
|
||||||
const [loggedin,setLoggedin] = useState(false);
|
|
||||||
const [role, setRole] = useState('user');
|
|
||||||
|
|
||||||
|
|
||||||
if (loggedin) {
|
|
||||||
return (
|
|
||||||
<div className="user-menu">
|
|
||||||
<nav>
|
|
||||||
<a href="/settings">Настройки</a>
|
|
||||||
{role === "admin" && <a href="/admin">Панель администратора</a>}
|
|
||||||
<div>
|
|
||||||
<FaRegUser size={24} color='#3258e3' />
|
|
||||||
<button>Profile</button>
|
|
||||||
<button onClick={() => setLoggedin(false)}>Exit</button>
|
|
||||||
</div>
|
|
||||||
</nav>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return (
|
|
||||||
<div className="login-form">
|
|
||||||
<button onClick={() => setLoggedin(true)}>Войти</button>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
function ArticleViewer({ articleId }) {
|
|
||||||
const [article,setArticle] = useState(null);
|
|
||||||
const [loading, setLoading] = useState(true);
|
|
||||||
const [error, setError] = useState(null);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
const fetchArticle = async () => {
|
|
||||||
try {
|
|
||||||
setLoading(true);
|
|
||||||
setError(null);
|
|
||||||
const responce = await fetch(`http://localhost:8000/articles/${articleId}`)
|
|
||||||
|
|
||||||
if(!responce.ok) {
|
|
||||||
throw new Error('Не удалось загрузить статью');
|
|
||||||
}
|
|
||||||
|
|
||||||
const data = await responce.json();
|
|
||||||
setArticle(data);
|
|
||||||
} catch(err) {
|
|
||||||
setError(err.message);
|
|
||||||
} finally {
|
|
||||||
setLoading(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fetchArticle();
|
|
||||||
},[articleId]);
|
|
||||||
|
|
||||||
if (loading) {
|
|
||||||
return (
|
|
||||||
<div className={styles.loading}>
|
|
||||||
<div className="spinner"></div>
|
|
||||||
<p>Загружаем статью ...</p>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
if (error) {
|
|
||||||
return (
|
|
||||||
<div className={styles.error}>
|
|
||||||
<h3>Ошибка загрузки</h3>
|
|
||||||
<p>{error}</p>
|
|
||||||
<button onClick={()=>window.location.reload()}>Попробовать еще</button>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
if (!article) {
|
|
||||||
return (
|
|
||||||
<div className={styles.empty}>
|
|
||||||
<p>Статья не найдена</p>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return (
|
|
||||||
<div className={styles.article}>
|
|
||||||
<h1>{article.title}</h1>
|
|
||||||
<div className="article-meta">
|
|
||||||
<span>Автор: {article.author}</span>
|
|
||||||
<span>Дата: {new Date(article.createDate).toLocaleDateString()}</span>
|
|
||||||
</div>
|
|
||||||
<div className="article-body">{article.content}</div>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
function ProjectDashboard({ projects }) {
|
|
||||||
return (
|
|
||||||
<div className={styles.dashboard}>
|
|
||||||
<h1>Панель управления проектами</h1>
|
|
||||||
{projects.map(project => (
|
|
||||||
<div key={project.id} className={styles.project}>
|
|
||||||
<h2>{project.name}</h2>
|
|
||||||
<span className={styles.project_status}>{project.status}</span>
|
|
||||||
<p className={styles.project_description}>{project.description}</p>
|
|
||||||
|
|
||||||
{project.tasks.length >0 && (
|
|
||||||
<div className={styles.tasks}>
|
|
||||||
{project.tasks.map(task => (
|
|
||||||
<div className={styles.task_card} key={task.id}>
|
|
||||||
<h4>{task.title}</h4>
|
|
||||||
<p>{task.description}</p>
|
|
||||||
</div>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
function Product({ name, brand, price, imageUrl }) {
|
|
||||||
const [isLiked, setIsLiked] = React.useState(false)
|
|
||||||
|
|
||||||
const toggleLike = () => {
|
|
||||||
setIsLiked(!isLiked)
|
|
||||||
}
|
|
||||||
|
|
||||||
function handleAddClick() {
|
|
||||||
console.log('Working!')
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className={styles.product}>
|
|
||||||
<img src={imageUrl} alt='' />
|
|
||||||
<div className={styles.content}>
|
|
||||||
<div className={styles.title}>
|
|
||||||
<h4>{name}</h4>
|
|
||||||
<div className={styles.actions}>
|
|
||||||
<button
|
|
||||||
className={styles.likeButton}
|
|
||||||
onClick={toggleLike}
|
|
||||||
aria-label={isLiked ? 'Убрать лайк' : 'Добавить лайк'}
|
|
||||||
>
|
|
||||||
<svg
|
|
||||||
width='18'
|
|
||||||
height='18'
|
|
||||||
viewBox='0 0 24 24'
|
|
||||||
fill={isLiked ? 'red' : 'none'}
|
|
||||||
stroke={isLiked ? 'red' : 'currentColor'}
|
|
||||||
strokeWidth='1.5'
|
|
||||||
>
|
|
||||||
<path d='M12 21.35L10.55 20.03C5.4 15.36 2 12.28 2 8.5C2 5.42 4.42 3 7.5 3C9.24 3 10.91 3.81 12 5.09C13.09 3.81 14.76 3 16.5 3C19.58 3 22 5.42 22 8.5C22 12.28 18.6 15.36 13.45 20.04L12 21.35Z' />
|
|
||||||
</svg>
|
|
||||||
</button>
|
|
||||||
<button onClick={handleAddClick}>+</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<p className={styles.description}>{brand}</p>
|
|
||||||
<p className={styles.price}>${price}</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
function App() {
|
function App() {
|
||||||
const [products, setProducts] = React.useState([])
|
const [count, setCount] = useState(0)
|
||||||
|
|
||||||
const getProducts = async () => {
|
return (
|
||||||
const response = await fetch('http://localhost:8000/products')
|
<>
|
||||||
const data = await response.json()
|
<div>
|
||||||
setProducts(data)
|
<a href="https://vite.dev" target="_blank">
|
||||||
}
|
<img src={viteLogo} className="logo" alt="Vite logo" />
|
||||||
|
</a>
|
||||||
React.useEffect(() => {
|
<a href="https://react.dev" target="_blank">
|
||||||
getProducts()
|
<img src={reactLogo} className="logo react" alt="React logo" />
|
||||||
}, [])
|
</a>
|
||||||
|
</div>
|
||||||
return (
|
<h1>Vite + React</h1>
|
||||||
<>
|
<div className="card">
|
||||||
<div className={styles.container}>
|
<button onClick={() => setCount((count) => count + 1)}>
|
||||||
<Header />
|
count is {count}
|
||||||
</div>
|
</button>
|
||||||
<div className={styles.container}>
|
<p>
|
||||||
{products.length > 0 ? (
|
Edit <code>src/App.jsx</code> and save to test HMR
|
||||||
<ul className={styles.list}>
|
</p>
|
||||||
{products.map(product => (
|
</div>
|
||||||
<li key={product.id}>
|
<p className="read-the-docs">
|
||||||
<Product {...product} />
|
Click on the Vite and React logos to learn more
|
||||||
</li>
|
</p>
|
||||||
))}
|
</>
|
||||||
</ul>
|
)
|
||||||
) : (
|
|
||||||
<h3>Список товаров пуст</h3>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
</div>
|
|
||||||
</>
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function App2() {
|
export default App
|
||||||
const [projects, setProjects] = React.useState([])
|
|
||||||
|
|
||||||
const getProjects = async () => {
|
|
||||||
const response = await fetch('http://localhost:8000/projects')
|
|
||||||
const data = await response.json()
|
|
||||||
setProjects(data)
|
|
||||||
}
|
|
||||||
|
|
||||||
React.useEffect(() => {
|
|
||||||
getProjects()
|
|
||||||
}, [])
|
|
||||||
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
<div className={styles.container}>
|
|
||||||
<Header />
|
|
||||||
</div>
|
|
||||||
<div className={styles.container}>
|
|
||||||
<ProjectDashboard projects={projects} />
|
|
||||||
</div>
|
|
||||||
</>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
export default App2
|
|
||||||
|
|||||||
@@ -1,150 +0,0 @@
|
|||||||
@use './assets/styles/variables' as *;
|
|
||||||
|
|
||||||
.header {
|
|
||||||
display: flex;
|
|
||||||
justify-content: space-between;
|
|
||||||
align-items: center;
|
|
||||||
|
|
||||||
padding: 20px;
|
|
||||||
background-color: white;
|
|
||||||
|
|
||||||
border-bottom-left-radius: 10px;
|
|
||||||
border-bottom-right-radius: 10px;
|
|
||||||
|
|
||||||
nav {
|
|
||||||
display: flex;
|
|
||||||
justify-content: space-around;
|
|
||||||
flex-direction: row;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
|
|
||||||
div {
|
|
||||||
&:first-child {
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
gap: 20px;
|
|
||||||
|
|
||||||
h2 {
|
|
||||||
color: $primary-color;
|
|
||||||
}
|
|
||||||
|
|
||||||
input {
|
|
||||||
border-radius: 5px;
|
|
||||||
outline: none;
|
|
||||||
font-size: 16px;
|
|
||||||
border: 1px solid gainsboro;
|
|
||||||
padding: 5px 10px;
|
|
||||||
|
|
||||||
&:focus {
|
|
||||||
border: 1px solid $primary-color;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
&:last-child {
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
gap: 10px;
|
|
||||||
|
|
||||||
button {
|
|
||||||
outline: 0;
|
|
||||||
border: 0;
|
|
||||||
border-radius: 5px;
|
|
||||||
padding: 5px 15px;
|
|
||||||
font-size: 16px;
|
|
||||||
background-color: $primary-color;
|
|
||||||
color: $white-color;
|
|
||||||
font-weight: 600;
|
|
||||||
cursor: pointer;
|
|
||||||
|
|
||||||
&:hover {
|
|
||||||
background-color: $seconday-color;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.container {
|
|
||||||
max-width: 1220px;
|
|
||||||
margin: 0 auto;
|
|
||||||
.article {
|
|
||||||
text-align: center;
|
|
||||||
background-color: lightgray;
|
|
||||||
}
|
|
||||||
.error {
|
|
||||||
text-align: center;
|
|
||||||
background-color: lightcoral;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.list {
|
|
||||||
display: flex;
|
|
||||||
justify-content: space-between;
|
|
||||||
flex-wrap: wrap;
|
|
||||||
border-radius: 10px;
|
|
||||||
margin-top: 100px; /* временно */
|
|
||||||
padding: 20px;
|
|
||||||
background-color: white;
|
|
||||||
list-style: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
.product {
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
width: 350px;
|
|
||||||
gap: 20px;
|
|
||||||
border-radius: 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.content {
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
gap: 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.title {
|
|
||||||
display: flex;
|
|
||||||
justify-content: space-between;
|
|
||||||
align-items: center;
|
|
||||||
|
|
||||||
h4 {
|
|
||||||
font-size: 18px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.actions {
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
gap: 5px;
|
|
||||||
|
|
||||||
button {
|
|
||||||
border: 1px solid $primary-color;
|
|
||||||
background-color: $white-color;
|
|
||||||
color: $primary-color;
|
|
||||||
border-radius: 5px;
|
|
||||||
outline: 0;
|
|
||||||
|
|
||||||
font-size: 20px;
|
|
||||||
padding: 5px 10px;
|
|
||||||
|
|
||||||
cursor: pointer;
|
|
||||||
|
|
||||||
&:hover {
|
|
||||||
background-color: $seconday-color;
|
|
||||||
color: $white-color;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
img {
|
|
||||||
border-radius: 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.description {
|
|
||||||
color: gray;
|
|
||||||
}
|
|
||||||
|
|
||||||
.price {
|
|
||||||
font-weight: bold;
|
|
||||||
}
|
|
||||||
Binary file not shown.
|
Before Width: | Height: | Size: 23 KiB |
@@ -1,5 +0,0 @@
|
|||||||
$white-color: white;
|
|
||||||
$black-color: black;
|
|
||||||
|
|
||||||
$primary-color: #3258e3;
|
|
||||||
$seconday-color: #4432e3;
|
|
||||||
+26
@@ -0,0 +1,26 @@
|
|||||||
|
import { redirect } from 'react-router-dom'
|
||||||
|
|
||||||
|
// Проверка авторизации
|
||||||
|
export function requireAuth() {
|
||||||
|
const isAuthenticated = localStorage.getItem('auth') === 'true'
|
||||||
|
if (!isAuthenticated) {
|
||||||
|
return redirect('/login')
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
// Проверка авторизации и роли
|
||||||
|
export function requireAdmin() {
|
||||||
|
const isAuthenticated = localStorage.getItem('auth') === 'true'
|
||||||
|
const role = localStorage.getItem('role')
|
||||||
|
|
||||||
|
if (!isAuthenticated) {
|
||||||
|
return redirect('/login')
|
||||||
|
}
|
||||||
|
|
||||||
|
if (role !== 'admin') {
|
||||||
|
return redirect('/dashboard') // если авторизован, но не админ — на общую панель
|
||||||
|
}
|
||||||
|
|
||||||
|
return null
|
||||||
|
}
|
||||||
+8
-7
@@ -1,9 +1,10 @@
|
|||||||
import { StrictMode } from 'react'
|
import React from 'react'
|
||||||
import { createRoot } from 'react-dom/client'
|
import ReactDOM from 'react-dom/client'
|
||||||
import App from './App.jsx'
|
import { RouterProvider } from 'react-router-dom'
|
||||||
|
import router from './routes'
|
||||||
|
|
||||||
createRoot(document.getElementById('root')).render(
|
ReactDOM.createRoot(document.getElementById('root')).render(
|
||||||
<StrictMode>
|
<React.StrictMode>
|
||||||
<App />
|
<RouterProvider router={router} />
|
||||||
</StrictMode>
|
</React.StrictMode>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
import React from 'react'
|
||||||
|
|
||||||
|
export default function Admin() {
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<h1>Админ-панель</h1>
|
||||||
|
<p>Доступ разрешён только администраторам.</p>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
import React from 'react'
|
||||||
|
|
||||||
|
export default function Dashboard() {
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<h1>Панель пользователя</h1>
|
||||||
|
<p>Вы вошли как обычный пользователь или администратор.</p>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
import React, { useState } from 'react'
|
||||||
|
import { useNavigate } from 'react-router-dom'
|
||||||
|
|
||||||
|
export default function Login() {
|
||||||
|
const [role, setRole] = useState('user')
|
||||||
|
const navigate = useNavigate()
|
||||||
|
|
||||||
|
const handleLogin = () => {
|
||||||
|
localStorage.setItem('auth', 'true')
|
||||||
|
localStorage.setItem('role', role)
|
||||||
|
navigate('/dashboard')
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<h1>Вход</h1>
|
||||||
|
<label>
|
||||||
|
Роль:
|
||||||
|
<select value={role} onChange={e => setRole(e.target.value)}>
|
||||||
|
<option value='user'>Обычный пользователь</option>
|
||||||
|
<option value='admin'>Администратор</option>
|
||||||
|
</select>
|
||||||
|
</label>
|
||||||
|
<br />
|
||||||
|
<button onClick={handleLogin}>Войти</button>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
import { createBrowserRouter } from 'react-router-dom'
|
||||||
|
import Login from './pages/Login'
|
||||||
|
import Dashboard from './pages/Dashboard'
|
||||||
|
import Admin from './pages/Admin'
|
||||||
|
import { requireAuth, requireAdmin } from './auth'
|
||||||
|
|
||||||
|
const router = createBrowserRouter([
|
||||||
|
{
|
||||||
|
path: '/login',
|
||||||
|
element: <Login />,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: '/dashboard',
|
||||||
|
element: <Dashboard />,
|
||||||
|
loader: requireAuth,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: '/admin',
|
||||||
|
element: <Admin />,
|
||||||
|
loader: requireAdmin,
|
||||||
|
},
|
||||||
|
])
|
||||||
|
|
||||||
|
export default router
|
||||||
Reference in New Issue
Block a user