stacker.news/pages/~/index.js

36 lines
1.0 KiB
JavaScript
Raw Normal View History

import { useRouter } from 'next/router'
import { getGetServerSideProps } from '@/api/ssrApollo'
import Items from '@/components/items'
import Layout from '@/components/layout'
import { SUB_FULL, SUB_ITEMS } from '@/fragments/subs'
import Snl from '@/components/snl'
2023-11-21 23:32:22 +00:00
import { useQuery } from '@apollo/client'
import PageLoading from '@/components/page-loading'
import TerritoryHeader from '@/components/territory-header'
export const getServerSideProps = getGetServerSideProps({
query: SUB_ITEMS,
notFound: (data, vars) => vars.sub && !data.sub
})
export default function Sub ({ ssrData }) {
const router = useRouter()
const variables = { ...router.query }
2023-11-21 23:32:22 +00:00
const { data } = useQuery(SUB_FULL, { variables })
if (!data && !ssrData) return <PageLoading />
const { sub } = data || ssrData
return (
2024-01-04 03:15:54 +00:00
<Layout sub={sub?.name}>
2023-11-21 23:32:22 +00:00
{sub
2023-12-15 18:10:29 +00:00
? <TerritoryHeader sub={sub} />
2023-11-21 23:32:22 +00:00
: (
<>
<Snl />
</>)}
2023-07-25 14:14:45 +00:00
<Items ssrData={ssrData} variables={variables} />
</Layout>
)
}