stacker.news/pages/index.js

38 lines
818 B
JavaScript
Raw Normal View History

2021-04-12 13:05:09 -05:00
import Layout from '../components/layout'
2021-04-14 18:56:29 -05:00
import Items from '../components/items'
import { useRouter } from 'next/router'
2021-09-30 10:46:58 -05:00
import getSSRApolloClient from '../api/ssrApollo'
import { MORE_ITEMS } from '../fragments/items'
2021-04-12 13:05:09 -05:00
2021-09-30 10:46:58 -05:00
export async function getServerSideProps ({ req }) {
const client = await getSSRApolloClient(req)
const { data } = await client.query({
query: MORE_ITEMS,
variables: { sort: 'hot' }
})
let items, cursor
if (data) {
({ moreItems: { items, cursor } } = data)
}
return {
props: {
items,
cursor
}
}
}
export default function Index ({ items, cursor }) {
const router = useRouter()
2021-04-12 13:05:09 -05:00
return (
<Layout>
2021-09-30 10:46:58 -05:00
<Items
items={items} cursor={cursor}
variables={{ sort: 'hot' }} rank key={router.query.key}
/>
2021-04-12 13:05:09 -05:00
</Layout>
)
}