FILE / Unmei/Frontend

src/components/News/Post.tsx

Исходный файл и его история в репозитории.
FILE 9ff47797201a1116d032e330ffcc4d0b7c1b8ff5
Files
Frontend/src/components/News/Post.tsx
T
2020-04-29 02:50:07 +03:00

50 lines
1.2 KiB
TypeScript

import React from "react";
import {getPost} from "../../api/news";
import Loading from "../Loading";
import NotFoundError from "../NotFoundError";
import './Post.sass';
type Props = {
match: { params: { postId: number } }
};
type State = {
post: PostType | null
code: number
};
class Post extends React.Component<Props, State> {
state: State = {
post: null, code: 0
};
componentDidMount(): void {
const { match: { params: { postId }} } = this.props;
getPost(postId).then(post => {
this.setState({ post })
}).catch((error: ApiError) => {
this.setState({ code: error.code })
});
}
render() {
const { post, code } = this.state;
if(code === 100) return <NotFoundError/>;
if(!post) return <Loading/>;
return (
<div className={'Post'}>
<div className={'Post__Title'}>{post.title}</div>
<div className="Post__Content">
{post.full_post}
</div>
<div className="Post__Footer">
Автор: {post.author}
</div>
</div>
)
}
}
export default Post;