Tom 4fd23a3694
Add Random link and basic query (#1306)
* Add Random link and basic query

* Use random

* refine random sort query

* make vote threshold higher

---------

Co-authored-by: k00b <k00b@stacker.news>
2024-08-20 16:50:55 -05:00

32 lines
852 B
JavaScript

import Layout from '@/components/layout'
import Items from '@/components/items'
import { getGetServerSideProps } from '@/api/ssrApollo'
import { SUB_ITEMS } from '@/fragments/subs'
import { useRouter } from 'next/router'
const staticVariables = { sort: 'random' }
const variablesFunc = vars =>
({ ...staticVariables, ...vars })
export const getServerSideProps = getGetServerSideProps({
query: SUB_ITEMS,
variables: variablesFunc,
notFound: (data, vars) => vars.sub && !data.sub
})
export default function Index ({ ssrData }) {
const router = useRouter()
const variables = variablesFunc(router.query)
const sub = ssrData?.sub?.name || variables.sub
return (
<Layout sub={sub}>
<Items
ssrData={ssrData}
query={SUB_ITEMS}
variables={variables}
noMoreText='NO MORE'
/>
</Layout>
)
}