Skip to content

Commit

Permalink
Update page.tsx to fetch and pass next and previous articles
Browse files Browse the repository at this point in the history
* Change cache keys and tags for `cachedGetNextArticle` and `cachedGetPreviousArticle` to match `cachedGetContentDetail`
* Fetch next and previous articles using `cachedGetNextArticle` and `cachedGetPreviousArticle`
* Pass next and previous articles as props to `ContentDetail` component
  • Loading branch information
WakuwakuP committed Nov 6, 2024
1 parent 1d5611f commit 1af3328
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/app/content/detail/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ const cachedGetNextArticle = (publishedAt: string) =>
async () => {
return await getNextArticle(publishedAt)
},
['next-article', publishedAt],
['content-detail-next', publishedAt],
{
tags: ['next-article'],
tags: ['content-detail'],
},
)

Expand All @@ -73,9 +73,9 @@ const cachedGetPreviousArticle = (publishedAt: string) =>
async () => {
return await getPreviousArticle(publishedAt)
},
['previous-article', publishedAt],
['content-detail-previous', publishedAt],
{
tags: ['previous-article'],
tags: ['content-detail'],
},
)

Expand All @@ -89,8 +89,11 @@ export default async function ContentDetailPage({ params }: { params: { id: stri
}

const content = data
const nextArticle = cachedGetNextArticle(content.publishedAt)
const previousArticle = cachedGetPreviousArticle(content.publishedAt)

const getNextArticle = cachedGetNextArticle(content.publishedAt)
const getPreviousArticle = cachedGetPreviousArticle(content.publishedAt)
const nextArticle = await getNextArticle()
const previousArticle = await getPreviousArticle()

return (
<ContentDetail
Expand Down

0 comments on commit 1af3328

Please sign in to comment.