Skip to content
This repository was archived by the owner on Nov 8, 2022. It is now read-only.

Commit 2f3332f

Browse files
committed
fix(content ssr): missing comments data
1 parent 0544afa commit 2f3332f

File tree

3 files changed

+33
-6
lines changed

3 files changed

+33
-6
lines changed

pages/post.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react'
2-
import R from 'ramda'
32
import { Provider } from 'mobx-react'
3+
import R from 'ramda'
44

55
import { PAGE_SIZE } from '../config'
66

@@ -103,7 +103,6 @@ export default class Index extends React.Component {
103103
community: post.communities[0],
104104
},
105105
comments: { pagedComments },
106-
/* curPost: { post }, */
107106
}
108107
}
109108

pages/repo.js

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
import React from 'react'
22
import { Provider } from 'mobx-react'
3+
import R from 'ramda'
34

5+
import { PAGE_SIZE } from '../config'
46
import initRootStore from '../stores/init'
57
import { GAWraper, ErrorPage } from '../components'
68

79
import {
10+
nilOrEmpty,
811
makeGQClient,
912
getSubPath,
1013
getThirdPath,
14+
TYPE,
1115
ROUTE,
1216
THREAD,
1317
BStore,
@@ -33,14 +37,23 @@ import { P } from '../containers/schemas'
3337
// see https://github.com/yahoo/react-intl/issues/422
3438
global.Intl = require('intl')
3539

36-
async function fetchData(props) {
37-
const token = BStore.cookie.from_req(props.req, 'jwtToken')
40+
async function fetchData(props, opt) {
41+
const { realname } = R.merge({ realname: true }, opt)
42+
43+
const token = realname ? BStore.cookie.from_req(props.req, 'jwtToken') : null
3844
const gqClient = makeGQClient(token)
45+
const userHasLogin = nilOrEmpty(token) === false
3946

4047
const id = getThirdPath(props)
4148

4249
const sessionState = gqClient.request(P.sessionState)
4350
const repo = gqClient.request(P.repo, { id })
51+
const pagedComments = gqClient.request(P.pagedComments, {
52+
id,
53+
userHasLogin,
54+
thread: R.toUpper(THREAD.POST),
55+
filter: { page: 1, size: PAGE_SIZE.D, sort: TYPE.ASC_INSERTED },
56+
})
4457
const subscribedCommunities = gqClient.request(P.subscribedCommunities, {
4558
filter: {
4659
page: 1,
@@ -51,6 +64,7 @@ async function fetchData(props) {
5164
return {
5265
...(await sessionState),
5366
...(await repo),
67+
...(await pagedComments),
5468
...(await subscribedCommunities),
5569
}
5670
}
@@ -68,7 +82,7 @@ export default class Index extends React.Component {
6882
}
6983
}
7084

71-
const { sessionState, repo, subscribedCommunities } = resp
85+
const { sessionState, repo, pagedComments, subscribedCommunities } = resp
7286

7387
return {
7488
langSetup: {},
@@ -83,6 +97,7 @@ export default class Index extends React.Component {
8397
activeThread: THREAD.REPO,
8498
community: repo.communities[0],
8599
},
100+
comments: { pagedComments },
86101
}
87102
}
88103

pages/video.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
import React from 'react'
22
import { Provider } from 'mobx-react'
3+
import R from 'ramda'
34

5+
import { PAGE_SIZE } from '../config'
46
import initRootStore from '../stores/init'
57
import { GAWraper, ErrorPage } from '../components'
68

79
import {
10+
nilOrEmpty,
811
makeGQClient,
912
getSubPath,
1013
getThirdPath,
14+
TYPE,
1115
ROUTE,
1216
THREAD,
1317
BStore,
@@ -36,12 +40,19 @@ global.Intl = require('intl')
3640
async function fetchData(props) {
3741
const token = BStore.cookie.from_req(props.req, 'jwtToken')
3842
const gqClient = makeGQClient(token)
43+
const userHasLogin = nilOrEmpty(token) === false
3944

4045
const id = getThirdPath(props)
4146

4247
// query data
4348
const sessionState = gqClient.request(P.sessionState)
4449
const video = gqClient.request(P.video, { id })
50+
const pagedComments = gqClient.request(P.pagedComments, {
51+
id,
52+
userHasLogin,
53+
thread: R.toUpper(THREAD.JOB),
54+
filter: { page: 1, size: PAGE_SIZE.D, sort: TYPE.ASC_INSERTED },
55+
})
4556
const subscribedCommunities = gqClient.request(P.subscribedCommunities, {
4657
filter: {
4758
page: 1,
@@ -52,6 +63,7 @@ async function fetchData(props) {
5263
return {
5364
...(await sessionState),
5465
...(await video),
66+
...(await pagedComments),
5567
...(await subscribedCommunities),
5668
}
5769
}
@@ -69,7 +81,7 @@ export default class Index extends React.Component {
6981
}
7082
}
7183

72-
const { sessionState, video, subscribedCommunities } = resp
84+
const { sessionState, video, pagedComments, subscribedCommunities } = resp
7385

7486
return {
7587
langSetup: {},
@@ -84,6 +96,7 @@ export default class Index extends React.Component {
8496
activeThread: THREAD.VIDEO,
8597
community: video.communities[0],
8698
},
99+
comments: { pagedComments },
87100
}
88101
}
89102

0 commit comments

Comments
 (0)