Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 50265b1454 | |||
| 80fd4ed7cc | |||
| 91a6340078 | |||
| 102da1ad75 | |||
| a84b1972e7 | |||
| 2ba1a63832 | |||
| 9367009fdf | |||
| e0ba3a0f45 | |||
| df845c3ae7 | |||
| 7a5be1d876 | |||
| ec325b51bc |
@@ -1,18 +0,0 @@
|
|||||||
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.
|
|
||||||
+13
-9
@@ -2,17 +2,11 @@ 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 defineConfig([
|
export default [
|
||||||
globalIgnores(['dist']),
|
{ ignores: ['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,
|
||||||
@@ -22,8 +16,18 @@ export default defineConfig([
|
|||||||
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 },
|
||||||
|
],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
])
|
]
|
||||||
|
|||||||
+24
-11
@@ -1,13 +1,26 @@
|
|||||||
<!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>
|
||||||
</head>
|
<style>
|
||||||
<body>
|
* {
|
||||||
<div id="root"></div>
|
margin: 0;
|
||||||
<script type="module" src="/src/main.jsx"></script>
|
padding: 0;
|
||||||
</body>
|
box-sizing: border-box;
|
||||||
|
|
||||||
|
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
+1203
-428
File diff suppressed because it is too large
Load Diff
+11
-10
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"name": "router-middleware-practice",
|
"name": "store-client",
|
||||||
"private": true,
|
"private": true,
|
||||||
"version": "0.0.0",
|
"version": "0.0.0",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
@@ -12,17 +12,18 @@
|
|||||||
"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"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@eslint/js": "^9.30.1",
|
"@eslint/js": "^9.25.0",
|
||||||
"@types/react": "^19.1.8",
|
"@types/react": "^19.1.2",
|
||||||
"@types/react-dom": "^19.1.6",
|
"@types/react-dom": "^19.1.2",
|
||||||
"@vitejs/plugin-react": "^4.6.0",
|
"@vitejs/plugin-react": "^4.4.1",
|
||||||
"eslint": "^9.30.1",
|
"eslint": "^9.25.0",
|
||||||
"eslint-plugin-react-hooks": "^5.2.0",
|
"eslint-plugin-react-hooks": "^5.2.0",
|
||||||
"eslint-plugin-react-refresh": "^0.4.20",
|
"eslint-plugin-react-refresh": "^0.4.19",
|
||||||
"globals": "^16.3.0",
|
"globals": "^16.0.0",
|
||||||
"vite": "^7.0.4"
|
"sass-embedded": "^1.99.0",
|
||||||
|
"vite": "^6.3.5"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+99
-29
@@ -1,35 +1,105 @@
|
|||||||
|
import styles from './App.module.scss'
|
||||||
|
import SneakersImage from './assets/images/sneakers-image.jpg'
|
||||||
|
import { FaRegUser } from 'react-icons/fa'
|
||||||
|
import { FaHeart } from "react-icons/fa";
|
||||||
|
import { BsCheckSquare } from "react-icons/bs";
|
||||||
import { useState } from 'react'
|
import { useState } from 'react'
|
||||||
import reactLogo from './assets/react.svg'
|
|
||||||
import viteLogo from '/vite.svg'
|
function Header() {
|
||||||
import './App.css'
|
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>
|
||||||
|
<div>
|
||||||
|
<FaRegUser size={24} color='#3258e3' />
|
||||||
|
<button>Profile</button>
|
||||||
|
</div>
|
||||||
|
</header>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function Product() {
|
||||||
|
function LikeCounter() {
|
||||||
|
const [likes,setLikes] = useState(0);
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<h2>Лайков: {likes}</h2>
|
||||||
|
{likes < 10 && <button onClick={() => setLikes(likes + 1)}>👍 Лайк</button>}
|
||||||
|
{likes > 0 && <button onClick={() => setLikes(0)}>🔄 Сбросить</button> }
|
||||||
|
{likes >= 10 && <h3>Вы достигли лимита!</h3>}
|
||||||
|
<div className={styles.progress}>
|
||||||
|
<div className={styles.value} style={{ width: `${likes*10}%`}}></div>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleClick() {
|
||||||
|
console.log('Working!')
|
||||||
|
}
|
||||||
|
|
||||||
|
function Counter() {
|
||||||
|
const [isLiked,setIsLiked] = useState(false);
|
||||||
|
|
||||||
|
const toggleLike = () => {
|
||||||
|
setIsLiked(!isLiked);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<BsCheckSquare
|
||||||
|
onClick={toggleLike}
|
||||||
|
fill={isLiked==true ? 'red' : 'grey'}
|
||||||
|
size={44}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className={styles.product}>
|
||||||
|
<img src={SneakersImage} alt='' />
|
||||||
|
<div className={styles.content}>
|
||||||
|
<div className={styles.title}>
|
||||||
|
<h4>Sneakers Red & White 2025</h4>
|
||||||
|
<button onClick={event => handleClick(event)}>+</button>
|
||||||
|
</div>
|
||||||
|
<p className={styles.description}>NIKE</p>
|
||||||
|
<p className={styles.price}>$38.00</p>
|
||||||
|
</div>
|
||||||
|
<LikeCounter />
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
function App() {
|
function App() {
|
||||||
const [count, setCount] = useState(0)
|
return (
|
||||||
|
<>
|
||||||
return (
|
<div className={styles.container}>
|
||||||
<>
|
<Header />
|
||||||
<div>
|
</div>
|
||||||
<a href="https://vite.dev" target="_blank">
|
<div className={styles.container}>
|
||||||
<img src={viteLogo} className="logo" alt="Vite logo" />
|
<ul className={styles.list}>
|
||||||
</a>
|
<li>
|
||||||
<a href="https://react.dev" target="_blank">
|
<Product />
|
||||||
<img src={reactLogo} className="logo react" alt="React logo" />
|
</li>
|
||||||
</a>
|
<li>
|
||||||
</div>
|
<Product />
|
||||||
<h1>Vite + React</h1>
|
</li>
|
||||||
<div className="card">
|
<li>
|
||||||
<button onClick={() => setCount((count) => count + 1)}>
|
<Product />
|
||||||
count is {count}
|
</li>
|
||||||
</button>
|
</ul>
|
||||||
<p>
|
</div>
|
||||||
Edit <code>src/App.jsx</code> and save to test HMR
|
</>
|
||||||
</p>
|
)
|
||||||
</div>
|
|
||||||
<p className="read-the-docs">
|
|
||||||
Click on the Vite and React logos to learn more
|
|
||||||
</p>
|
|
||||||
</>
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default App
|
export default App
|
||||||
|
|||||||
@@ -0,0 +1,141 @@
|
|||||||
|
@use './assets/styles/variables' as *;
|
||||||
|
|
||||||
|
.progress {
|
||||||
|
width: 100%;
|
||||||
|
height: 10px;
|
||||||
|
border: 1px solid black;
|
||||||
|
|
||||||
|
}
|
||||||
|
.value {
|
||||||
|
/*width:70%;*/
|
||||||
|
height: 100%;
|
||||||
|
background-color: green;
|
||||||
|
}
|
||||||
|
|
||||||
|
.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;
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
.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;
|
||||||
|
}
|
||||||
|
|
||||||
|
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.
|
After Width: | Height: | Size: 23 KiB |
@@ -0,0 +1,5 @@
|
|||||||
|
$white-color: white;
|
||||||
|
$black-color: black;
|
||||||
|
|
||||||
|
$primary-color: #3258e3;
|
||||||
|
$seconday-color: #4432e3;
|
||||||
-26
@@ -1,26 +0,0 @@
|
|||||||
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
|
|
||||||
}
|
|
||||||
+7
-8
@@ -1,10 +1,9 @@
|
|||||||
import React from 'react'
|
import { StrictMode } from 'react'
|
||||||
import ReactDOM from 'react-dom/client'
|
import { createRoot } from 'react-dom/client'
|
||||||
import { RouterProvider } from 'react-router-dom'
|
import App from './App.jsx'
|
||||||
import router from './routes'
|
|
||||||
|
|
||||||
ReactDOM.createRoot(document.getElementById('root')).render(
|
createRoot(document.getElementById('root')).render(
|
||||||
<React.StrictMode>
|
<StrictMode>
|
||||||
<RouterProvider router={router} />
|
<App />
|
||||||
</React.StrictMode>
|
</StrictMode>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,10 +0,0 @@
|
|||||||
import React from 'react'
|
|
||||||
|
|
||||||
export default function Admin() {
|
|
||||||
return (
|
|
||||||
<div>
|
|
||||||
<h1>Админ-панель</h1>
|
|
||||||
<p>Доступ разрешён только администраторам.</p>
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
import React from 'react'
|
|
||||||
|
|
||||||
export default function Dashboard() {
|
|
||||||
return (
|
|
||||||
<div>
|
|
||||||
<h1>Панель пользователя</h1>
|
|
||||||
<p>Вы вошли как обычный пользователь или администратор.</p>
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
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>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
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