Compare commits

..

5 Commits

Author SHA1 Message Date
laktionov-as b05a44eb0a Сделали компоненты 2026-06-04 19:05:41 +03:00
laktionov-as 0d3b7ce2fb Делали разделение на компоненты 2026-06-02 21:47:28 +03:00
isHardCoded 61d10e2bbf Сверстали страницу корзины 2025-07-31 11:59:52 +03:00
isHardCoded c2d14e90fe Подготовили структуру для корзины 2025-07-14 18:05:17 +03:00
isHardCoded bcffa33ade Fix 2025-07-14 16:50:14 +03:00
27 changed files with 1340 additions and 294 deletions
+1056 -101
View File
File diff suppressed because it is too large Load Diff
+3 -2
View File
@@ -11,11 +11,11 @@
"preview": "vite preview"
},
"dependencies": {
"json-server": "^1.0.0-beta.3",
"react": "^19.1.0",
"react-dom": "^19.1.0",
"react-icons": "^5.5.0",
"react-router-dom": "^7.15.1",
"sass-embedded": "^1.89.2"
"react-router-dom": "^7.7.1"
},
"devDependencies": {
"@eslint/js": "^9.25.0",
@@ -26,6 +26,7 @@
"eslint-plugin-react-hooks": "^5.2.0",
"eslint-plugin-react-refresh": "^0.4.19",
"globals": "^16.0.0",
"sass-embedded": "^1.100.0",
"vite": "^6.3.5"
}
}
+30
View File
@@ -0,0 +1,30 @@
import styles from './OrderDetail.module.scss'
const OrderDetail = () => {
return (
<div className={styles.detail}>
<h2>Order Summary</h2>
<div className={styles.stats}>
<div>
<p>Subtotal</p>
<span>$565</span>
</div>
<div>
<p>Discount (-20%)</p>
<span>-$113</span>
</div>
<div>
<p>Delivery Fee</p>
<span>$15</span>
</div>
</div>
<div className={styles.total}>
<p>Total</p>
<span>$467</span>
</div>
<button>Go to Checkout</button>
</div>
)
}
export default OrderDetail
+67
View File
@@ -0,0 +1,67 @@
@use '../assets/styles/variables' as *;
.detail {
border: 1px solid gainsboro;
border-radius: 20px;
flex-basis: 50%;
margin-top: 24px;
padding: 20px;
display: flex;
flex-direction: column;
.stats {
display: flex;
flex-direction: column;
gap: 20px;
margin-top: 24px;
padding-bottom: 20px;
border-bottom: 1px solid gainsboro;
div {
display: flex;
align-items: center;
justify-content: space-between;
p {
color: gray;
font-size: 20px;
}
span {
font-size: 20px;
font-weight: bold;
}
}
}
.total {
display: flex;
align-items: center;
justify-content: space-between;
p {
color: gray;
font-size: 20px;
}
span {
font-size: 20px;
font-weight: bold;
margin-top: 20px;
}
}
button {
outline: 0;
border: 0;
font-size: 16px;
padding: 20px;
border-radius: 62px;
background-color: $primary-color;
color: $white-color;
cursor: pointer;
margin-top: 24px;
}
}
+29
View File
@@ -0,0 +1,29 @@
import styles from './index.module.scss'
import JacketImage from '../../../assets/images/products/jacket.svg'
import TrashIcon from '../../../assets/icons/trash.svg'
const CartItem = () => {
return (
<div className={styles.item}>
<button className={styles.trash}>
<img src={TrashIcon} alt='' />
</button>
<div className={styles.image}>
<img src={JacketImage} alt='' />
</div>
<div className={styles.content}>
<h2>Quilted Satin Jacket</h2>
<div className={styles.wrapper}>
<span className={styles.price}>$145</span>
<div className={styles.buttons}>
<button>-</button>
<span>1</span>
<button>+</button>
</div>
</div>
</div>
</div>
)
}
export default CartItem
@@ -0,0 +1,62 @@
.item {
border-bottom: 1px solid #dcdcdc;
padding: 24px 0;
position: relative;
.trash {
outline: 0;
border: 0;
background-color: white;
position: absolute;
top: 20px;
right: 20px;
cursor: pointer;
}
.image {
background-color: #f5f5f5;
display: flex;
align-items: center;
justify-content: center;
padding: 35px;
height: 124px;
width: 124px;
img {
width: 90px;
object-fit: contain;
}
}
.wrapper {
display: flex;
align-items: center;
justify-content: space-between;
.price {
font-size: 24px;
}
.buttons {
display: flex;
background-color: #f0f0f0;
padding: 12px 20px;
gap: 20px;
border-radius: 62px;
align-items: center;
span {
font-size: 14px;
}
button {
outline: 0;
border: 0;
font-size: 16px;
cursor: pointer;
}
}
}
}
@@ -1,11 +1,9 @@
import styles from './index.module.scss'
import WishIcon from '../../assets/icons/wish.svg'
import { Link } from 'react-router-dom'
import WishIcon from '../../../assets/icons/wish.svg'
const ProductCard = ({ id, name, price, imageUrl }) => {
const ProductCard = ({ name, price, imageUrl }) => {
return (
<div className={styles.product}>
<div className={styles.image}>
<img src={imageUrl} alt='' />
@@ -16,9 +14,7 @@ const ProductCard = ({ id, name, price, imageUrl }) => {
</div>
</div>
<div className={styles.content}>
<Link to={{ pathname: `/catalog/${id}` }} state={ name, price}>
<h4>{name}</h4>
</Link>
<h4>{name}</h4>
<div className={styles.stats}>
<span>${price}</span>
</div>
@@ -1,4 +1,4 @@
@use '../../assets/styles/variables' as *;
@use '../../../assets/styles/variables' as *;
.product {
display: flex;
+8 -18
View File
@@ -4,7 +4,7 @@ import CartIcon from '../../assets/icons/cart.svg'
import UserIcon from '../../assets/icons/user.svg'
import WishlistIcon from '../../assets/icons/wishlist.svg'
import LoopIcon from '../../assets/icons/loop.svg'
import { Link, NavLink } from 'react-router-dom'
import { Link } from 'react-router-dom'
const Header = () => {
return (
@@ -13,22 +13,16 @@ const Header = () => {
<nav>
<ul>
<li>
<NavLink to={{ pathname: '/' }}
className={ ({ isActive }) => (isActive ? styles.active : '')}>
Главная
</NavLink>
<Link to={{ pathname: '/' }}>Home</Link>
</li>
<li>
<Link to={{ pathname: '/contact' }}>Контакты</Link>
<Link to={{ pathname: '/contact' }}>Contact</Link>
</li>
<li>
<NavLink to={{ pathname: '/about' }}
className={ ({ isActive }) => (isActive ? styles.active : '')}>
О нас
</NavLink>
<Link to={{ pathname: '/about' }}>About</Link>
</li>
<li>
<Link to={{ pathname: '/login' }}>Sign Up</Link>
<a href='#'>Sign Up</a>
</li>
</ul>
</nav>
@@ -43,16 +37,12 @@ const Header = () => {
</Link>
</button>
<button>
<NavLink to={{ pathname: '/cart', search: '?category=electronic', state: {id: 44} }}
className={ ({ isActive }) => (isActive ? styles.active : '')}>
<Link to={{ pathname: '/cart' }}>
<img src={CartIcon} alt='' />
</NavLink>
</Link>
</button>
<button>
<NavLink to={{ pathname: '/profile/111' }}
className={ ({ isActive }) => (isActive ? styles.active : '')}>
<img src={UserIcon} alt='' />
</NavLink>
<img src={UserIcon} alt='' />
</button>
</div>
</header>
-3
View File
@@ -53,6 +53,3 @@
}
}
}
.active {
border-bottom: 1px solid red;
}
+20
View File
@@ -0,0 +1,20 @@
import CartItem from '../../card/cart'
import styles from './index.module.scss'
const CartList = () => {
return (
<ul className={styles.list}>
<li>
<CartItem />
</li>
<li>
<CartItem />
</li>
<li>
<CartItem />
</li>
</ul>
)
}
export default CartList
@@ -0,0 +1,13 @@
.list {
display: flex;
border: 1px solid gainsboro;
border-radius: 20px;
padding: 20px;
margin-top: 24px;
list-style: none;
max-width: 715px;
flex-direction: column;
flex-basis: 80%;
}
-76
View File
@@ -1,76 +0,0 @@
import React from 'react'
import styles from './index.module.scss'
import ProductCard from '../card'
const ProductList = () => {
const [products, setProducts] = React.useState([])
const [loading, setLoading] = React.useState(true)
const [error, setError] = React.useState(null)
console.log("rendred");
React.useEffect(() => {
let cancelled = false
console.log("useEffect");
const getProducts = async () => {
try {
setLoading(true)
setError(null)
const response = await fetch('http://localhost:8000/products')
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`)
}
const data = await response.json()
if (!cancelled) {
setProducts(data)
}
} catch (err) {
if (!cancelled) {
setError(err.message)
setProducts([])
}
} finally {
if (!cancelled) {
setLoading(false)
}
}
}
getProducts()
return () => {
cancelled = true
}
},[])
if (loading) {
return <div className={styles.loading}>Загрузка продуктов...</div>
}
if (error) {
return (
<div className={styles.error}>
<p>Ошибка при загрузке продуктов: {error}</p>
<button onClick={() => window.location.reload()}>
Попробовать снова
</button>
</div>
)
}
return (
<ul className={styles.list}>
{products.map(product => (
<li key={product.id}>
<ProductCard {...product} />
</li>
))}
</ul>
)
}
export default ProductList
+34
View File
@@ -0,0 +1,34 @@
import styles from './index.module.scss'
import ProductCard from '../../card/product'
import { useProducts } from '../../../hooks/useProducts'
const ProductList = () => {
const { products, loading, error } = useProducts()
if (loading) {
return <div className={styles.loading}>Загрузка продуктов...</div>
}
if (error) {
return (
<div className={styles.error}>
<p>Ошибка при загрузке продуктов: {error}</p>
<button onClick={() => window.location.reload()}>
Попробовать снова
</button>
</div>
)
}
return (
<ul className={styles.list}>
{products.map(product => (
<li key={product.id}>
<ProductCard {...product} />
</li>
))}
</ul>
)
}
export default ProductList
+1 -10
View File
@@ -3,27 +3,18 @@ import {
BrowserRouter as Router,
Routes,
Route,
Navigate, // 1. Импортируем компонент для редиректа
Navigate,
} from 'react-router-dom'
import Catalog from './pages/catalog'
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(
<Router>
<Routes>
{/* 2. Добавляем редирект с корневого пути */}
<Route path='/' element={<Navigate to='/catalog' replace />} />
<Route path='/catalog' element={<Catalog />} />
<Route path='/catalog/:id' element={<Item />} />
<Route path='/cart' element={<Cart />} />
<Route path='/about' element={<About />} />
<Route path='/login' element={<Login />} />
<Route path='/profile/:id' element={<UserProfile name='Alex' />} />
</Routes>
</Router>
)
-13
View File
@@ -1,13 +0,0 @@
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
@@ -1,4 +0,0 @@
.container {
max-width: 1170px;
margin: 0 auto;
}
+11 -4
View File
@@ -1,13 +1,20 @@
import styles from './index.module.scss'
import Header from '../../components/header/index'
import Header from '../../components/header'
import CartList from '../../components/list/cart'
import OrderDetail from '../../components/OrderDetail'
const Cart = () => {
return (
<div className={styles.container}>
<div className={styles.container}>
<Header />
</div>
)
<h1 style={{ marginTop: 24 }}>Your Cart</h1>
<div style={{ display: 'flex', gap: 20 }}>
<CartList />
<OrderDetail />
</div>
</div>
)
}
export default Cart
+1 -1
View File
@@ -1,7 +1,7 @@
import styles from './index.module.scss'
import Header from '../../components/header/index'
import ProductList from '../../components/list/index'
import ProductList from '../../components/list/product/index'
const Catalog = () => {
return (
-12
View File
@@ -1,12 +0,0 @@
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
@@ -1,22 +0,0 @@
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
@@ -1,15 +0,0 @@
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
@@ -1,4 +0,0 @@
.container {
max-width: 1170px;
margin: 0 auto;
}