2021-04-14 18:56:29 -05:00
|
|
|
import Layout from '../../components/layout'
|
2021-04-26 16:55:15 -05:00
|
|
|
import { ITEM_FIELDS } from '../../fragments/items'
|
2021-09-23 12:42:00 -05:00
|
|
|
import { gql } from '@apollo/client'
|
2021-07-07 19:15:27 -05:00
|
|
|
import Seo from '../../components/seo'
|
2021-07-08 12:27:52 -05:00
|
|
|
import ApolloClient from '../../api/client'
|
2021-09-23 12:42:00 -05:00
|
|
|
import ItemFull from '../../components/item-full'
|
2021-07-08 12:27:52 -05:00
|
|
|
|
|
|
|
// ssr the item without comments so that we can populate metatags
|
|
|
|
export async function getServerSideProps ({ req, params: { id } }) {
|
2021-08-12 16:21:56 -05:00
|
|
|
if (isNaN(id)) {
|
|
|
|
return {
|
|
|
|
notFound: true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-08 12:27:52 -05: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 18:56:29 -05:00
|
|
|
|
2021-04-27 16:30:58 -05:00
|
|
|
return {
|
|
|
|
props: {
|
2021-07-08 12:27:52 -05:00
|
|
|
item
|
2021-04-27 16:30:58 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-04-26 19:55:48 -05:00
|
|
|
|
2021-09-23 12:42:00 -05:00
|
|
|
export default function AnItem ({ item }) {
|
2021-04-14 18:56:29 -05:00
|
|
|
return (
|
2021-07-07 19:34:23 -05:00
|
|
|
<Layout noSeo>
|
2021-07-08 12:27:52 -05:00
|
|
|
<Seo item={item} />
|
2021-09-23 12:42:00 -05:00
|
|
|
<ItemFull item={item} />
|
2021-04-26 19:55:48 -05:00
|
|
|
</Layout>
|
|
|
|
)
|
|
|
|
}
|