Skip to content

Commit 60c4ff8

Browse files
committed
feat: add condition to display pagination only when their next or prev page
1 parent a2df68a commit 60c4ff8

1 file changed

Lines changed: 20 additions & 20 deletions

File tree

src/pages/browse/[alpha]/[page].astro

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ export async function getStaticPaths({ paginate }) {
1616
const dictionary = await getCollection("dictionary");
1717
return ALPHABETS.flatMap(alpha => {
1818
const filteredWords = dictionary.filter(word => word.slug[0] === alpha);
19-
console.log(filteredWords);
20-
2119
return paginate(filteredWords, {
2220
params: { alpha },
2321
pageSize: 1
@@ -56,24 +54,26 @@ export async function getStaticPaths({ paginate }) {
5654
</div>
5755

5856
<!-- Pagination -->
59-
<div class="w-full flex !mt-auto">
60-
<div class="mx-auto flex items-center space-x-4">
61-
{page.url.prev ? (
62-
<a href={page.url.prev} class="bg-black text-white no-underline rounded py-1 px-2">Previous</a>
63-
) : (
64-
<span class="bg-gray-100 text-gray-400 cursor-not-allowed no-underline rounded py-1 px-2">Previous</span>
65-
)}
66-
67-
<span>
68-
Page { page.currentPage }
69-
</span>
70-
71-
{page.url.next ? (
72-
<a href={page.url.next} class="bg-black text-white no-underline rounded py-1 px-2">Next</a>
73-
) : (
74-
<span class="bg-gray-100 text-gray-400 cursor-not-allowed no-underline rounded py-1 px-2">Next</span>
75-
)}
57+
{(page.url.next || page.url.prev) ? (
58+
<div class="w-full flex !mt-auto">
59+
<div class="mx-auto flex items-center space-x-4">
60+
{page.url.prev ? (
61+
<a href={page.url.prev} class="bg-black text-white no-underline rounded py-1 px-2">Previous</a>
62+
) : (
63+
<span class="bg-gray-100 text-gray-400 cursor-not-allowed no-underline rounded py-1 px-2">Previous</span>
64+
)}
65+
66+
<span>
67+
Page { page.currentPage }
68+
</span>
69+
70+
{page.url.next ? (
71+
<a href={page.url.next} class="bg-black text-white no-underline rounded py-1 px-2">Next</a>
72+
) : (
73+
<span class="bg-gray-100 text-gray-400 cursor-not-allowed no-underline rounded py-1 px-2">Next</span>
74+
)}
75+
</div>
7676
</div>
77-
</div>
77+
) : null}
7878
</main>
7979
</BaseLayout>

0 commit comments

Comments
 (0)