mirror of
https://github.com/astuto/astuto.git
synced 2025-12-16 11:47:56 +01:00
Add infinite scroll to post list
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
import * as React from 'react';
|
||||
|
||||
import InfiniteScroll from 'react-infinite-scroller';
|
||||
|
||||
import PostListItem from './PostListItem';
|
||||
import Spinner from '../shared/Spinner';
|
||||
|
||||
@@ -9,14 +11,24 @@ interface Props {
|
||||
posts: Array<IPost>;
|
||||
areLoading: boolean;
|
||||
error: string;
|
||||
|
||||
handleLoadMore(): void;
|
||||
page: number;
|
||||
hasMore: boolean;
|
||||
}
|
||||
|
||||
const PostList = ({ posts, areLoading, error }: Props) => (
|
||||
const PostList = ({ posts, areLoading, error, handleLoadMore, page, hasMore }: Props) => (
|
||||
<div className="box postList">
|
||||
{ areLoading ? <Spinner /> : null }
|
||||
{ error ? <span className="error">{error}</span> : null }
|
||||
{
|
||||
posts.map((post, i) => (
|
||||
<InfiniteScroll
|
||||
initialLoad={false}
|
||||
loadMore={handleLoadMore}
|
||||
threshold={50}
|
||||
hasMore={hasMore}
|
||||
loader={<Spinner />}
|
||||
useWindow={true}
|
||||
>
|
||||
{posts.map((post, i) => (
|
||||
<PostListItem
|
||||
title={post.title}
|
||||
description={post.description}
|
||||
@@ -24,8 +36,8 @@ const PostList = ({ posts, areLoading, error }: Props) => (
|
||||
|
||||
key={i}
|
||||
/>
|
||||
))
|
||||
}
|
||||
))}
|
||||
</InfiniteScroll>
|
||||
</div>
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user