mirror of
https://github.com/astuto/astuto.git
synced 2025-12-15 11:17:49 +01:00
64 lines
1.4 KiB
TypeScript
64 lines
1.4 KiB
TypeScript
import * as React from 'react';
|
|
|
|
import InfiniteScroll from 'react-infinite-scroller';
|
|
|
|
import PostListItem from './PostListItem';
|
|
import Spinner from '../shared/Spinner';
|
|
import {
|
|
DangerText,
|
|
CenteredMutedText,
|
|
} from '../shared/CustomTexts';
|
|
|
|
import IPost from '../../interfaces/IPost';
|
|
import IPostStatus from '../../interfaces/IPostStatus';
|
|
|
|
interface Props {
|
|
posts: Array<IPost>;
|
|
postStatuses: Array<IPostStatus>;
|
|
areLoading: boolean;
|
|
error: string;
|
|
|
|
handleLoadMore(): void;
|
|
page: number;
|
|
hasMore: boolean;
|
|
}
|
|
|
|
const PostList = ({
|
|
posts,
|
|
postStatuses,
|
|
areLoading,
|
|
error,
|
|
handleLoadMore,
|
|
page,
|
|
hasMore
|
|
}: Props) => (
|
|
<div className="postList">
|
|
{ error ? <DangerText>{error}</DangerText> : null }
|
|
<InfiniteScroll
|
|
initialLoad={false}
|
|
loadMore={handleLoadMore}
|
|
threshold={50}
|
|
hasMore={hasMore}
|
|
loader={<Spinner key={0} />}
|
|
useWindow={true}
|
|
>
|
|
{
|
|
posts.length > 0 ?
|
|
posts.map((post, i) => (
|
|
<PostListItem
|
|
id={post.id}
|
|
title={post.title}
|
|
description={post.description}
|
|
postStatus={postStatuses.find(postStatus => postStatus.id === post.postStatusId)}
|
|
|
|
key={i}
|
|
/>
|
|
))
|
|
:
|
|
areLoading ? <p></p> : <CenteredMutedText>There are no posts.</CenteredMutedText>
|
|
}
|
|
</InfiniteScroll>
|
|
</div>
|
|
);
|
|
|
|
export default PostList; |