Что доделали по уроку

This commit is contained in:
2026-05-17 12:46:44 +03:00
parent 6cfec52fb8
commit c3a78e506a
17 changed files with 141 additions and 29 deletions
+18 -14
View File
@@ -11,7 +11,7 @@
"react": "^19.1.0", "react": "^19.1.0",
"react-dom": "^19.1.0", "react-dom": "^19.1.0",
"react-icons": "^5.5.0", "react-icons": "^5.5.0",
"react-router-dom": "^7.6.3", "react-router-dom": "^7.15.1",
"sass-embedded": "^1.89.2" "sass-embedded": "^1.89.2"
}, },
"devDependencies": { "devDependencies": {
@@ -1622,12 +1622,16 @@
"license": "MIT" "license": "MIT"
}, },
"node_modules/cookie": { "node_modules/cookie": {
"version": "1.0.2", "version": "1.1.1",
"resolved": "https://registry.npmjs.org/cookie/-/cookie-1.0.2.tgz", "resolved": "https://registry.npmjs.org/cookie/-/cookie-1.1.1.tgz",
"integrity": "sha512-9Kr/j4O16ISv8zBBhJoi4bXOYNTkFLOqSL3UDB0njXxCXNezjeyVrJyGOWtgfs/q2km1gwBcfH8q1yEGoMYunA==", "integrity": "sha512-ei8Aos7ja0weRpFzJnEA9UHJ/7XQmqglbRwnf2ATjcB9Wq874VKH9kfjjirM6UhU2/E5fFYadylyhFldcqSidQ==",
"license": "MIT", "license": "MIT",
"engines": { "engines": {
"node": ">=18" "node": ">=18"
},
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/express"
} }
}, },
"node_modules/cross-spawn": { "node_modules/cross-spawn": {
@@ -2516,9 +2520,9 @@
} }
}, },
"node_modules/react-router": { "node_modules/react-router": {
"version": "7.6.3", "version": "7.15.1",
"resolved": "https://registry.npmjs.org/react-router/-/react-router-7.6.3.tgz", "resolved": "https://registry.npmjs.org/react-router/-/react-router-7.15.1.tgz",
"integrity": "sha512-zf45LZp5skDC6I3jDLXQUu0u26jtuP4lEGbc7BbdyxenBN1vJSTA18czM2D+h5qyMBuMrD+9uB+mU37HIoKGRA==", "integrity": "sha512-R8rl9HhgikFYoPJymnUtPXWbnDb3oget6lQnfIoupbt61aT9aOhRkDsY2XRhZRyX1Z/8a5sL74fXmFNm3NRK5A==",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"cookie": "^1.0.1", "cookie": "^1.0.1",
@@ -2538,12 +2542,12 @@
} }
}, },
"node_modules/react-router-dom": { "node_modules/react-router-dom": {
"version": "7.6.3", "version": "7.15.1",
"resolved": "https://registry.npmjs.org/react-router-dom/-/react-router-dom-7.6.3.tgz", "resolved": "https://registry.npmjs.org/react-router-dom/-/react-router-dom-7.15.1.tgz",
"integrity": "sha512-DiWJm9qdUAmiJrVWaeJdu4TKu13+iB/8IEi0EW/XgaHCjW/vWGrwzup0GVvaMteuZjKnh5bEvJP/K0MDnzawHw==", "integrity": "sha512-AzF62gjY6U9rkMq4RfP/r2EVtQ7DMfNMjyOp/flLTCrtRylLiK4wT4pSq6O8rOXZ2eXdZYJPEYe+ifomiv+Igg==",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"react-router": "7.6.3" "react-router": "7.15.1"
}, },
"engines": { "engines": {
"node": ">=20.0.0" "node": ">=20.0.0"
@@ -2947,9 +2951,9 @@
} }
}, },
"node_modules/set-cookie-parser": { "node_modules/set-cookie-parser": {
"version": "2.7.1", "version": "2.7.2",
"resolved": "https://registry.npmjs.org/set-cookie-parser/-/set-cookie-parser-2.7.1.tgz", "resolved": "https://registry.npmjs.org/set-cookie-parser/-/set-cookie-parser-2.7.2.tgz",
"integrity": "sha512-IOc8uWeOZgnb3ptbCURJWNjWUPcO3ZnTTdzsurqERrP6nPyv+paC55vJM0LpOlT2ne+Ix+9+CRG1MNLlyZ4GjQ==", "integrity": "sha512-oeM1lpU/UvhTxw+g3cIfxXHyJRc/uidd3yK1P242gzHds0udQBYzs3y8j4gCCW+ZJ7ad0yctld8RYO+bdurlvw==",
"license": "MIT" "license": "MIT"
}, },
"node_modules/shebang-command": { "node_modules/shebang-command": {
+1 -1
View File
@@ -14,7 +14,7 @@
"react": "^19.1.0", "react": "^19.1.0",
"react-dom": "^19.1.0", "react-dom": "^19.1.0",
"react-icons": "^5.5.0", "react-icons": "^5.5.0",
"react-router-dom": "^7.6.3", "react-router-dom": "^7.15.1",
"sass-embedded": "^1.89.2" "sass-embedded": "^1.89.2"
}, },
"devDependencies": { "devDependencies": {
+6 -2
View File
@@ -1,9 +1,11 @@
import styles from './index.module.scss' import styles from './index.module.scss'
import WishIcon from '../../assets/icons/wish.svg' import WishIcon from '../../assets/icons/wish.svg'
import { Link } from 'react-router-dom'
const ProductCard = ({ name, price, imageUrl }) => { const ProductCard = ({ id, name, price, imageUrl }) => {
return ( return (
<div className={styles.product}> <div className={styles.product}>
<div className={styles.image}> <div className={styles.image}>
<img src={imageUrl} alt='' /> <img src={imageUrl} alt='' />
@@ -14,7 +16,9 @@ const ProductCard = ({ name, price, imageUrl }) => {
</div> </div>
</div> </div>
<div className={styles.content}> <div className={styles.content}>
<h4>{name}</h4> <Link to={{ pathname: `/catalog/${id}` }} state={ name, price}>
<h4>{name}</h4>
</Link>
<div className={styles.stats}> <div className={styles.stats}>
<span>${price}</span> <span>${price}</span>
</div> </div>
+18 -8
View File
@@ -4,7 +4,7 @@ import CartIcon from '../../assets/icons/cart.svg'
import UserIcon from '../../assets/icons/user.svg' import UserIcon from '../../assets/icons/user.svg'
import WishlistIcon from '../../assets/icons/wishlist.svg' import WishlistIcon from '../../assets/icons/wishlist.svg'
import LoopIcon from '../../assets/icons/loop.svg' import LoopIcon from '../../assets/icons/loop.svg'
import { Link } from 'react-router-dom' import { Link, NavLink } from 'react-router-dom'
const Header = () => { const Header = () => {
return ( return (
@@ -13,16 +13,22 @@ const Header = () => {
<nav> <nav>
<ul> <ul>
<li> <li>
<Link to={{ pathname: '/' }}>Home</Link> <NavLink to={{ pathname: '/' }}
className={ ({ isActive }) => (isActive ? styles.active : '')}>
Главная
</NavLink>
</li> </li>
<li> <li>
<Link to={{ pathname: '/contact' }}>Contact</Link> <Link to={{ pathname: '/contact' }}>Контакты</Link>
</li> </li>
<li> <li>
<Link to={{ pathname: '/about' }}>About</Link> <NavLink to={{ pathname: '/about' }}
className={ ({ isActive }) => (isActive ? styles.active : '')}>
О нас
</NavLink>
</li> </li>
<li> <li>
<a href='#'>Sign Up</a> <Link to={{ pathname: '/login' }}>Sign Up</Link>
</li> </li>
</ul> </ul>
</nav> </nav>
@@ -37,12 +43,16 @@ const Header = () => {
</Link> </Link>
</button> </button>
<button> <button>
<Link to={{ pathname: '/cart' }}> <NavLink to={{ pathname: '/cart', search: '?category=electronic', state: {id: 44} }}
className={ ({ isActive }) => (isActive ? styles.active : '')}>
<img src={CartIcon} alt='' /> <img src={CartIcon} alt='' />
</Link> </NavLink>
</button> </button>
<button> <button>
<img src={UserIcon} alt='' /> <NavLink to={{ pathname: '/profile/111' }}
className={ ({ isActive }) => (isActive ? styles.active : '')}>
<img src={UserIcon} alt='' />
</NavLink>
</button> </button>
</div> </div>
</header> </header>
+3
View File
@@ -53,3 +53,6 @@
} }
} }
} }
.active {
border-bottom: 1px solid red;
}
+3 -2
View File
@@ -7,10 +7,11 @@ const ProductList = () => {
const [products, setProducts] = React.useState([]) const [products, setProducts] = React.useState([])
const [loading, setLoading] = React.useState(true) const [loading, setLoading] = React.useState(true)
const [error, setError] = React.useState(null) const [error, setError] = React.useState(null)
console.log("rendred");
React.useEffect(() => { React.useEffect(() => {
let cancelled = false let cancelled = false
console.log("useEffect");
const getProducts = async () => { const getProducts = async () => {
try { try {
setLoading(true) setLoading(true)
@@ -44,7 +45,7 @@ const ProductList = () => {
return () => { return () => {
cancelled = true cancelled = true
} }
}, []) },[])
if (loading) { if (loading) {
return <div className={styles.loading}>Загрузка продуктов...</div> return <div className={styles.loading}>Загрузка продуктов...</div>
+8
View File
@@ -8,6 +8,10 @@ import {
import Catalog from './pages/catalog' import Catalog from './pages/catalog'
import Cart from './pages/cart' import Cart from './pages/cart'
import About from './pages/about'
import Login from './pages/login'
import UserProfile from './pages/profile'
import Item from './pages/item'
createRoot(document.getElementById('root')).render( createRoot(document.getElementById('root')).render(
<Router> <Router>
@@ -15,7 +19,11 @@ createRoot(document.getElementById('root')).render(
{/* 2. Добавляем редирект с корневого пути */} {/* 2. Добавляем редирект с корневого пути */}
<Route path='/' element={<Navigate to='/catalog' replace />} /> <Route path='/' element={<Navigate to='/catalog' replace />} />
<Route path='/catalog' element={<Catalog />} /> <Route path='/catalog' element={<Catalog />} />
<Route path='/catalog/:id' element={<Item />} />
<Route path='/cart' element={<Cart />} /> <Route path='/cart' element={<Cart />} />
<Route path='/about' element={<About />} />
<Route path='/login' element={<Login />} />
<Route path='/profile/:id' element={<UserProfile name='Alex' />} />
</Routes> </Routes>
</Router> </Router>
) )
+13
View File
@@ -0,0 +1,13 @@
import styles from './index.module.scss'
import Header from '../../components/header/index'
const About = () => {
return (
<div className={styles.container}>
<Header />
</div>
)
}
export default About
+4
View File
@@ -0,0 +1,4 @@
.container {
max-width: 1170px;
margin: 0 auto;
}
+9 -1
View File
@@ -1,5 +1,13 @@
import styles from './index.module.scss'
import Header from '../../components/header/index'
const Cart = () => { const Cart = () => {
return <></> return (
<div className={styles.container}>
<Header />
</div>
)
} }
export default Cart export default Cart
+4
View File
@@ -0,0 +1,4 @@
.container {
max-width: 1170px;
margin: 0 auto;
}
+12
View File
@@ -0,0 +1,12 @@
import styles from './index.module.scss'
import { useParams } from 'react-router-dom'
const Product = ({ name, price }) => {
const { id } = useParams();
return (
<>
<h2>Товар {id}. {name} по цене {price }</h2>
</>
)
}
export default Product
View File
+22
View File
@@ -0,0 +1,22 @@
import styles from './index.module.scss'
import { useNavigate } from 'react-router-dom'
const Login = () => {
const navigate = useNavigate();
const handleSubmit = formData => {
//Какая то логика проверки авторизации
navigate('/catalog')
}
return (
<>
<h2>Страница авторизации</h2>
<form onSubmit={handleSubmit}>
<button type="submit">Войти</button>
</form>
</>
)
}
export default Login
View File
+15
View File
@@ -0,0 +1,15 @@
import styles from './index.module.scss'
import Header from '../../components/header/index'
import { useParams } from 'react-router-dom'
const UserProfile = ({ name }) => {
const { id } = useParams();
return (
<div className={styles.container}>
<Header />
<h2>Профиль пользователя {id} {name}</h2>
</div>
)
}
export default UserProfile
+4
View File
@@ -0,0 +1,4 @@
.container {
max-width: 1170px;
margin: 0 auto;
}