Изменения фронта

This commit is contained in:
urec56 2024-02-08 13:59:12 +03:00
commit b9f347253d
6 changed files with 61 additions and 10 deletions

View file

@ -8,7 +8,7 @@ import AppZalupa from "./components/layout/AppZalupa.jsx";
export default function App() {
return <Layout>
<AppHeader />
<AppZalupa />
{/*<AppZalupa />*/}
<Layout>
<AppContent />
</Layout>

View file

@ -1,5 +1,10 @@
export const users= await fetch('http://localhost:8000/api/users', {
method: "GET"
import {cryptoData, cryptoAssets} from "./data.js";
export function fakeFetchCrypto() {
return new Promise(resolve => {
setTimeout(() => {
resolve(cryptoData)
}, 2000)
})
.then(function (response) {
return response.json();
@ -11,5 +16,30 @@ export const users= await fetch('http://localhost:8000/api/users', {
.catch(function (error) {
console.log('Ошибка:', error);
});
}
export function fetchAssets() {
return new Promise(resolve => {
setTimeout(() => {
resolve(cryptoAssets)
}, 2000)
})
}
export async function fetchUsers() {
return (fetch('http://localhost:8000/api/users', {
method: "GET"
})
.then(function (res) {
return res.json();
})
.then(function (data) {
console.log(data);
return data;
})
.catch(function (err) {
console.log('Ошибка:', err);
})
)
}

View file

@ -1,5 +1,6 @@
import {Layout} from "antd";
import {users} from "../../api.js";
import {Layout, Spin} from "antd";
import {fakeFetchCrypto, fetchAssets, fetchUsers} from "../../api.js";
import {useEffect, useState} from "react";
@ -12,6 +13,26 @@ const contentStyle = {
padding: '1rem',
};
export default function () {
return (<Layout.Content style={contentStyle}>users</Layout.Content>)
export default function AppContent() {
const [loading, setLoading] = useState(true)
const [users, setUsers] = useState([])
const [assets, setAssets] = useState([])
useEffect(() => {
async function preload() {
const result = await fetchUsers()
setUsers(result)
setLoading(false)
}
preload()
}, []);
if (loading) {
return <Spin fullscreen/>
}
return (<Layout.Content style={contentStyle}>{users[0].email}</Layout.Content>)
}

View file

@ -6,6 +6,6 @@ const footerStyle = {
backgroundColor: '#4096ff',
};
export default function () {
export default function AppFooter() {
return (<Layout.Footer style={footerStyle}>Footer</Layout.Footer>)
}

View file

@ -8,6 +8,6 @@ const headerStyle = {
backgroundColor: '#4096ff',
};
export default function () {
export default function AppHeader() {
return (<Layout.Header style={headerStyle}>Header</Layout.Header>)
}

View file

@ -5,7 +5,7 @@ import { Avatar, Button, Skeleton, List} from 'antd';
const count = 3;
const fakeDataUrl = `http://localhost:8000/api/users`;
export default function () {
export default function AppZalupa() {
const [initLoading, setInitLoading] = useState(true);
const [loading, setLoading] = useState(false);
const [data, setData] = useState([]);