stacker.news/pages/[username]/comments.js

53 lines
1.1 KiB
JavaScript
Raw Normal View History

2021-04-22 22:14:32 +00:00
import Layout from '../../components/layout'
2021-04-27 00:55:48 +00:00
import { CommentsQuery } from '../../components/comments'
2021-04-22 22:14:32 +00:00
import { COMMENT_FIELDS } from '../../fragments/comments'
import { gql } from '@apollo/client'
import ApolloClient from '../../api/client'
import UserHeader from '../../components/user-header'
2021-04-27 00:55:48 +00:00
export async function getServerSideProps ({ req, params }) {
const { error, data: { user } } = await (await ApolloClient(req)).query({
2021-04-22 22:14:32 +00:00
query:
gql`{
user(name: "${params.username}") {
id
createdAt
name
nitems
ncomments
stacked
sats
}
}`
})
if (!user || error) {
return {
notFound: true
}
}
return {
props: {
user
}
}
}
export default function User ({ user }) {
const query = gql`
${COMMENT_FIELDS}
{
comments: userComments(userId: ${user.id}) {
...CommentFields
}
}
`
return (
<Layout>
<UserHeader user={user} />
2021-04-27 00:55:48 +00:00
<CommentsQuery query={query} includeParent noReply />
2021-04-22 22:14:32 +00:00
</Layout>
)
}