|
2 | 2 | this page is for /explore |
3 | 3 | */ |
4 | 4 | import { Provider } from 'mobx-react' |
5 | | -import { clone } from 'ramda' |
6 | 5 | import { METRIC } from '@/constant' |
7 | 6 |
|
8 | | -import { PAGE_SIZE } from '@/config' |
9 | | -import { |
10 | | - ssrBaseStates, |
11 | | - ssrFetchPrepare, |
12 | | - ssrGetParam, |
13 | | - refreshIfneed, |
14 | | - exploreSEO, |
15 | | - ssrError, |
16 | | -} from '@/utils' |
| 7 | +import { exploreSEO } from '@/utils' |
17 | 8 |
|
18 | 9 | import { useStore } from '@/stores/init' |
19 | 10 |
|
20 | 11 | import GlobalLayout from '@/containers/layout/GlobalLayout' |
21 | 12 | import ExploreContent from '@/containers/content/ExploreContent' |
22 | 13 |
|
23 | | -import { P } from '@/schemas' |
24 | | - |
25 | | -const loader = async (context, opt = {}) => { |
26 | | - const { gqClient, userHasLogin } = ssrFetchPrepare(context, opt) |
27 | | - |
28 | | - const category = ssrGetParam(context, 'nc_path') |
29 | | - const page = ssrGetParam(context, 'page') |
30 | | - |
31 | | - const filter = { |
32 | | - page: 1, |
33 | | - size: PAGE_SIZE.M, |
34 | | - } |
35 | | - |
36 | | - const communitiesFilter = clone(filter) |
37 | | - // @ts-ignore |
38 | | - if (category) communitiesFilter.category = category |
39 | | - if (page) communitiesFilter.page = parseInt(page, 10) |
40 | | - |
41 | | - const sessionState = gqClient.request(P.sessionState) |
42 | | - const pagedCommunities = gqClient.request(P.pagedCommunities, { |
43 | | - filter: communitiesFilter, |
44 | | - userHasLogin, |
45 | | - }) |
46 | | - const pagedCategories = gqClient.request(P.pagedCategories, { filter }) |
47 | | - |
48 | | - const subscribedCommunities = gqClient.request(P.subscribedCommunities, { |
49 | | - filter: { |
50 | | - page: 1, |
51 | | - size: 30, |
52 | | - }, |
53 | | - }) |
54 | | - |
55 | | - return { |
56 | | - ...(await sessionState), |
57 | | - ...(await pagedCategories), |
58 | | - ...(await pagedCommunities), |
59 | | - ...(await subscribedCommunities), |
60 | | - } |
61 | | -} |
62 | | - |
63 | 14 | export const getServerSideProps = async (context) => { |
64 | | - let resp |
65 | | - try { |
66 | | - resp = await loader(context) |
67 | | - const { sessionState } = resp |
68 | | - |
69 | | - refreshIfneed(sessionState, '/explore', context) |
70 | | - } catch (e) { |
71 | | - console.log('#### error from server: ', e) |
72 | | - return ssrError(context, 'fetch', 500) |
73 | | - } |
74 | | - |
75 | | - const { pagedCategories, pagedCommunities } = resp |
76 | | - |
77 | | - const initProps = { |
78 | | - ...ssrBaseStates(resp), |
79 | | - exploreContent: { |
80 | | - pagedCommunities, |
81 | | - pagedCategories, |
| 15 | + return { |
| 16 | + redirect: { |
| 17 | + permanent: false, |
| 18 | + destination: '/home', |
82 | 19 | }, |
83 | 20 | } |
84 | | - |
85 | | - return { props: { errorCode: null, ...initProps } } |
86 | 21 | } |
87 | 22 |
|
88 | 23 | const ExplorePage = (props) => { |
|
0 commit comments