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

Commit d79e648

Browse files
committed
fix(works): merge error for detail page, bump version
1 parent 91497a2 commit d79e648

File tree

4 files changed

+34
-49
lines changed

4 files changed

+34
-49
lines changed

config/config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
"//--- contact configs ---//": "",
6060
"EMAIL_SUPPORT": "[email protected]",
6161
"// GRAPHQL_ENDPOINT": "https://api.coderplanets.com/graphiql",
62-
"BUILD_VERSION": "v2.1.11",
62+
"BUILD_VERSION": "v2.1.12",
6363
"// 1000 * 60 * 10 = 10 mins": "",
6464
"SSR_CACHE_TIME": 60000
6565
}

deploy/production/web.tar.gz

101 Bytes
Binary file not shown.

src/pages/post/[id].tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1+
import { GetStaticPaths, GetStaticProps } from 'next'
12
import { Provider } from 'mobx-react'
23
import { useRouter } from 'next/router'
3-
import { GetStaticPaths, GetStaticProps } from 'next'
44

55
import { ARTICLE_THREAD, METRIC } from '@/constant'
6-
import LavaLampLoading from '@/widgets/Loading/LavaLampLoading'
76

8-
import { ssrFetchPrepare, articleSEO, ssrGetParam, makeGQClient } from '@/utils'
7+
import { articleSEO, makeGQClient } from '@/utils'
98
import { useStore } from '@/stores/init'
109

1110
import GlobalLayout from '@/containers/layout/GlobalLayout'
1211
import ArticleDigest from '@/containers/digest/ArticleDigest'
1312
import ArticleContent from '@/containers/content/ArticleContent'
13+
import LavaLampLoading from '@/widgets/Loading/LavaLampLoading'
1414

1515
import { P } from '@/schemas'
1616

src/pages/w/[id].tsx

Lines changed: 30 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,63 @@
1+
import { GetStaticPaths, GetStaticProps } from 'next'
12
// import { GetServerSideProps } from 'next'
3+
import { useRouter } from 'next/router'
24
import { Provider } from 'mobx-react'
35

4-
import { ROUTE, THREAD, METRIC } from '@/constant'
5-
6-
import {
7-
ssrFetchPrepare,
8-
ssrError,
9-
articleSEO,
10-
ssrBaseStates,
11-
ssrGetParam,
12-
refreshIfneed,
13-
} from '@/utils'
6+
import { ARTICLE_THREAD, METRIC } from '@/constant'
7+
import { articleSEO, makeGQClient } from '@/utils'
148

159
import { useStore } from '@/stores/init'
1610

1711
import GlobalLayout from '@/containers/layout/GlobalLayout'
1812
import ArticleDigest from '@/containers/digest/ArticleDigest'
1913
import ArticleContent from '@/containers/content/ArticleContent'
14+
import LavaLampLoading from '@/widgets/Loading/LavaLampLoading'
2015

2116
import { P } from '@/schemas'
2217

23-
const loader = async (context, opt = {}) => {
24-
const id = ssrGetParam(context, 'id')
25-
const { gqClient, userHasLogin } = ssrFetchPrepare(context, opt)
26-
27-
// query data
28-
const sessionState = gqClient.request(P.sessionState)
29-
const works = gqClient.request(P.works, { id, userHasLogin })
18+
const loader = async (params) => {
19+
const gqClient = makeGQClient('')
20+
const { id } = params
3021

31-
const subscribedCommunities = gqClient.request(P.subscribedCommunities, {
32-
filter: {
33-
page: 1,
34-
size: 30,
35-
},
36-
})
22+
const works = gqClient.request(P.works, { id, userHasLogin: false })
3723

3824
return {
39-
...(await sessionState),
4025
...(await works),
41-
...(await subscribedCommunities),
4226
}
4327
}
4428

45-
export const getServerSideProps = async (context) => {
46-
let resp
47-
try {
48-
resp = await loader(context)
49-
const { works, sessionState } = resp
50-
refreshIfneed(sessionState, `/works/${works.id}`, context)
51-
} catch (e) {
52-
console.log('#### error from server: ', e)
53-
return ssrError(context, 'fetch', 500)
54-
}
29+
export const getStaticPaths: GetStaticPaths = async () => {
30+
return { paths: [], fallback: true }
31+
}
5532

56-
const { works } = resp
33+
export const getStaticProps: GetStaticProps = async (ctx) => {
34+
console.log('ctx: ', ctx)
35+
const { params } = ctx
5736

58-
const initProps = {
59-
...ssrBaseStates(resp),
60-
route: { mainPath: ROUTE.WORKS, subPath: works.id },
61-
viewing: {
62-
works,
63-
activeThread: THREAD.WORKS,
37+
const resp = await loader(params)
38+
// console.log('resp: ', resp)
39+
40+
return {
41+
props: {
42+
viewing: {
43+
works: resp.works,
44+
activeThread: ARTICLE_THREAD.WORKS,
45+
},
6446
},
47+
revalidate: 5,
6548
}
66-
67-
return { props: { errorCode: null, ...initProps } }
6849
}
6950

7051
const WorksArticlePage = (props) => {
7152
const store = useStore(props)
53+
54+
const { isFallback } = useRouter()
55+
if (isFallback) return <LavaLampLoading top={20} left={30} />
56+
7257
const { viewing } = props
7358
const { works } = viewing
7459

75-
const seoConfig = articleSEO(THREAD.WORKS, works)
60+
const seoConfig = articleSEO(ARTICLE_THREAD.WORKS, works)
7661

7762
return (
7863
<Provider store={store}>

0 commit comments

Comments
 (0)