stacker.news/pages/items/[id].js

49 lines
962 B
JavaScript
Raw Normal View History

2021-04-14 23:56:29 +00:00
import Layout from '../../components/layout'
import { ITEM_FIELDS } from '../../fragments/items'
2021-09-23 17:42:00 +00:00
import { gql } from '@apollo/client'
2021-07-08 00:15:27 +00:00
import Seo from '../../components/seo'
2021-07-08 17:27:52 +00:00
import ApolloClient from '../../api/client'
2021-09-23 17:42:00 +00:00
import ItemFull from '../../components/item-full'
2021-07-08 17:27:52 +00:00
// ssr the item without comments so that we can populate metatags
export async function getServerSideProps ({ req, params: { id } }) {
if (isNaN(id)) {
return {
notFound: true
}
}
2021-07-08 17:27:52 +00:00
const { error, data: { item } } = await (await ApolloClient(req)).query({
query:
gql`
${ITEM_FIELDS}
{
item(id: ${id}) {
...ItemFields
text
}
}`
})
if (!item || error) {
return {
notFound: true
}
}
2021-04-14 23:56:29 +00:00
2021-04-27 21:30:58 +00:00
return {
props: {
2021-07-08 17:27:52 +00:00
item
2021-04-27 21:30:58 +00:00
}
}
}
2021-04-27 00:55:48 +00:00
2021-09-23 17:42:00 +00:00
export default function AnItem ({ item }) {
2021-04-14 23:56:29 +00:00
return (
2021-07-08 00:34:23 +00:00
<Layout noSeo>
2021-07-08 17:27:52 +00:00
<Seo item={item} />
2021-09-23 17:42:00 +00:00
<ItemFull item={item} />
2021-04-27 00:55:48 +00:00
</Layout>
)
}