2022-10-26 22:46:01 +00:00
|
|
|
// ssr the related query with an adequate limit
|
|
|
|
// need to use a cursor on related
|
2024-03-20 00:37:31 +00:00
|
|
|
import { RELATED_ITEMS, RELATED_ITEMS_WITH_ITEM } from '@/fragments/items'
|
|
|
|
import { getGetServerSideProps } from '@/api/ssrApollo'
|
|
|
|
import Items from '@/components/items'
|
|
|
|
import Layout from '@/components/layout'
|
2022-10-26 22:46:01 +00:00
|
|
|
import { useRouter } from 'next/router'
|
2024-03-20 00:37:31 +00:00
|
|
|
import Item from '@/components/item'
|
2023-07-23 15:08:43 +00:00
|
|
|
import { useQuery } from '@apollo/client'
|
2024-03-20 00:37:31 +00:00
|
|
|
import PageLoading from '@/components/page-loading'
|
2022-10-26 22:46:01 +00:00
|
|
|
|
2023-08-28 17:52:15 +00:00
|
|
|
export const getServerSideProps = getGetServerSideProps({
|
|
|
|
query: RELATED_ITEMS_WITH_ITEM,
|
|
|
|
notFound: data => !data.item
|
|
|
|
})
|
2022-10-26 22:46:01 +00:00
|
|
|
|
2023-07-23 15:08:43 +00:00
|
|
|
export default function Related ({ ssrData }) {
|
2022-10-26 22:46:01 +00:00
|
|
|
const router = useRouter()
|
|
|
|
|
2023-07-23 15:08:43 +00:00
|
|
|
const { data } = useQuery(RELATED_ITEMS_WITH_ITEM, { variables: { id: router.query.id } })
|
|
|
|
if (!data && !ssrData) return <PageLoading />
|
|
|
|
|
|
|
|
const { item } = data || ssrData
|
|
|
|
|
2022-10-26 22:46:01 +00:00
|
|
|
return (
|
|
|
|
<Layout>
|
|
|
|
<Item item={item} />
|
2024-07-11 21:59:07 +00:00
|
|
|
<div className='fw-bold mt-2'>related</div>
|
2022-10-26 22:46:01 +00:00
|
|
|
<Items
|
2023-07-23 15:08:43 +00:00
|
|
|
ssrData={ssrData}
|
2022-10-26 22:46:01 +00:00
|
|
|
query={RELATED_ITEMS}
|
|
|
|
destructureData={data => data.related}
|
|
|
|
variables={{ id: router.query.id }}
|
|
|
|
/>
|
|
|
|
</Layout>
|
|
|
|
)
|
|
|
|
}
|