2019-09-02 14:32:57 +02:00
|
|
|
import * as React from 'react';
|
2022-06-05 11:40:43 +02:00
|
|
|
import I18n from 'i18n-js';
|
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,
|
2019-09-19 16:42:43 +02:00
|
|
|
CenteredMutedText,
|
2019-09-15 18:26:51 +02:00
|
|
|
} 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
|
|
|
|
|
|
|
|
hasMore: boolean;
|
2019-09-27 16:57:23 +02:00
|
|
|
handleLoadMore(): void;
|
|
|
|
|
|
|
|
|
|
isLoggedIn: boolean;
|
|
|
|
|
authenticityToken: string;
|
2019-09-02 19:26:34 +02:00
|
|
|
}
|
|
|
|
|
|
2019-09-11 18:30:59 +02:00
|
|
|
const PostList = ({
|
|
|
|
|
posts,
|
|
|
|
|
postStatuses,
|
|
|
|
|
areLoading,
|
|
|
|
|
error,
|
2019-09-27 16:57:23 +02:00
|
|
|
hasMore,
|
2019-09-11 18:30:59 +02:00
|
|
|
handleLoadMore,
|
2019-09-27 16:57:23 +02:00
|
|
|
isLoggedIn,
|
|
|
|
|
authenticityToken,
|
2019-09-11 18:30:59 +02:00
|
|
|
}: 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-27 16:57:23 +02:00
|
|
|
likesCount={post.likesCount}
|
|
|
|
|
liked={post.liked}
|
2019-09-21 11:17:58 +02:00
|
|
|
commentsCount={post.commentsCount}
|
2019-09-06 14:36:26 +02:00
|
|
|
|
2019-09-27 16:57:23 +02:00
|
|
|
isLoggedIn={isLoggedIn}
|
|
|
|
|
authenticityToken={authenticityToken}
|
|
|
|
|
|
2019-09-06 14:36:26 +02:00
|
|
|
key={i}
|
|
|
|
|
/>
|
|
|
|
|
))
|
|
|
|
|
:
|
2022-06-05 11:40:43 +02:00
|
|
|
areLoading ? <p></p> : <CenteredMutedText>{I18n.t('board.posts_list.empty')}</CenteredMutedText>
|
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;
|