2023-07-23 10:08:43 -05:00
|
|
|
import { useRouter } from 'next/router'
|
2024-03-20 01:37:31 +01:00
|
|
|
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 17:32:22 -06:00
|
|
|
import { useQuery } from '@apollo/client'
|
2024-03-20 01:37:31 +01:00
|
|
|
import PageLoading from '@/components/page-loading'
|
|
|
|
import TerritoryHeader from '@/components/territory-header'
|
2023-07-23 10:08:43 -05:00
|
|
|
|
2023-08-28 12:52:15 -05:00
|
|
|
export const getServerSideProps = getGetServerSideProps({
|
|
|
|
query: SUB_ITEMS,
|
|
|
|
notFound: (data, vars) => vars.sub && !data.sub
|
|
|
|
})
|
2023-07-23 10:08:43 -05:00
|
|
|
|
|
|
|
export default function Sub ({ ssrData }) {
|
|
|
|
const router = useRouter()
|
|
|
|
const variables = { ...router.query }
|
2023-11-21 17:32:22 -06:00
|
|
|
const { data } = useQuery(SUB_FULL, { variables })
|
|
|
|
|
|
|
|
if (!data && !ssrData) return <PageLoading />
|
|
|
|
const { sub } = data || ssrData
|
2023-07-23 10:08:43 -05:00
|
|
|
|
|
|
|
return (
|
2024-01-03 21:15:54 -06:00
|
|
|
<Layout sub={sub?.name}>
|
2023-11-21 17:32:22 -06:00
|
|
|
{sub
|
2023-12-15 12:10:29 -06:00
|
|
|
? <TerritoryHeader sub={sub} />
|
2023-11-21 17:32:22 -06:00
|
|
|
: (
|
|
|
|
<>
|
|
|
|
<Snl />
|
|
|
|
</>)}
|
2023-07-25 09:14:45 -05:00
|
|
|
<Items ssrData={ssrData} variables={variables} />
|
2023-07-23 10:08:43 -05:00
|
|
|
</Layout>
|
|
|
|
)
|
|
|
|
}
|