Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Nov 8, 2022. It is now read-only.

Commit51d15b6

Browse files
committed
chore: merge branch 'router' into dev
2 parentsaa01021 +bcec01f commit51d15b6

File tree

15 files changed

+191
-111
lines changed

15 files changed

+191
-111
lines changed

‎containers/Route/logic.js‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import{useEffect}from'react'
2-
import{Global,buildLog,getMainPath,getSubPath}from'@utils'
2+
import{Global,buildLog,parseURL}from'@utils'
33

44
/* eslint-disable-next-line */
55
constlog=buildLog('L:Route')
@@ -20,8 +20,7 @@ export const init = (_store, routeObj) => {
2020

2121
store=_store
2222
// sync init router info
23-
constmainPath=getMainPath(routeObj)
24-
constsubPath=getSubPath(routeObj)
23+
const{ mainPath, subPath}=parseURL(routeObj)
2524
const{ query}=routeObj
2625

2726
store.markState({ mainPath, subPath, query})
@@ -35,8 +34,7 @@ export const useInit = (_store, routeObj) => {
3534
useEffect(()=>{
3635
store=_store
3736
// sync init router info
38-
constmainPath=getMainPath(routeObj)
39-
constsubPath=getSubPath(routeObj)
37+
const{ mainPath, subPath}=parseURL(routeObj)
4038
const{ query}=routeObj
4139

4240
store.markState({ mainPath, subPath, query})

‎containers/Route/store.js‎

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,13 @@ import R from 'ramda'
88
// import Router from 'next/router'
99

1010
import{PAGE_SIZE}from'@config'
11-
import{Global,onClient,markStates,buildLog,serializeQuery}from'@utils'
11+
import{
12+
Global,
13+
isClientSide,
14+
markStates,
15+
buildLog,
16+
serializeQuery,
17+
}from'@utils'
1218

1319
/* eslint-disable-next-line */
1420
constlog=buildLog('S:RouteStore')
@@ -23,6 +29,8 @@ const Query = t.model('Query', {
2329

2430
constRouteStore=t
2531
.model('RouteStore',{
32+
communityPath:t.optional(t.string,''),
33+
threadPath:t.optional(t.string,''),
2634
mainPath:t.optional(t.string,''),
2735
subPath:t.optional(t.string,''),
2836
query:t.optional(Query,{}),
@@ -32,13 +40,15 @@ const RouteStore = t
3240
returngetParent(self)
3341
},
3442
getcurRoute(){
35-
const{ mainPath, subPath}=self
36-
return{ mainPath, subPath}
43+
const{communityPath, threadPath,mainPath, subPath}=self
44+
return{communityPath, threadPath,mainPath, subPath}
3745
},
3846
}))
3947
.actions(self=>({
48+
// TODO: if current url is subdomain, then we should
49+
// reload to that page directly
4050
markRoute(query){
41-
if(!onClient)returnfalse
51+
if(!isClientSide)returnfalse
4252
const{ mainPath, subPath, page}=query
4353
query=R.pickBy(v=>!R.isEmpty(v),query)
4454

‎pages/communities.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ import R from 'ramda'
77

88
import{ROUTE}from'@constant'
99
import{
10+
parseURL,
1011
getJwtToken,
1112
makeGQClient,
1213
queryStringToJSON,
1314
nilOrEmpty,
14-
getSubPath,
1515
ssrAmbulance,
1616
parseTheme,
1717
}from'@utils'
@@ -45,7 +45,7 @@ async function fetchData(props, opt) {
4545
consttoken=realname ?getJwtToken(props) :null
4646
constgqClient=makeGQClient(token)
4747
constuserHasLogin=nilOrEmpty(token)===false
48-
constsubPath=getSubPath(props)
48+
const{subPath}=parseURL(props)
4949
constcategory=subPath!=='' ?subPath :'pl'
5050

5151
const{ asPath}=props

‎pages/community.js‎

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,12 @@ import NextSeo from 'next-seo'
66
import{PAGE_SIZE,SITE_URL}from'@config'
77
importinitRootStorefrom'@stores/init'
88

9-
importAnalysisServicefrom'@services/Analysis'
10-
importGlobalLayoutfrom'@containers/GlobalLayout'
11-
importThemeWrapperfrom'@containers/ThemeWrapper'
12-
importMultiLanguagefrom'@containers/MultiLanguage'
13-
importSidebarfrom'@containers/Sidebar'
14-
importPreviewfrom'@containers/Preview'
15-
importDoraemonfrom'@containers/Doraemon'
16-
importRoutefrom'@containers/Route'
17-
importHeaderfrom'@containers/Header'
18-
importCommunityBannerfrom'@containers/CommunityBanner'
19-
importCommunityContentfrom'@containers/CommunityContent'
20-
importFooterfrom'@containers/Footer'
21-
importErrorBoxfrom'@containers/ErrorBox'
22-
importErrorPagefrom'@components/ErrorPage'
23-
249
import{
10+
isServerSide,
2511
getJwtToken,
2612
makeGQClient,
2713
queryStringToJSON,
28-
getMainPath,
29-
getSubPath,
14+
parseURL,
3015
akaTranslate,
3116
extractThreadFromPath,
3217
buildLog,
@@ -40,6 +25,21 @@ import {
4025
parseTheme,
4126
}from'@utils'
4227

28+
importAnalysisServicefrom'@services/Analysis'
29+
importGlobalLayoutfrom'@containers/GlobalLayout'
30+
importThemeWrapperfrom'@containers/ThemeWrapper'
31+
importMultiLanguagefrom'@containers/MultiLanguage'
32+
importSidebarfrom'@containers/Sidebar'
33+
importPreviewfrom'@containers/Preview'
34+
importDoraemonfrom'@containers/Doraemon'
35+
importRoutefrom'@containers/Route'
36+
importHeaderfrom'@containers/Header'
37+
importCommunityBannerfrom'@containers/CommunityBanner'
38+
importCommunityContentfrom'@containers/CommunityContent'
39+
importFooterfrom'@containers/Footer'
40+
importErrorBoxfrom'@containers/ErrorBox'
41+
importErrorPagefrom'@components/ErrorPage'
42+
4343
import{P}from'@schemas'
4444

4545
/* eslint-disable-next-line */
@@ -59,10 +59,8 @@ async function fetchData(props, opt) {
5959
const{ asPath}=props
6060
// schema
6161

62-
// utils: filter, tags staff
63-
constmainPath=getMainPath(props)
64-
constcommunity=akaTranslate(mainPath)
65-
consttopic=getSubPath(props)
62+
const{ communityPath,threadPath:topic}=parseURL(props)
63+
constcommunity=akaTranslate(communityPath)
6664
constthread=extractThreadFromPath(props)
6765

6866
letfilter=addTopicIfNeed(
@@ -107,8 +105,9 @@ async function fetchData(props, opt) {
107105

108106
exportdefaultclassCommunityPageextendsReact.Component{
109107
staticasyncgetInitialProps(props){
110-
constmainPath=getMainPath(props)
111-
constsubPath=getSubPath(props)
108+
if(!isServerSide)return{}
109+
110+
const{ communityPath, threadPath}=parseURL(props)
112111
constthread=extractThreadFromPath(props)
113112

114113
letresp
@@ -120,7 +119,7 @@ export default class CommunityPage extends React.Component {
120119
}else{
121120
return{
122121
statusCode:404,
123-
target:mainPath,
122+
target:communityPath,
124123
viewing:{community:{}},
125124
route:{},
126125
}
@@ -157,7 +156,12 @@ export default class CommunityPage extends React.Component {
157156
repo:{},
158157
user:{},
159158
},
160-
route:{mainPath:community.raw, subPath},
159+
route:{
160+
communityPath:community.raw,
161+
mainPath:community.raw,
162+
threadPath,
163+
subPath:threadPath,
164+
},
161165
tagsBar:{tags:partialTags},
162166
},
163167
contentsThread
@@ -180,7 +184,7 @@ export default class CommunityPage extends React.Component {
180184
viewing:{ community},
181185
route,
182186
}=this.props
183-
const{mainPath, subPath}=route
187+
const{communityPath, threadPath}=route
184188

185189
constseoTitle=
186190
community.raw==='home'
@@ -201,7 +205,7 @@ export default class CommunityPage extends React.Component {
201205
<React.Fragment>
202206
<NextSeo
203207
config={{
204-
url:`${SITE_URL}/${mainPath}/${subPath}`,
208+
url:`${SITE_URL}/${communityPath}/${threadPath}`,
205209
title:seoTitle,
206210
description:`${community.desc}`,
207211
}}

‎pages/home/posts.js‎

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ import {
2525
getJwtToken,
2626
makeGQClient,
2727
queryStringToJSON,
28-
getMainPath,
29-
getSubPath,
28+
parseURL,
3029
akaTranslate,
3130
extractThreadFromPath,
3231
buildLog,
@@ -60,9 +59,8 @@ async function fetchData(props, opt) {
6059
// schema
6160

6261
// utils: filter, tags staff
63-
constmainPath=getMainPath(props)
64-
constcommunity=akaTranslate(mainPath)
65-
consttopic=getSubPath(props)
62+
const{ communityPath,subPath:topic}=parseURL(props)
63+
constcommunity=akaTranslate(communityPath)
6664
constthread=extractThreadFromPath(props)
6765

6866
letfilter=addTopicIfNeed(
@@ -107,8 +105,7 @@ async function fetchData(props, opt) {
107105

108106
exportdefaultclassHomePageextendsReact.Component{
109107
staticasyncgetInitialProps(props){
110-
constmainPath=getMainPath(props)
111-
constsubPath=getSubPath(props)
108+
const{ communityPath, threadPath}=parseURL(props)
112109
constthread=extractThreadFromPath(props)
113110

114111
letresp
@@ -120,7 +117,7 @@ export default class HomePage extends React.Component {
120117
}else{
121118
return{
122119
statusCode:404,
123-
target:mainPath,
120+
target:communityPath,
124121
viewing:{community:{}},
125122
route:{},
126123
}
@@ -157,7 +154,12 @@ export default class HomePage extends React.Component {
157154
repo:{},
158155
user:{},
159156
},
160-
route:{mainPath:community.raw, subPath},
157+
route:{
158+
communityPath:community.raw,
159+
mainPath:community.raw,
160+
threadPath,
161+
subPath:threadPath,
162+
},
161163
tagsBar:{tags:partialTags},
162164
},
163165
contentsThread
@@ -180,7 +182,7 @@ export default class HomePage extends React.Component {
180182
viewing:{ community},
181183
route,
182184
}=this.props
183-
const{mainPath, subPath}=route
185+
const{communityPath, subPath}=route
184186

185187
constseoTitle=
186188
community.raw==='home'
@@ -201,7 +203,7 @@ export default class HomePage extends React.Component {
201203
<React.Fragment>
202204
<NextSeo
203205
config={{
204-
url:`${SITE_URL}/${mainPath}/${subPath}`,
206+
url:`${SITE_URL}/${communityPath}/${subPath}`,
205207
title:seoTitle,
206208
description:`${community.desc}`,
207209
}}

‎pages/index.js‎

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Provider } from 'mobx-react'
33
importRfrom'ramda'
44

55
import{ROUTE}from'@constant'
6-
import{buildLog,getMainPath}from'@utils'
6+
import{buildLog,parseURL,isServerSide}from'@utils'
77
importAnalysisServicefrom'@services/Analysis'
88

99
importGlobalLayoutfrom'@containers/GlobalLayout'
@@ -37,16 +37,13 @@ global.Intl = require('intl')
3737
*/
3838
exportdefaultclassPageCommunityextendsReact.Component{
3939
staticasyncgetInitialProps(props){
40-
constisServer=typeofwindow==='undefined'
41-
console.log('page:index isServer: ',isServer)
40+
if(!isServerSide)return{}
4241

43-
if(!isServer)return{}
42+
const{ communityPath, threadPath}=parseURL(props)
4443

45-
constmainPath=getMainPath(props)
46-
constsubPath=getMainPath(props)
4744
consthideSidebar=
48-
R.contains(mainPath,[ROUTE.USER])||
49-
R.contains(subPath,[ROUTE.POST,ROUTE.REPO,ROUTE.VIDEO,ROUTE.JOB])
45+
R.contains(communityPath,[ROUTE.USER])||
46+
R.contains(threadPath,[ROUTE.POST,ROUTE.REPO,ROUTE.VIDEO,ROUTE.JOB])
5047

5148
return{
5249
hideSidebar,

‎pages/job.js‎

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@ import { TYPE, ROUTE, THREAD } from '@constant'
88
import{
99
getJwtToken,
1010
makeGQClient,
11-
getMainPath,
12-
getSubPath,
13-
getThirdPath,
11+
parseURL,
1412
nilOrEmpty,
1513
ssrAmbulance,
1614
parseTheme,
@@ -45,7 +43,7 @@ async function fetchData(props) {
4543
constuserHasLogin=nilOrEmpty(token)===false
4644

4745
// schema
48-
constid=getThirdPath(props)
46+
const{thridPath:id}=parseURL(props)
4947

5048
// query data
5149
constsessionState=gqClient.request(P.sessionState)
@@ -74,17 +72,18 @@ async function fetchData(props) {
7472
exportdefaultclassJobPageextendsReact.Component{
7573
staticasyncgetInitialProps(props){
7674
letresp
75+
const{ communityPath, threadPath}=parseURL(props)
76+
7777
try{
7878
resp=awaitfetchData(props)
7979
}catch({response:{ errors}}){
8080
if(ssrAmbulance.hasLoginError(errors)){
8181
resp=awaitfetchData(props,{realname:false})
8282
}else{
83-
return{statusCode:404,target:getSubPath(props)}
83+
return{statusCode:404,target:threadPath}
8484
}
8585
}
8686

87-
constmainPath=getMainPath(props)
8887
const{ sessionState, pagedComments, subscribedCommunities, job}=resp
8988

9089
return{
@@ -97,7 +96,12 @@ export default class JobPage extends React.Component {
9796
isValidSession:sessionState.isValid,
9897
userSubscribedCommunities:subscribedCommunities,
9998
},
100-
route:{ mainPath,subPath:ROUTE.JOB},
99+
route:{
100+
communityPath,
101+
mainPath:communityPath,
102+
threadPath:ROUTE.JOB,
103+
subPath:ROUTE.JOB,
104+
},
101105
viewing:{
102106
job,
103107
activeThread:THREAD.JOB,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp