-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpost.tsx
46 lines (41 loc) · 1.16 KB
/
post.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import React from 'react';
import { useRouter } from 'next/router';
import ErrorPage from 'next/error';
import Layout from 'components/Layout/Layout';
import PostListContainer from 'components/PostListContainer/post-list-container';
import Pagination from 'components/Pagination/pagination';
import { Container } from 'next/app';
import { PagedAllPosts } from '../utils/api';
import { Post } from 'types/types';
type Props = {
posts: Post[];
page: number;
lastPage: number;
};
export default function PostList({ posts, page, lastPage }: Props) {
const router = useRouter();
return (
<Layout title='Posts'>
<Container>
{router.isFallback ? (
<ErrorPage statusCode={404} />
) : (
<PostListContainer title={`Post`} posts={posts} />
)}
<Pagination basePath='/post' page={page} lastPage={lastPage} />
</Container>
</Layout>
);
}
//TODO: API parse from strapi
export async function getServerSideProps({ query }) {
const page = parseInt(query.page) || 1;
const data = await PagedAllPosts(page);
return {
props: {
posts: data.posts,
page,
lastPage: data.lastPage,
},
};
}