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

60 lines
1.3 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'
2021-04-15 19:41:02 +00:00
import Comments from '../../components/comments'
2021-04-14 23:56:29 +00:00
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
2021-04-18 18:50:04 +00:00
? <Comment item={item} replyOpen includeParent cacheId='ROOT_QUERY' />
2021-04-14 23:56:29 +00:00
: (
<>
<Item item={item}>
{item.text && <Text>{item.text}</Text>}
2021-04-18 18:50:04 +00:00
<Reply parentId={item.id} cacheId='ROOT_QUERY' />
2021-04-14 23:56:29 +00:00
</Item>
</>
)}
2021-04-17 18:15:18 +00:00
<Comments parentId={item.id} />
2021-04-14 23:56:29 +00:00
</Layout>
)
}