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

60 lines
1.1 KiB
JavaScript
Raw Normal View History

2021-04-14 23:56:29 +00:00
import gql from 'graphql-tag'
import Item from '../../components/item'
import Layout from '../../components/layout'
import ApolloClient from '../../api/client'
import Reply from '../../components/reply'
import Comment from '../../components/comment'
import Text from '../../components/text'
export async function getServerSideProps ({ params }) {
const { error, data: { item } } = await ApolloClient.query({
query:
gql`{
item(id: ${params.id}) {
id
createdAt
title
url
text
parentId
user {
name
}
sats
ncomments
}
}`
})
if (!item || error) {
return {
notFound: true
}
}
return {
props: {
item: item
}
}
}
export default function FullItem ({ item }) {
return (
<Layout>
{item.parentId
? (
<Comment item={item} />
)
: (
<>
<Item item={item}>
{item.text && <Text>{item.text}</Text>}
<Reply parentId={item.id} />
</Item>
</>
)}
</Layout>
)
}