Rework loading followers and pagination a bit. Closes #2835

This commit is contained in:
Gabe Kangas
2023-03-22 14:38:29 -07:00
parent c994564fb4
commit 78fe01d049
4 changed files with 38 additions and 32 deletions

View File

@@ -3,9 +3,20 @@
.followers { .followers {
width: 100%; width: 100%;
padding: 5px; padding: 5px;
min-height: 20vh;
.followerRow {
display: grid;
grid-template-columns: repeat(4, minmax(0, 1fr));
}
@media (max-width: 900px) {
.followerRow {
grid-template-columns: repeat(2, minmax(0, 1fr));
}
}
@include screen(mobile) { @include screen(mobile) {
.followerRow { .followerRow {
display: block;
justify-content: center; justify-content: center;
} }
} }

View File

@@ -1,5 +1,5 @@
import { FC, useEffect, useState } from 'react'; import { FC, useEffect, useState } from 'react';
import { Col, Pagination, Row, Skeleton } from 'antd'; import { Pagination, Spin } from 'antd';
import { ErrorBoundary } from 'react-error-boundary'; import { ErrorBoundary } from 'react-error-boundary';
import { Follower } from '../../../../interfaces/follower'; import { Follower } from '../../../../interfaces/follower';
import { SingleFollower } from '../SingleFollower/SingleFollower'; import { SingleFollower } from '../SingleFollower/SingleFollower';
@@ -23,8 +23,10 @@ export const FollowerCollection: FC<FollowerCollectionProps> = ({ name, onFollow
const getFollowers = async () => { const getFollowers = async () => {
try { try {
setLoading(true);
const response = await fetch( const response = await fetch(
`${ENDPOINT}?offset=${page * ITEMS_PER_PAGE}&limit=${ITEMS_PER_PAGE}`, `${ENDPOINT}?offset=${(page - 1) * ITEMS_PER_PAGE}&limit=${ITEMS_PER_PAGE}`,
); );
const data = await response.json(); const data = await response.json();
@@ -60,13 +62,7 @@ export const FollowerCollection: FC<FollowerCollectionProps> = ({ name, onFollow
</div> </div>
); );
const loadingSkeleton = <Skeleton active paragraph={{ rows: 3 }} />; if (!followers?.length && !loading) {
if (loading) {
return loadingSkeleton;
}
if (!followers?.length) {
return noFollowers; return noFollowers;
} }
@@ -81,14 +77,13 @@ export const FollowerCollection: FC<FollowerCollectionProps> = ({ name, onFollow
/> />
)} )}
> >
<Spin spinning={loading} size="large">
<div className={styles.followers} id="followers-collection"> <div className={styles.followers} id="followers-collection">
<Row wrap gutter={[10, 10]} className={styles.followerRow}> <div className={styles.followerRow}>
{followers.map(follower => ( {followers.map(follower => (
<Col key={follower.link}>
<SingleFollower key={follower.link} follower={follower} /> <SingleFollower key={follower.link} follower={follower} />
</Col>
))} ))}
</Row> </div>
<Pagination <Pagination
className={styles.pagination} className={styles.pagination}
@@ -103,6 +98,7 @@ export const FollowerCollection: FC<FollowerCollectionProps> = ({ name, onFollow
hideOnSinglePage hideOnSinglePage
/> />
</div> </div>
</Spin>
</ErrorBoundary> </ErrorBoundary>
); );
}; };

View File

@@ -7,9 +7,8 @@
padding: 10px 10px; padding: 10px 10px;
border-radius: 15px; border-radius: 15px;
height: 75px; height: 75px;
width: 250px;
font-size: 0.8rem; font-size: 0.8rem;
margin: 5px;
color: var(--theme-color-components-text-on-light); color: var(--theme-color-components-text-on-light);
.name { .name {

View File

@@ -12,7 +12,7 @@ export const SingleFollower: FC<SingleFollowerProps> = ({ follower }) => (
<div className={cn([styles.follower, 'followers-follower'])}> <div className={cn([styles.follower, 'followers-follower'])}>
<a href={follower.link} target="_blank" rel="noreferrer"> <a href={follower.link} target="_blank" rel="noreferrer">
<Row wrap={false}> <Row wrap={false}>
<Col span={6}> <Col span={4}>
<Avatar <Avatar
src={follower.image} src={follower.image}
alt="Avatar" alt="Avatar"