Добавление Mainpage

Добавлено отображение задач на Main странице сайта
This commit is contained in:
Dozzy7528
2026-02-15 20:02:33 +03:00
parent 29c580d26d
commit 88e1e4f0f3
2 changed files with 92 additions and 7 deletions

View File

@@ -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;