11import React from 'react'
22import { Provider } from 'mobx-react'
3+ import R from 'ramda'
34
45import GAWraper from '../components/GAWraper'
56import initRootStore from '../stores/init'
@@ -14,8 +15,6 @@ import Header from '../containers/Header'
1415import CommunitiesBanner from '../containers/CommunitiesBanner'
1516import CommunitiesContent from '../containers/CommunitiesContent'
1617
17- import { P } from '../containers/schemas'
18-
1918import {
2019 makeGQClient ,
2120 // Global,
@@ -24,6 +23,8 @@ import {
2423 getMainPath ,
2524 getSubPath ,
2625 BStore ,
26+ ssrPagedSchema ,
27+ ssrPagedContents ,
2728} from '../utils'
2829import Footer from '../components/Footer'
2930
@@ -45,12 +46,12 @@ async function fetchData(props) {
4546 const subpath = getSubPath ( props )
4647 console . log ( 'subpath --> ' , subpath )
4748
48- const pagedCommunities = gqClient . request ( P . pagedCommunities , {
49+ const pagedContents = gqClient . request ( ssrPagedSchema ( subpath ) , {
4950 filter : { page : 1 , size : 30 } ,
5051 } )
5152
5253 return {
53- ...( await pagedCommunities ) ,
54+ ...( await pagedContents ) ,
5455 }
5556}
5657
@@ -64,13 +65,37 @@ export default class Index extends React.Component {
6465 const subPath = getSubPath ( props )
6566 const mainPath = getMainPath ( props )
6667
67- const { pagedCommunities } = await fetchData ( props )
68+ let resp
69+ try {
70+ resp = await fetchData ( props )
71+ } catch ( { response : { errors } } ) {
72+ /*
73+ if (ssrAmbulance.hasLoginError(errors)) {
74+ resp = await fetchData(props, { realname: false })
75+ } else {
76+ return { statusCode: 404, target: subPath }
77+ }
78+ */
79+ return { statusCode : 404 , target : subPath }
80+ }
81+
82+ const { pagedCommunities } = resp
83+ const pagedContents = ssrPagedContents ( mainPath , subPath , resp )
6884
85+ return R . merge (
86+ {
87+ route : { mainPath, subPath } ,
88+ communities : pagedCommunities ,
89+ } ,
90+ pagedContents
91+ )
92+ /*
6993 return {
7094 route: { mainPath, subPath },
7195 communities: pagedCommunities,
7296 communitiesContent: { pagedCommunities },
7397 }
98+ */
7499 }
75100
76101 constructor ( props ) {
0 commit comments