diff options
| author | Armand Philippot <git@armandphilippot.com> | 2022-01-25 11:47:59 +0100 |
|---|---|---|
| committer | Armand Philippot <git@armandphilippot.com> | 2022-01-25 11:49:56 +0100 |
| commit | 71942c86311a9d1ddf4ae486d811f8393786e855 (patch) | |
| tree | 4e14e1f1ff083dabbb483ba2f12874666c1d6ced /src/pages/recherche/index.tsx | |
| parent | 82702fbe2d0607e7ca8a02c878b2e79a21664b7c (diff) | |
chore: display a progress bar before load more button
Since I'm using cursor pagination, users cannot know if there is a lot
of posts available. With this cursor, they can verify the progression.
Diffstat (limited to 'src/pages/recherche/index.tsx')
| -rw-r--r-- | src/pages/recherche/index.tsx | 31 |
1 files changed, 26 insertions, 5 deletions
diff --git a/src/pages/recherche/index.tsx b/src/pages/recherche/index.tsx index 771bd3b..f497ca3 100644 --- a/src/pages/recherche/index.tsx +++ b/src/pages/recherche/index.tsx @@ -17,6 +17,7 @@ import Sidebar from '@components/Sidebar/Sidebar'; import { ThematicsList, TopicsList } from '@components/Widgets'; import styles from '@styles/pages/Page.module.scss'; import Spinner from '@components/Spinner/Spinner'; +import PaginationCursor from '@components/PaginationCursor/PaginationCursor'; const Search: NextPageWithLayout = () => { const [query, setQuery] = useState(''); @@ -53,6 +54,20 @@ const Search: NextPageWithLayout = () => { if (data) setTotalPostsCount(data[0].pageInfo.total); }, [data]); + const [loadedPostsCount, setLoadedPostsCount] = useState<number>( + config.postsPerPage + ); + + useEffect(() => { + if (data && data.length > 0) { + const newCount = + config.postsPerPage + + data[0].pageInfo.total - + data[data.length - 1].pageInfo.total; + setLoadedPostsCount(newCount); + } + }, [data]); + const isLoadingInitialData = !data && !error; const isLoadingMore: boolean = isLoadingInitialData || @@ -104,11 +119,17 @@ const Search: NextPageWithLayout = () => { <div className={styles.body}> {getPostsList()} {hasNextPage && ( - <Button - isDisabled={isLoadingMore} - clickHandler={loadMorePosts} - position="center" - >{t`Load more?`}</Button> + <> + <PaginationCursor + current={loadedPostsCount} + total={totalPostsCount} + /> + <Button + isDisabled={isLoadingMore} + clickHandler={loadMorePosts} + position="center" + >{t`Load more?`}</Button> + </> )} </div> <Sidebar position="right"> |
