2021-04-14 23:56:29 +00:00
|
|
|
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-22 22:14:32 +00:00
|
|
|
import { COMMENTS } from '../../fragments/comments'
|
2021-04-26 21:55:15 +00:00
|
|
|
import { ITEM_FIELDS } from '../../fragments/items'
|
|
|
|
import { gql } from '@apollo/client'
|
2021-04-14 23:56:29 +00:00
|
|
|
|
2021-04-26 21:55:15 +00:00
|
|
|
export async function getServerSideProps ({ req, params }) {
|
|
|
|
const { error, data: { item } } = await (await ApolloClient(req)).query({
|
2021-04-14 23:56:29 +00:00
|
|
|
query:
|
2021-04-26 21:55:15 +00:00
|
|
|
gql`
|
|
|
|
${ITEM_FIELDS}
|
|
|
|
{
|
2021-04-14 23:56:29 +00:00
|
|
|
item(id: ${params.id}) {
|
2021-04-26 21:55:15 +00:00
|
|
|
...ItemFields
|
2021-04-14 23:56:29 +00:00
|
|
|
text
|
|
|
|
}
|
|
|
|
}`
|
|
|
|
})
|
|
|
|
|
|
|
|
if (!item || error) {
|
|
|
|
return {
|
|
|
|
notFound: true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
props: {
|
|
|
|
item: item
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default function FullItem ({ item }) {
|
2021-04-22 22:14:32 +00:00
|
|
|
const commentsQuery = gql`
|
|
|
|
${COMMENTS}
|
|
|
|
{
|
|
|
|
comments(parentId: ${item.id}) {
|
|
|
|
...CommentsRecursive
|
|
|
|
}
|
|
|
|
}`
|
|
|
|
|
2021-04-14 23:56:29 +00:00
|
|
|
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-22 22:14:32 +00:00
|
|
|
<div className='mt-5'>
|
|
|
|
<Comments query={commentsQuery} />
|
|
|
|
</div>
|
2021-04-14 23:56:29 +00:00
|
|
|
</Layout>
|
|
|
|
)
|
|
|
|
}
|