Files
astuto/app/javascript/components/Board/PostList.tsx

63 lines
1.4 KiB
TypeScript
Raw Normal View History

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-02 14:32:57 +02:00
2019-09-02 19:26:34 +02:00
import IPost from '../../interfaces/IPost';
import IPostStatus from '../../interfaces/IPostStatus';
2019-09-02 19:26:34 +02:00
interface Props {
posts: Array<IPost>;
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
}
const PostList = ({
posts,
postStatuses,
areLoading,
error,
handleLoadMore,
page,
hasMore
}: Props) => (
2019-09-03 12:58:44 +02:00
<div className="box postList">
{ error ? <span className="error">{error}</span> : 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}
postStatus={postStatuses.find(postStatus => postStatus.id === post.postStatusId)}
2019-09-06 14:36:26 +02:00
key={i}
/>
))
:
areLoading ?
<span className="infoText">Loading...</span>
:
<span className="infoText text-muted">There are no posts.</span>
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;