fix authors list pages

This commit is contained in:
ilya-bkv 2024-02-26 14:38:23 +03:00
parent 507cfebd48
commit e34aa5e70b

View File

@ -28,6 +28,7 @@ export const AuthorsList = (props: Props) => {
const fetchAuthors = async (queryType: Props['query'], page: number) => { const fetchAuthors = async (queryType: Props['query'], page: number) => {
setLoading(true) setLoading(true)
const offset = PAGE_SIZE * page const offset = PAGE_SIZE * page
const result = await apiClient.loadAuthorsBy({ const result = await apiClient.loadAuthorsBy({
by: { order: queryType }, by: { order: queryType },
limit: PAGE_SIZE, limit: PAGE_SIZE,
@ -35,12 +36,11 @@ export const AuthorsList = (props: Props) => {
}) })
if (queryType === 'shouts') { if (queryType === 'shouts') {
setAuthorsByShouts((prev) => [...prev, ...result]) setAuthorsByShouts((prev) => [prev, ...result])
} else { } else {
setAuthorsByFollowers((prev) => [...prev, ...result]) setAuthorsByFollowers((prev) => [prev, ...result])
} }
setLoading(false) setLoading(false)
return result
} }
const loadMoreAuthors = () => { const loadMoreAuthors = () => {
@ -73,7 +73,7 @@ export const AuthorsList = (props: Props) => {
// }) // })
createEffect(() => { createEffect(() => {
setAllLoaded(authorsByShouts().length === authorsList.length) setAllLoaded(props.allAuthorsLength === authorsList.length)
}) })
return ( return (
@ -96,6 +96,7 @@ export const AuthorsList = (props: Props) => {
<div class="row"> <div class="row">
<div class="col-lg-20 col-xl-18"> <div class="col-lg-20 col-xl-18">
<div class={styles.action}> <div class={styles.action}>
<p>{`${loading()}`}</p>
<Show when={!loading() && authorsList().length > 0 && !allLoaded()}> <Show when={!loading() && authorsList().length > 0 && !allLoaded()}>
<Button value={t('Load more')} onClick={loadMoreAuthors} /> <Button value={t('Load more')} onClick={loadMoreAuthors} />
</Show> </Show>