Keyan 01b021a337
comment pagination with limit/offset (#1824)
* basic query with limit/offset

* roughly working increment

* working limiting/pageable queries

* denormalize direct comments + full comments below threshold

* notifications in megathread + working nest view more buttons

* fix empty comment footer

* make comments nested resolver again

* use time in cursor to avoid duplicates

* squash migrations

* do not need item.comments undefined checks
2025-01-29 19:00:05 -06:00

33 lines
1.0 KiB
JavaScript

import Layout from '@/components/layout'
import { ITEM_FULL } from '@/fragments/items'
import ItemFull from '@/components/item-full'
import { getGetServerSideProps } from '@/api/ssrApollo'
import { useQuery } from '@apollo/client'
import { useRouter } from 'next/router'
import PageLoading from '@/components/page-loading'
export const getServerSideProps = getGetServerSideProps({
query: ITEM_FULL,
notFound: data => !data.item || (data.item.status === 'STOPPED' && !data.item.mine)
})
export default function Item ({ ssrData }) {
const router = useRouter()
const { data, fetchMore } = useQuery(ITEM_FULL, { variables: { ...router.query } })
if (!data && !ssrData) return <PageLoading />
const { item } = data || ssrData
const sub = item.subName || item.root?.subName
const fetchMoreComments = async () => {
await fetchMore({ variables: { ...router.query, cursor: item.comments.cursor } })
}
return (
<Layout sub={sub} item={item}>
<ItemFull item={item} fetchMoreComments={fetchMoreComments} />
</Layout>
)
}