diff --git a/db.json b/db.json
index c64c11b..ab98116 100644
--- a/db.json
+++ b/db.json
@@ -21,5 +21,35 @@
"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": "Project 1",
+ "status": "work",
+ "description": "Very important!",
+ "tasks": [
+ {
+ "id":1,
+ "title":"Task 1",
+ "description": "Описание задачи"
+ },
+ {
+ "id":2,
+ "title":"Task 2",
+ "description": "Описание задачи 2"
+ }
+ ]
+ }
+ ]
+
}
diff --git a/src/App.jsx b/src/App.jsx
index a9b55c5..b391185 100644
--- a/src/App.jsx
+++ b/src/App.jsx
@@ -1,6 +1,6 @@
import styles from './App.module.scss'
import { FaRegUser } from 'react-icons/fa'
-import React from 'react'
+import React, { useState, useEffect } from 'react'
function Header() {
const handleChange = event => {
@@ -14,14 +14,127 @@ function Header() {
Store
-
-
-
-
+
)
}
+function UserMenu({ userName }) {
+ const [loggedin,setLoggedin] = useState(false);
+ const [role, setRole] = useState('user');
+
+
+ if (loggedin) {
+ return (
+
+ );
+ }
+ return (
+
+
+
+ );
+}
+
+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 (
+
+
+
Загружаем статью ...
+
+ );
+ }
+ if (error) {
+ return (
+
+
Ошибка загрузки
+
{error}
+
+
+ );
+ }
+ if (!article) {
+ return (
+
+ );
+ }
+ return (
+
+
{article.title}
+
+ Автор: {article.author}
+ Дата: {new Date(article.createDate).toLocaleDateString()}
+
+
{article.content}
+
+ );
+}
+
+function ProjectDashboard({ projects }) {
+ return (
+
+
Панель управления проектами
+ {projects.map(project => (
+
+
{project.name}
+
{project.status}
+
{project.description}
+
+ {project.tasks.length >0 && (
+
+ {project.tasks.map(task => (
+
+
{task.title}
+
{task.description}
+
+ ))}
+
+ )}
+
+ ))}
+
+ )
+}
+
function Product({ name, brand, price, imageUrl }) {
const [isLiked, setIsLiked] = React.useState(false)
@@ -78,23 +191,53 @@ function App() {
React.useEffect(() => {
getProducts()
}, [])
-
+
return (
<>
-
- {products.map(product => (
- -
-
-
- ))}
-
+ {products.length > 0 ? (
+
+ {products.map(product => (
+ -
+
+
+ ))}
+
+ ) : (
+
Список товаров пуст
+ )
+ }
>
)
}
-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 (
+ <>
+
+
+
+
+ >
+ )
+}
+
+export default App2
diff --git a/src/App.module.scss b/src/App.module.scss
index 94683dc..72fa34f 100644
--- a/src/App.module.scss
+++ b/src/App.module.scss
@@ -10,7 +10,14 @@
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;
@@ -61,6 +68,14 @@
.container {
max-width: 1220px;
margin: 0 auto;
+ .article {
+ text-align: center;
+ background-color: lightgray;
+ }
+ .error {
+ text-align: center;
+ background-color: lightcoral;
+ }
}
.list {