Fix followers pagination UI

This commit is contained in:
Gabe Kangas 2022-07-05 12:53:21 -07:00
parent e443188cbc
commit 14f405bf58
No known key found for this signature in database
GPG Key ID: 9A56337728BC81EA

View File

@ -22,27 +22,28 @@ export default class FollowerList extends Component {
}
}
async getFollowers() {
const { currentPage } = this.state;
async getFollowers(requestedPage) {
const limit = 24;
const offset = currentPage * limit;
const u = `${URL_FOLLOWERS}?offset=${offset}&limit=${limit}`;
const offset = requestedPage * limit;
const u = `${URL_FOLLOWERS}?offset=${offset || 0}&limit=${limit}`;
const response = await fetch(u);
const followers = await response.json();
const pages = Math.ceil(followers.total / limit);
this.setState({
followers: followers.results,
total: response.total,
total: followers.total,
pages: pages,
});
}
changeFollowersPage(page) {
this.setState({ currentPage: page });
this.getFollowers();
changeFollowersPage(requestedPage) {
this.setState({ currentPage: requestedPage });
this.getFollowers(requestedPage);
}
render() {
const { followers, total, currentPage } = this.state;
const { followers, total, pages, currentPage } = this.state;
if (!followers) {
return null;
}
@ -62,8 +63,8 @@ export default class FollowerList extends Component {
</div>`;
const paginationControls =
total > 1 &&
Array(total)
pages > 1 &&
Array(pages)
.fill()
.map((x, n) => {
const activePageClass =