2019-09-02 14:32:57 +02:00
|
|
|
import * as React from 'react';
|
|
|
|
|
|
2019-09-04 21:12:07 +02:00
|
|
|
import InfiniteScroll from 'react-infinite-scroller';
|
|
|
|
|
|
2019-09-02 19:26:34 +02:00
|
|
|
import PostListItem from './PostListItem';
|
|
|
|
|
import Spinner from '../shared/Spinner';
|
2019-09-15 18:26:51 +02:00
|
|
|
import {
|
|
|
|
|
DangerText,
|
|
|
|
|
MutedText,
|
|
|
|
|
} from '../shared/CustomTexts';
|
2019-09-02 14:32:57 +02:00
|
|
|
|
2019-09-02 19:26:34 +02:00
|
|
|
import IPost from '../../interfaces/IPost';
|
2019-09-11 18:30:59 +02:00
|
|
|
import IPostStatus from '../../interfaces/IPostStatus';
|
2019-09-02 19:26:34 +02:00
|
|
|
|
|
|
|
|
interface Props {
|
|
|
|
|
posts: Array<IPost>;
|
2019-09-11 18:30:59 +02:00
|
|
|
postStatuses: Array<IPostStatus>;
|
2019-09-03 12:58:44 +02:00
|
|
|
areLoading: boolean;
|
2019-09-02 19:26:34 +02:00
|
|
|
error: string;
|
2019-09-04 21:12:07 +02:00
|
|
|
|
|
|
|
|
handleLoadMore(): void;
|
|
|
|
|
page: number;
|
|
|
|
|
hasMore: boolean;
|
2019-09-02 19:26:34 +02:00
|
|
|
}
|
|
|
|
|
|
2019-09-11 18:30:59 +02:00
|
|
|
const PostList = ({
|
|
|
|
|
posts,
|
|
|
|
|
postStatuses,
|
|
|
|
|
areLoading,
|
|
|
|
|
error,
|
|
|
|
|
handleLoadMore,
|
|
|
|
|
page,
|
|
|
|
|
hasMore
|
|
|
|
|
}: Props) => (
|
2019-09-16 12:22:30 +02:00
|
|
|
<div className="postList">
|
2019-09-15 18:26:51 +02:00
|
|
|
{ error ? <DangerText>{error}</DangerText> : null }
|
2019-09-04 21:12:07 +02:00
|
|
|
<InfiniteScroll
|
|
|
|
|
initialLoad={false}
|
|
|
|
|
loadMore={handleLoadMore}
|
|
|
|
|
threshold={50}
|
|
|
|
|
hasMore={hasMore}
|
2019-09-05 13:51:17 +02:00
|
|
|
loader={<Spinner key={0} />}
|
2019-09-04 21:12:07 +02:00
|
|
|
useWindow={true}
|
|
|
|
|
>
|
2019-09-06 14:36:26 +02:00
|
|
|
{
|
|
|
|
|
posts.length > 0 ?
|
|
|
|
|
posts.map((post, i) => (
|
|
|
|
|
<PostListItem
|
2019-09-12 15:51:45 +02:00
|
|
|
id={post.id}
|
2019-09-06 14:36:26 +02:00
|
|
|
title={post.title}
|
|
|
|
|
description={post.description}
|
2019-09-11 18:30:59 +02:00
|
|
|
postStatus={postStatuses.find(postStatus => postStatus.id === post.postStatusId)}
|
2019-09-06 14:36:26 +02:00
|
|
|
|
|
|
|
|
key={i}
|
|
|
|
|
/>
|
|
|
|
|
))
|
|
|
|
|
:
|
2019-09-11 21:03:40 +02:00
|
|
|
areLoading ?
|
2019-09-15 18:26:51 +02:00
|
|
|
<MutedText>Loading...</MutedText>
|
2019-09-11 21:03:40 +02:00
|
|
|
:
|
2019-09-15 18:26:51 +02:00
|
|
|
<MutedText>There are no posts.</MutedText>
|
2019-09-06 14:36:26 +02:00
|
|
|
}
|
2019-09-04 21:12:07 +02:00
|
|
|
</InfiniteScroll>
|
2019-09-03 12:58:44 +02:00
|
|
|
</div>
|
|
|
|
|
);
|
2019-09-02 14:32:57 +02:00
|
|
|
|
|
|
|
|
export default PostList;
|