Compare commits
13 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| a72a5bc640 | |||
| c44b4a283c | |||
| c5760f27b4 | |||
| ca519f47b1 | |||
| 2812645834 | |||
| b8e88a4866 | |||
| 102da1ad75 | |||
| a84b1972e7 | |||
| 2ba1a63832 | |||
| 9367009fdf | |||
| e0ba3a0f45 | |||
| df845c3ae7 | |||
| 7a5be1d876 |
@@ -1,22 +1,55 @@
|
||||
{
|
||||
"advertisement": [
|
||||
"products": [
|
||||
{
|
||||
"id": 1,
|
||||
"name": "Sneakers Red & White 2025",
|
||||
"brand": "NIKE",
|
||||
"price": 38.0,
|
||||
"imageUrl": "./src/assets/images/sneakers-image.jpg"
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"name": "Sneakers Red & White 2025",
|
||||
"brand": "NIKE",
|
||||
"price": 38.0,
|
||||
"imageUrl": "./src/assets/images/sneakers-image.jpg"
|
||||
},
|
||||
{
|
||||
"id": 3,
|
||||
"name": "Sneakers Red & White 2025",
|
||||
"brand": "NIKE",
|
||||
"price": 38.0,
|
||||
"imageUrl": "./src/assets/images/sneakers-image.jpg"
|
||||
}
|
||||
],
|
||||
"articles": [
|
||||
{
|
||||
"id": 1,
|
||||
"title": "Статья 1",
|
||||
"author": "Иванов Иван Иванович",
|
||||
"createDate": "2020-01-15",
|
||||
"content": "Основной текст статьи"
|
||||
}
|
||||
],
|
||||
"projects": [
|
||||
{
|
||||
"id":1,
|
||||
"name":"Продаю голодного кота!",
|
||||
"description":"Кот бегемот. Прокормить невозможно!",
|
||||
"url":"https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTqlWZ1N8qSUMB1HuqN6DjnXP_D5NRGNJ-W6zLZqP-Y9Q&s=10"
|
||||
},
|
||||
{
|
||||
"id":2,
|
||||
"name":"Продаю машину",
|
||||
"description":"Не бита не крашена без пробега по РФ",
|
||||
"url":"https://s0.rbk.ru/v6_top_pics/media/img/9/33/347054091401339.jpeg"
|
||||
},
|
||||
{
|
||||
"id":3,
|
||||
"name":"Продаю квартиру",
|
||||
"description":"Центр города, с видом на море.",
|
||||
"url":"https://hoff.ru/upload/medialibrary/11c/11cb47c1d2d4f248b7dde57f479f2d47.jpg"
|
||||
"name": "Project 1",
|
||||
"status": "work",
|
||||
"description": "Very important!",
|
||||
"tasks": [
|
||||
{
|
||||
"id":1,
|
||||
"title":"Task 1",
|
||||
"description": "Описание задачи"
|
||||
},
|
||||
{
|
||||
"id":2,
|
||||
"title":"Task 2",
|
||||
"description": "Описание задачи 2"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+13
@@ -5,6 +5,19 @@
|
||||
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Vite + React</title>
|
||||
<style>
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
|
||||
font-family: Arial, Helvetica, sans-serif;
|
||||
}
|
||||
|
||||
body {
|
||||
background-color: rgb(249, 249, 249);
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div id="root"></div>
|
||||
|
||||
Generated
+382
-561
File diff suppressed because it is too large
Load Diff
+28
-28
@@ -1,30 +1,30 @@
|
||||
{
|
||||
"name": "store-client",
|
||||
"private": true,
|
||||
"version": "0.0.0",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"server": "json-server db.json",
|
||||
"dev": "vite",
|
||||
"build": "vite build",
|
||||
"lint": "eslint .",
|
||||
"preview": "vite preview"
|
||||
},
|
||||
"dependencies": {
|
||||
"json-server": "^1.0.0-beta.15",
|
||||
"react": "^19.1.0",
|
||||
"react-dom": "^19.1.0",
|
||||
"react-router-dom": "^7.18.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@eslint/js": "^9.25.0",
|
||||
"@types/react": "^19.1.2",
|
||||
"@types/react-dom": "^19.1.2",
|
||||
"@vitejs/plugin-react": "^4.4.1",
|
||||
"eslint": "^9.25.0",
|
||||
"eslint-plugin-react-hooks": "^5.2.0",
|
||||
"eslint-plugin-react-refresh": "^0.4.19",
|
||||
"globals": "^16.0.0",
|
||||
"vite": "^6.3.5"
|
||||
}
|
||||
"name": "store-client",
|
||||
"private": true,
|
||||
"version": "0.0.0",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"server": "json-server --watch db.json --port 8000",
|
||||
"build": "vite build",
|
||||
"lint": "eslint .",
|
||||
"preview": "vite preview"
|
||||
},
|
||||
"dependencies": {
|
||||
"react": "^19.1.0",
|
||||
"react-dom": "^19.1.0",
|
||||
"react-icons": "^5.5.0",
|
||||
"sass-embedded": "^1.89.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@eslint/js": "^9.25.0",
|
||||
"@types/react": "^19.1.2",
|
||||
"@types/react-dom": "^19.1.2",
|
||||
"@vitejs/plugin-react": "^4.4.1",
|
||||
"eslint": "^9.25.0",
|
||||
"eslint-plugin-react-hooks": "^5.2.0",
|
||||
"eslint-plugin-react-refresh": "^0.4.19",
|
||||
"globals": "^16.0.0",
|
||||
"vite": "^6.3.5"
|
||||
}
|
||||
}
|
||||
|
||||
+235
-6
@@ -1,14 +1,243 @@
|
||||
import { RouterProvider } from "react-router-dom";
|
||||
import { router } from './router'
|
||||
import Header from './components/Header/index'
|
||||
import styles from './App.module.scss'
|
||||
import { FaRegUser } from 'react-icons/fa'
|
||||
import React, { useState, useEffect } from 'react'
|
||||
|
||||
function Header() {
|
||||
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>
|
||||
<UserMenu isLoggedin={true} userName="Bob" role="user" />
|
||||
</header>
|
||||
)
|
||||
}
|
||||
|
||||
function UserMenu({ userName }) {
|
||||
const [loggedin,setLoggedin] = useState(false);
|
||||
const [role, setRole] = useState('user');
|
||||
|
||||
|
||||
if (loggedin) {
|
||||
return (
|
||||
<div className="user-menu">
|
||||
<nav>
|
||||
<a href="/settings">Настройки</a>
|
||||
{role === "admin" && <a href="/admin">Панель администратора</a>}
|
||||
<div>
|
||||
<FaRegUser size={24} color='#3258e3' />
|
||||
<button>Profile</button>
|
||||
<button onClick={() => setLoggedin(false)}>Exit</button>
|
||||
</div>
|
||||
</nav>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
return (
|
||||
<div className="login-form">
|
||||
<button onClick={() => setLoggedin(true)}>Войти</button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function ArticleViewer({ articleId }) {
|
||||
const [article,setArticle] = useState(null);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [error, setError] = useState(null);
|
||||
|
||||
useEffect(() => {
|
||||
const fetchArticle = async () => {
|
||||
try {
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
const responce = await fetch(`http://localhost:8000/articles/${articleId}`)
|
||||
|
||||
if(!responce.ok) {
|
||||
throw new Error('Не удалось загрузить статью');
|
||||
}
|
||||
|
||||
const data = await responce.json();
|
||||
setArticle(data);
|
||||
} catch(err) {
|
||||
setError(err.message);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}
|
||||
fetchArticle();
|
||||
},[articleId]);
|
||||
|
||||
if (loading) {
|
||||
return (
|
||||
<div className={styles.loading}>
|
||||
<div className="spinner"></div>
|
||||
<p>Загружаем статью ...</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
if (error) {
|
||||
return (
|
||||
<div className={styles.error}>
|
||||
<h3>Ошибка загрузки</h3>
|
||||
<p>{error}</p>
|
||||
<button onClick={()=>window.location.reload()}>Попробовать еще</button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
if (!article) {
|
||||
return (
|
||||
<div className={styles.empty}>
|
||||
<p>Статья не найдена</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
return (
|
||||
<div className={styles.article}>
|
||||
<h1>{article.title}</h1>
|
||||
<div className="article-meta">
|
||||
<span>Автор: {article.author}</span>
|
||||
<span>Дата: {new Date(article.createDate).toLocaleDateString()}</span>
|
||||
</div>
|
||||
<div className="article-body">{article.content}</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function ProjectDashboard({ projects }) {
|
||||
return (
|
||||
<div className={styles.dashboard}>
|
||||
<h1>Панель управления проектами</h1>
|
||||
{projects.map(project => (
|
||||
<div key={project.id} className={styles.project}>
|
||||
<h2>{project.name}</h2>
|
||||
<span className={styles.project_status}>{project.status}</span>
|
||||
<p className={styles.project_description}>{project.description}</p>
|
||||
|
||||
{project.tasks.length >0 && (
|
||||
<div className={styles.tasks}>
|
||||
{project.tasks.map(task => (
|
||||
<div className={styles.task_card} key={task.id}>
|
||||
<h4>{task.title}</h4>
|
||||
<p>{task.description}</p>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function Product({ name, brand, price, imageUrl }) {
|
||||
const [isLiked, setIsLiked] = React.useState(false)
|
||||
|
||||
const toggleLike = () => {
|
||||
setIsLiked(!isLiked)
|
||||
}
|
||||
|
||||
function handleAddClick() {
|
||||
console.log('Working!')
|
||||
}
|
||||
|
||||
return (
|
||||
<div className={styles.product}>
|
||||
<img src={imageUrl} alt='' />
|
||||
<div className={styles.content}>
|
||||
<div className={styles.title}>
|
||||
<h4>{name}</h4>
|
||||
<div className={styles.actions}>
|
||||
<button
|
||||
className={styles.likeButton}
|
||||
onClick={toggleLike}
|
||||
aria-label={isLiked ? 'Убрать лайк' : 'Добавить лайк'}
|
||||
>
|
||||
<svg
|
||||
width='18'
|
||||
height='18'
|
||||
viewBox='0 0 24 24'
|
||||
fill={isLiked ? 'red' : 'none'}
|
||||
stroke={isLiked ? 'red' : 'currentColor'}
|
||||
strokeWidth='1.5'
|
||||
>
|
||||
<path d='M12 21.35L10.55 20.03C5.4 15.36 2 12.28 2 8.5C2 5.42 4.42 3 7.5 3C9.24 3 10.91 3.81 12 5.09C13.09 3.81 14.76 3 16.5 3C19.58 3 22 5.42 22 8.5C22 12.28 18.6 15.36 13.45 20.04L12 21.35Z' />
|
||||
</svg>
|
||||
</button>
|
||||
<button onClick={handleAddClick}>+</button>
|
||||
</div>
|
||||
</div>
|
||||
<p className={styles.description}>{brand}</p>
|
||||
<p className={styles.price}>${price}</p>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function App() {
|
||||
const [products, setProducts] = React.useState([])
|
||||
|
||||
const getProducts = async () => {
|
||||
const response = await fetch('http://localhost:8000/products')
|
||||
const data = await response.json()
|
||||
setProducts(data)
|
||||
}
|
||||
|
||||
React.useEffect(() => {
|
||||
getProducts()
|
||||
}, [])
|
||||
|
||||
return (
|
||||
<>
|
||||
<Header />
|
||||
<RouterProvider router={router} />
|
||||
<div className={styles.container}>
|
||||
<Header />
|
||||
</div>
|
||||
<div className={styles.container}>
|
||||
{products.length > 0 ? (
|
||||
<ul className={styles.list}>
|
||||
{products.map(product => (
|
||||
<li key={product.id}>
|
||||
<Product {...product} />
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
) : (
|
||||
<h3>Список товаров пуст</h3>
|
||||
)
|
||||
}
|
||||
</div>
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
export default App
|
||||
function App2() {
|
||||
const [projects, setProjects] = React.useState([])
|
||||
|
||||
const getProjects = async () => {
|
||||
const response = await fetch('http://localhost:8000/projects')
|
||||
const data = await response.json()
|
||||
setProjects(data)
|
||||
}
|
||||
|
||||
React.useEffect(() => {
|
||||
getProjects()
|
||||
}, [])
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className={styles.container}>
|
||||
<Header />
|
||||
</div>
|
||||
<div className={styles.container}>
|
||||
<ProjectDashboard projects={projects} />
|
||||
</div>
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
export default App2
|
||||
|
||||
@@ -0,0 +1,150 @@
|
||||
@use './assets/styles/variables' as *;
|
||||
|
||||
.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;
|
||||
|
||||
nav {
|
||||
display: flex;
|
||||
justify-content: space-around;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
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;
|
||||
.article {
|
||||
text-align: center;
|
||||
background-color: lightgray;
|
||||
}
|
||||
.error {
|
||||
text-align: center;
|
||||
background-color: lightcoral;
|
||||
}
|
||||
}
|
||||
|
||||
.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;
|
||||
}
|
||||
|
||||
.actions {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 5px;
|
||||
|
||||
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;
|
||||
@@ -1,49 +0,0 @@
|
||||
import styles from './index.module.css'
|
||||
import { useState, useEffect } from 'react'
|
||||
|
||||
export default function() {
|
||||
const [data,setData] = useState([]);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [error, setError] = useState(null);
|
||||
|
||||
useEffect(()=>{
|
||||
const controller = new AbortController();
|
||||
const fetchData = async () => {
|
||||
try {
|
||||
const response = await fetch('http://localhost:3000/advertisement', {
|
||||
signal: controller.signal // Link the abort signal to the fetch request
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP error! Status: ${response.status}`);
|
||||
}
|
||||
|
||||
const result = await response.json();
|
||||
setData(result);
|
||||
} catch (err) {
|
||||
if (err.name !== 'AbortError') {
|
||||
setError(err.message);
|
||||
}
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
fetchData();
|
||||
return () => controller.abort();
|
||||
},[]);
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className={styles.container}>
|
||||
{data.map(item => <div key={item.id} className={styles.card}>
|
||||
<h3>{item.name}</h3>
|
||||
<div
|
||||
className={styles.img}
|
||||
style={{backgroundImage: `url(${item.url})`}}>
|
||||
</div>
|
||||
<p>{item.description}</p>
|
||||
</div>)}
|
||||
</div>
|
||||
</>
|
||||
)
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
.container {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
flex-wrap: wrap;
|
||||
column-gap: 10px;
|
||||
}
|
||||
.card {
|
||||
min-width: 100px;
|
||||
min-height: 200px;
|
||||
/*border: 1px solid black;*/
|
||||
border-radius: 10px;
|
||||
box-shadow: 2px 2px 5px 2px black;
|
||||
}
|
||||
.card h3 {
|
||||
text-align: center;
|
||||
}
|
||||
.card p {
|
||||
margin: 5px 10px;
|
||||
}
|
||||
.img {
|
||||
width: 200px;
|
||||
height: 200px;
|
||||
border-radius: 5px;
|
||||
background-size: cover;
|
||||
background-position: center;
|
||||
margin: 0 auto;
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
import styles from './index.module.css'
|
||||
|
||||
export default function() {
|
||||
return (
|
||||
<>
|
||||
<header>
|
||||
<nav>
|
||||
<ul className={styles.container}>
|
||||
<li><a href="/">Главная</a></li>
|
||||
<li><a href="/favorite">Избранное</a></li>
|
||||
<li><a href="/profile">Профиль</a></li>
|
||||
</ul>
|
||||
</nav>
|
||||
</header>
|
||||
</>
|
||||
)
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
.container {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
list-style: none;
|
||||
column-gap: 1em;
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
import { StrictMode } from 'react'
|
||||
import { createRoot } from 'react-dom/client'
|
||||
// удаляем import './index.css'
|
||||
import App from './App.jsx'
|
||||
|
||||
createRoot(document.getElementById('root')).render(
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
export default function() {
|
||||
return (
|
||||
<>
|
||||
<h1>Error</h1>
|
||||
</>
|
||||
)
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
export default function() {
|
||||
return (
|
||||
<>
|
||||
<h1>Favorites</h1>
|
||||
</>
|
||||
)
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
import AdvList from '../components/AdvList/index'
|
||||
|
||||
export default function() {
|
||||
return (
|
||||
<>
|
||||
<h1>Main</h1>
|
||||
<div>
|
||||
<AdvList />
|
||||
</div>
|
||||
</>
|
||||
)
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
export default function() {
|
||||
return (
|
||||
<>
|
||||
<h1>Profile</h1>
|
||||
</>
|
||||
)
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
import { createBrowserRouter } from 'react-router-dom'
|
||||
import MainPage from './pages/Main'
|
||||
import ErrorPage from './pages/Error'
|
||||
import FavoritePage from './pages/Favorites'
|
||||
import ProfilePage from './pages/Profile'
|
||||
|
||||
export const router = createBrowserRouter([
|
||||
{
|
||||
path: "/",
|
||||
element: <MainPage />,
|
||||
errorElement: <ErrorPage />,
|
||||
children: [
|
||||
{
|
||||
path: "/",
|
||||
element: <MainPage />,
|
||||
loader: async () => fetch("/api/dashboard-data"),
|
||||
},
|
||||
]
|
||||
},
|
||||
{
|
||||
path: "/favorite",
|
||||
element: <FavoritePage />
|
||||
},
|
||||
{
|
||||
path: "/profile",
|
||||
element: <ProfilePage />
|
||||
}
|
||||
]);
|
||||
Reference in New Issue
Block a user