resolve all comments

This commit is contained in:
Copple committed 2026-02-03 19:02:43 +01:00
1 parent 80304bca04
commit a9074efde8
2 files changed
+18 -6

No files matched your search

+13 -3
View File
@@ -2,12 +2,22 @@ import type { NextApiRequest, NextApiResponse } from 'next'
import { fetchChangelogPage, recursiveDecodeURI } from '~/lib/changelog.server'
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
if (req.method !== 'GET') {
return res.status(405).json({ error: 'Method not allowed' })
}
res.setHeader('Cache-Control', 'public, max-age=900, stale-while-revalidate=900')
const encodedNext = (req.query.next ?? null) as string | null
const next = recursiveDecodeURI(encodedNext)
const restPage = req.query.restPage ? Number(req.query.restPage) : 1
const parsedRestPage = req.query.restPage ? Number(req.query.restPage) : 1
const restPage = Number.isNaN(parsedRestPage) || parsedRestPage < 1 ? 1 : parsedRestPage
const data = await fetchChangelogPage({ next, restPage })
res.status(200).json(data)
try {
const data = await fetchChangelogPage({ next, restPage })
res.status(200).json(data)
} catch (error) {
console.error('Failed to fetch changelog:', error)
res.status(500).json({ error: 'Failed to fetch changelog' })
}
}
+5 -3
View File
@@ -62,7 +62,9 @@ function ChangelogPage({ changelog, pageInfo, restPage }: ChangelogPageProps) {
if (end) {
params.set('next', end)
}
params.set('restPage', String(currentRestPage + 1))
// Cap restPage at 10 to avoid unnecessary API calls after all oldReleases are exhausted
const nextRestPage = Math.min(currentRestPage + 1, 10)
params.set('restPage', String(nextRestPage))
const response = await fetch(`/api/changelog?${params.toString()}`)
if (!response.ok) {
@@ -71,8 +73,8 @@ function ChangelogPage({ changelog, pageInfo, restPage }: ChangelogPageProps) {
const data = await response.json()
setEntries((prev) => prev.concat(data.changelog ?? []))
setCurrentPageInfo(data.pageInfo ?? currentPageInfo)
setCurrentRestPage(data.restPage ?? currentRestPage + 1)
setCurrentPageInfo(data.pageInfo ?? { hasNextPage: false, endCursor: null })
setCurrentRestPage(data.restPage ?? nextRestPage)
} catch (error) {
console.error(error)
} finally {