Skip to content

Commit b576272

Browse files
committed
Handle journey data in pagination component
1 parent c480416 commit b576272

1 file changed

Lines changed: 21 additions & 18 deletions

File tree

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,36 @@
11
---
22
import Icon from '#src/astro/components/Icon.astro';
33
4-
const { pagination } = Astro.props;
4+
const { pagination, journey } = Astro.props;
55
6-
if (!pagination) return null;
6+
if (!pagination && !journey) return null;
77
8-
const {
9-
pageNumber,
10-
totalPages,
11-
baseUrl,
12-
hasPrevious,
13-
hasNext,
14-
totalItems,
15-
itemType
16-
} = pagination;
8+
const isJourney = Boolean(journey);
179
18-
const previousUrl = `${baseUrl}/p/${hasPrevious ? pageNumber - 1 : 1}`;
19-
const nextUrl = `${baseUrl}/p/${hasNext ? pageNumber + 1 : totalPages}`;
10+
const hasPrevious = isJourney ? Boolean(journey.previousUrl) : pagination.hasPrevious;
11+
const previousText = 'Previous';
12+
const previousUrl = isJourney ?
13+
journey.previousUrl :
14+
`${pagination.baseUrl}/p/${hasPrevious ? pagination.pageNumber - 1 : 1}`;
15+
16+
const hasNext = isJourney ? Boolean(journey.nextUrl) : pagination.hasNext;
17+
const nextText ='Next';
18+
const nextUrl = isJourney ?
19+
journey.nextUrl :
20+
`${pagination.baseUrl}/p/${hasNext ? pagination.pageNumber + 1 : pagination.totalPages}`;
21+
22+
const detail = isJourney ?
23+
`<a href="${journey.url}">${journey.title}</a> collection <span>(${journey.itemNumber} of ${journey.totalItems} articles)</span>` :
24+
`Page ${pagination.pageNumber} of ${pagination.totalPages} (${pagination.totalItems} ${pagination.itemType})`;
2025
---
2126
<nav aria-label='Pagination'>
2227
<a href={previousUrl} rel='prev' aria-disabled={!hasPrevious}>
2328
<Icon name='chevron-left' size='1.25em' />
24-
Previous
29+
{previousText}
2530
</a>
2631
<a href={nextUrl} rel='next' aria-disabled={!hasNext}>
27-
Next
32+
{nextText}
2833
<Icon name='chevron-right' size='1.25em' />
2934
</a>
30-
<p>
31-
{`Page ${pageNumber} of ${totalPages} (${totalItems} ${itemType})`}
32-
</p>
35+
<p set:html={detail} />
3336
</nav>

0 commit comments

Comments
 (0)