stacker.news/pages/index.js

38 lines
818 B
JavaScript
Raw Normal View History

2021-04-12 18:05:09 +00:00
import Layout from '../components/layout'
2021-04-14 23:56:29 +00:00
import Items from '../components/items'
import { useRouter } from 'next/router'
2021-09-30 15:46:58 +00:00
import getSSRApolloClient from '../api/ssrApollo'
import { MORE_ITEMS } from '../fragments/items'
2021-04-12 18:05:09 +00:00
2021-09-30 15:46:58 +00: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 18:05:09 +00:00
return (
<Layout>
2021-09-30 15:46:58 +00:00
<Items
items={items} cursor={cursor}
variables={{ sort: 'hot' }} rank key={router.query.key}
/>
2021-04-12 18:05:09 +00:00
</Layout>
)
}