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

Commit 45c0ad8

Browse files
authored
chore(works): use getStaticProps (#1268)
1 parent 6286cf8 commit 45c0ad8

File tree

3 files changed

+21
-31
lines changed

3 files changed

+21
-31
lines changed

src/pages/topics.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,6 @@ const loader = async () => {
5757
// }
5858

5959
export const getStaticProps: GetStaticProps = async (ctx) => {
60-
console.log('hot params: ', ctx)
61-
6260
const thread = THREAD.POST
6361
const resp = await loader()
6462

src/pages/works.tsx

Lines changed: 16 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,53 @@
11
/*
22
this page is for /works
33
*/
4+
45
import { Provider } from 'mobx-react'
6+
import { GetStaticProps } from 'next'
57

68
import { METRIC, THREAD } from '@/constant'
79
import {
8-
ssrFetchPrepare,
9-
ssrHomePagedArticlesFilter,
10+
isrPagedArticlesFilter,
1011
ssrPagedArticleSchema,
11-
ssrBaseStates,
1212
ssrParseArticleThread,
13-
ssrRescue,
1413
worksSEO,
15-
ssrError,
14+
makeGQClient,
1615
} from '@/utils'
17-
import { P } from '@/schemas'
16+
// import { P } from '@/schemas'
1817

1918
import GlobalLayout from '@/containers/layout/GlobalLayout'
2019
import WorksContent from '@/containers/content/WorksContent'
2120

2221
import { useStore } from '@/stores/init'
2322

24-
const loader = async (context, opt = {}) => {
25-
const { gqClient, userHasLogin } = ssrFetchPrepare(context, opt)
26-
const filter = ssrHomePagedArticlesFilter(context, userHasLogin)
23+
const loader = async () => {
24+
const gqClient = makeGQClient('')
25+
const filter = isrPagedArticlesFilter({})
2726

2827
const pagedArticles = gqClient.request(
2928
ssrPagedArticleSchema(THREAD.WORKS),
3029
filter,
3130
)
32-
const sessionState = gqClient.request(P.sessionState)
3331

3432
return {
3533
filter,
36-
...(await sessionState),
3734
...(await pagedArticles),
3835
}
3936
}
4037

41-
export const getServerSideProps = async (context) => {
42-
let resp
43-
try {
44-
resp = await loader(context)
45-
} catch (e) {
46-
console.log('#### error from server: ', e)
47-
if (ssrRescue.hasLoginError(e.response?.errors)) {
48-
resp = await loader(context, { tokenExpired: true })
49-
} else {
50-
return ssrError(context, 'fetch', 500)
51-
}
52-
}
38+
export const getStaticProps: GetStaticProps = async () => {
39+
const thread = THREAD.WORKS
40+
const resp = await loader()
5341

5442
const { filter } = resp
55-
56-
const { articlesThread } = ssrParseArticleThread(resp, THREAD.WORKS, filter)
57-
const { pagedWorks } = articlesThread
43+
// console.log('iii got resp: ', resp)
44+
const {
45+
articlesThread: { pagedWorks },
46+
} = ssrParseArticleThread(resp, thread, filter)
5847

5948
const initProps = {
60-
...ssrBaseStates(resp),
6149
viewing: {
62-
activeThread: THREAD.WORKS,
50+
activeThread: thread,
6351
},
6452
worksContent: {
6553
pagedWorks,

utils/helper.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,11 @@ export const changeToCommunity = (raw = ''): void => {
289289
const { pathname } = window.location
290290
const curPath = pathname.slice(1)
291291
const isNonCommunityPage = includes(curPath, values(NON_COMMUNITY_ROUTE))
292-
const isArticlePage = includes(curPath.split('/')[0], values(ARTICLE_THREAD))
292+
const isArticlePage = includes(curPath.split('/')[0], [
293+
values(ARTICLE_THREAD),
294+
// works detail page
295+
'w',
296+
])
293297
const isTargetNonCommunityPage = includes(raw, values(NON_COMMUNITY_ROUTE))
294298

295299
if (isNonCommunityPage || isArticlePage || isTargetNonCommunityPage) {

0 commit comments

Comments
 (0)