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
17 changed files with 1332 additions and 174 deletions
+1050 -91
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.6.3",
"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,6 +1,6 @@
import styles from './index.module.scss'
import WishIcon from '../../assets/icons/wish.svg'
import WishIcon from '../../../assets/icons/wish.svg'
const ProductCard = ({ name, price, imageUrl }) => {
return (
@@ -1,4 +1,4 @@
@use '../../assets/styles/variables' as *;
@use '../../../assets/styles/variables' as *;
.product {
display: flex;
+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%;
}
-75
View File
@@ -1,75 +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)
React.useEffect(() => {
let cancelled = false
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 -2
View File
@@ -3,7 +3,7 @@ import {
BrowserRouter as Router,
Routes,
Route,
Navigate, // 1. Импортируем компонент для редиректа
Navigate,
} from 'react-router-dom'
import Catalog from './pages/catalog'
@@ -12,7 +12,6 @@ import Cart from './pages/cart'
createRoot(document.getElementById('root')).render(
<Router>
<Routes>
{/* 2. Добавляем редирект с корневого пути */}
<Route path='/' element={<Navigate to='/catalog' replace />} />
<Route path='/catalog' element={<Catalog />} />
<Route path='/cart' element={<Cart />} />
+16 -1
View File
@@ -1,5 +1,20 @@
import styles from './index.module.scss'
import Header from '../../components/header'
import CartList from '../../components/list/cart'
import OrderDetail from '../../components/OrderDetail'
const Cart = () => {
return <></>
return (
<div className={styles.container}>
<Header />
<h1 style={{ marginTop: 24 }}>Your Cart</h1>
<div style={{ display: 'flex', gap: 20 }}>
<CartList />
<OrderDetail />
</div>
</div>
)
}
export default Cart
+4
View File
@@ -0,0 +1,4 @@
.container {
max-width: 1170px;
margin: 0 auto;
}
+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 (