Compare commits
2 Commits
5d2dc9f7c5
...
0fe463e33a
Author | SHA1 | Date | |
---|---|---|---|
|
0fe463e33a | ||
|
34e30fbaba |
5
@types/assets.d.ts
vendored
Normal file
5
@types/assets.d.ts
vendored
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
declare module '*.png' {
|
||||||
|
const imagePath: string;
|
||||||
|
|
||||||
|
export default imagePath;
|
||||||
|
}
|
@ -1,8 +1,45 @@
|
|||||||
import React from 'react';
|
import React, { useEffect, useState } from 'react';
|
||||||
import Heading from '../../components/heading';
|
import Heading from '../../components/heading';
|
||||||
|
|
||||||
const ListPage = (): React.ReactElement => {
|
const ListPage = (): React.ReactElement => {
|
||||||
return <Heading>List Page New</Heading>;
|
const [error, setError] = useState<string>(null);
|
||||||
|
const [data, setData] = useState<Array<{ id: number; title: string; description: string }>>();
|
||||||
|
const [isLoading, setIsLoading] = useState(true);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const handle = async () => {
|
||||||
|
setIsLoading(true);
|
||||||
|
try {
|
||||||
|
const res = await fetch('/api/list');
|
||||||
|
const data = await res.json();
|
||||||
|
if (res.ok) {
|
||||||
|
setData(data);
|
||||||
|
} else {
|
||||||
|
setError(data.message);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
setError(e.message);
|
||||||
|
} finally {
|
||||||
|
setIsLoading(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
handle();
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Heading>List Page New</Heading>
|
||||||
|
{isLoading && <div>Loading...</div>}
|
||||||
|
{error && <div>Произошла ошибка</div>}
|
||||||
|
{data?.map((item) => {
|
||||||
|
return (
|
||||||
|
<div key={item.id}>
|
||||||
|
{item.id}: {item.title} - {item.description}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</>
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default ListPage;
|
export default ListPage;
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { getNavigationValue } from '@brojs/cli';
|
import { getNavigationValue } from '@brojs/cli';
|
||||||
import { HeaderContainer, NavContainer, NavItem, NavLink } from './index.style';
|
import { HeaderContainer, NavContainer, NavItem, NavLink } from './index.style';
|
||||||
|
import Logo from './logo/logo';
|
||||||
|
|
||||||
const navigations: Array<{ name: string; href: string }> = [
|
const navigations: Array<{ name: string; href: string }> = [
|
||||||
{
|
{
|
||||||
@ -16,6 +17,7 @@ const navigations: Array<{ name: string; href: string }> = [
|
|||||||
const Header = (): React.ReactElement => {
|
const Header = (): React.ReactElement => {
|
||||||
return (
|
return (
|
||||||
<HeaderContainer>
|
<HeaderContainer>
|
||||||
|
<Logo />
|
||||||
<NavContainer>
|
<NavContainer>
|
||||||
{navigations.map((item) => {
|
{navigations.map((item) => {
|
||||||
return (
|
return (
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
import styled from '@emotion/styled';
|
import styled from '@emotion/styled';
|
||||||
import { NavLink as NavLinkBase } from 'react-router-dom';
|
import { NavLink as NavLinkBase } from 'react-router-dom';
|
||||||
|
|
||||||
export const HeaderContainer = styled('header')``;
|
export const HeaderContainer = styled('header')`
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
`;
|
||||||
|
|
||||||
export const NavContainer = styled.nav`
|
export const NavContainer = styled.nav`
|
||||||
display: flex;
|
display: flex;
|
||||||
|
17
src/container/main/components/layout/logo/logo.tsx
Normal file
17
src/container/main/components/layout/logo/logo.tsx
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import styled from '@emotion/styled';
|
||||||
|
import logoPng from './logo2.png';
|
||||||
|
|
||||||
|
const LogoStyled = styled.img`
|
||||||
|
width: 24px;
|
||||||
|
height: 24px;
|
||||||
|
padding: 8px;
|
||||||
|
`;
|
||||||
|
|
||||||
|
// ${__webpack_public_path__}/remote-assets/logo.png
|
||||||
|
|
||||||
|
const Logo = () => {
|
||||||
|
return <LogoStyled src={logoPng} alt={'logo'} />;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default Logo;
|
BIN
src/container/main/components/layout/logo/logo2.png
Normal file
BIN
src/container/main/components/layout/logo/logo2.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 90 KiB |
@ -1,3 +1,12 @@
|
|||||||
const router = require('express').Router();
|
const router = require('express').Router();
|
||||||
|
const listRouter = require('./list');
|
||||||
module.exports = router;
|
module.exports = router;
|
||||||
|
|
||||||
|
const delay =
|
||||||
|
(ms = 1000) =>
|
||||||
|
(req, res, next) => {
|
||||||
|
setTimeout(next, ms);
|
||||||
|
};
|
||||||
|
|
||||||
|
router.use(delay());
|
||||||
|
router.use('/list', listRouter);
|
||||||
|
7
stubs/api/list/data/list.json
Normal file
7
stubs/api/list/data/list.json
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
[
|
||||||
|
{ "id": 1, "title": "title", "description": "description" },
|
||||||
|
{ "id": 2, "title": "title", "description": "description" },
|
||||||
|
{ "id": 3, "title": "title", "description": "description" },
|
||||||
|
{ "id": 4, "title": "title", "description": "description" },
|
||||||
|
{ "id": 5, "title": "title", "description": "description" }
|
||||||
|
]
|
12
stubs/api/list/index.js
Normal file
12
stubs/api/list/index.js
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
const router = require('express').Router();
|
||||||
|
|
||||||
|
module.exports = router;
|
||||||
|
|
||||||
|
const data = require('./data/list.json');
|
||||||
|
|
||||||
|
router.get('/', (req, res) => {
|
||||||
|
res.send(data);
|
||||||
|
// res.status(500).send({
|
||||||
|
// message: 'Internal server error'
|
||||||
|
// });
|
||||||
|
});
|
Loading…
Reference in New Issue
Block a user