Compare commits

..

10 Commits

22 changed files with 4522 additions and 3312 deletions
+1096 -83
View File
File diff suppressed because it is too large Load Diff
+3 -1
View File
@@ -11,10 +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",
"sass-embedded": "^1.89.2"
"react-router-dom": "^7.7.1"
},
"devDependencies": {
"@eslint/js": "^9.25.0",
@@ -25,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"
}
}
-17
View File
@@ -1,17 +0,0 @@
import styles from './App.module.scss'
import Header from './components/header'
import ProductList from './components/list'
import Timer from './components/timer'
const App = () => {
return (
<div className={styles.container}>
<Header />
<Timer />
<ProductList />
</div>
)
}
export default App
+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;
+8 -3
View File
@@ -4,6 +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 } from 'react-router-dom'
const Header = () => {
return (
@@ -12,13 +13,13 @@ const Header = () => {
<nav>
<ul>
<li>
<a href='#'>Home</a>
<Link to={{ pathname: '/' }}>Home</Link>
</li>
<li>
<a href='#'>Contact</a>
<Link to={{ pathname: '/contact' }}>Contact</Link>
</li>
<li>
<a href='#'>About</a>
<Link to={{ pathname: '/about' }}>About</Link>
</li>
<li>
<a href='#'>Sign Up</a>
@@ -31,10 +32,14 @@ const Header = () => {
</div>
<div className={styles.buttons}>
<button>
<Link to={{ pathname: '/wishlist' }}>
<img src={WishlistIcon} alt='' />
</Link>
</button>
<button>
<Link to={{ pathname: '/cart' }}>
<img src={CartIcon} alt='' />
</Link>
</button>
<button>
<img src={UserIcon} alt='' />
+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
-21
View File
@@ -1,21 +0,0 @@
import React, { useState, useEffect } from 'react'
import styles from './index.module.scss'
const Timer = () => {
const [seconds, setSeconds] = useState(0);
useEffect(() => {
const interval = setInterval(() => {
setSeconds(prev => prev + 1);
}, 1000);
return () => {
clearInterval(interval);
};
}, []);
return (
<div>
<h2>Прошло секунд: {seconds}</h2>
</div>
);
}
export default Timer
+16 -5
View File
@@ -1,9 +1,20 @@
import { StrictMode } from 'react'
import { createRoot } from 'react-dom/client'
import App from './App.jsx'
import {
BrowserRouter as Router,
Routes,
Route,
Navigate,
} from 'react-router-dom'
import Catalog from './pages/catalog'
import Cart from './pages/cart'
createRoot(document.getElementById('root')).render(
<StrictMode>
<App />
</StrictMode>
<Router>
<Routes>
<Route path='/' element={<Navigate to='/catalog' replace />} />
<Route path='/catalog' element={<Catalog />} />
<Route path='/cart' element={<Cart />} />
</Routes>
</Router>
)
+20
View File
@@ -0,0 +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 (
<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
@@ -1,5 +1,3 @@
@use './assets/styles/variables' as *;
.container {
max-width: 1170px;
margin: 0 auto;
+15
View File
@@ -0,0 +1,15 @@
import styles from './index.module.scss'
import Header from '../../components/header/index'
import ProductList from '../../components/list/product/index'
const Catalog = () => {
return (
<div className={styles.container}>
<Header />
<ProductList />
</div>
)
}
export default Catalog
+4
View File
@@ -0,0 +1,4 @@
.container {
max-width: 1170px;
margin: 0 auto;
}