Добавление Mainpage
Добавлено отображение задач на Main странице сайта
This commit is contained in:
@@ -1,19 +1,51 @@
|
||||
import { useState, useEffect } from 'react';
|
||||
import {useState, useEffect} from 'react';
|
||||
import axios from 'axios';
|
||||
import Header from './Header';
|
||||
import './css/Mainpage.css';
|
||||
|
||||
const Mainpage = () => {
|
||||
const [user, setUser] = useState(null);
|
||||
const [tasks, setTasks] = useState([]);
|
||||
const [error, setError] = useState('');
|
||||
|
||||
const [count, setCount] = useState('0');
|
||||
|
||||
useEffect(() => {
|
||||
const checkSession = async () => {
|
||||
try {
|
||||
const response = await axios.get('/api/users/my_tasks');
|
||||
setTasks(response.data.tasks || []);
|
||||
setCount(response.data.count || 0);
|
||||
} catch (err) {
|
||||
setError('Ошибка загрузки задачи');
|
||||
}
|
||||
};
|
||||
|
||||
checkSession();
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<>
|
||||
<Header />
|
||||
<div className="">
|
||||
|
||||
<div className="content-wrapper">
|
||||
{
|
||||
error && <div className="error">{error}</div>
|
||||
}
|
||||
<div className="main-layout">
|
||||
<div className="tasks-box">
|
||||
<h3>Задачи ({count})</h3>
|
||||
{tasks.length > 0 ? (
|
||||
<ul>
|
||||
{tasks.map((task, index) => (
|
||||
<li key={index}>{task.title || task.name || `Задача ${index + 1}`}</li>
|
||||
))}
|
||||
</ul>
|
||||
) : (
|
||||
<p>Нет задач</p>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
export default Mainpage;
|
||||
Reference in New Issue
Block a user