Skip to content

Commit

Permalink
#8 Fix pagination logic
Browse files Browse the repository at this point in the history
  • Loading branch information
raeperd committed Jan 9, 2022
1 parent e39a99a commit 6e4cb30
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import Head from 'next/head';
import { useState } from 'react';
import { Article, getAllArticles } from '../lib/article';

const PAGE_SIZE = 1
const PAGE_SIZE = 3

export default function Index({ siteName, posts }: IndexProps) {
const [pageCurrent, setPageCurrent] = useState(0)
const lastPage = Math.floor(posts.length / PAGE_SIZE) - 1
const pageLast = posts.length < PAGE_SIZE ? 0 : Math.ceil(posts.length / PAGE_SIZE) - 1
return (
<>
<Head>
Expand All @@ -25,7 +25,7 @@ export default function Index({ siteName, posts }: IndexProps) {
prev_page
</button>
)}
{pageCurrent !== lastPage && (
{pageCurrent !== pageLast && (
<button
className="next"
type="button"
Expand Down

0 comments on commit 6e4cb30

Please sign in to comment.