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.

Commit2beba95

Browse files
committed
refactor(router): move onClient to ssr_helper & rename for convention
rename to isClientSide
1 parent9ce5972 commit2beba95

File tree

6 files changed

+30
-18
lines changed

6 files changed

+30
-18
lines changed

‎containers/Route/store.js‎

Lines changed: 8 additions & 2 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')
@@ -42,7 +48,7 @@ const RouteStore = t
4248
// TODO: if current url is subdomain, then we should
4349
// reload to that page directly
4450
markRoute(query){
45-
if(!onClient)returnfalse
51+
if(!isClientSide)returnfalse
4652
const{ mainPath, subPath, page}=query
4753
query=R.pickBy(v=>!R.isEmpty(v),query)
4854

‎pages/community.js‎

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ async function fetchData(props, opt) {
5959
const{ asPath}=props
6060
// schema
6161

62-
const{mainPath,subPath:topic}=parseURL(props)
63-
constcommunity=akaTranslate(mainPath)
62+
const{communityPath,threadPath:topic}=parseURL(props)
63+
constcommunity=akaTranslate(communityPath)
6464
constthread=extractThreadFromPath(props)
6565

6666
letfilter=addTopicIfNeed(
@@ -105,9 +105,9 @@ async function fetchData(props, opt) {
105105

106106
exportdefaultclassCommunityPageextendsReact.Component{
107107
staticasyncgetInitialProps(props){
108-
if(!isServerSide())return{}
108+
if(!isServerSide)return{}
109109

110-
const{mainPath, subPath}=parseURL(props)
110+
const{communityPath, threadPath}=parseURL(props)
111111
constthread=extractThreadFromPath(props)
112112

113113
letresp
@@ -119,7 +119,7 @@ export default class CommunityPage extends React.Component {
119119
}else{
120120
return{
121121
statusCode:404,
122-
target:mainPath,
122+
target:communityPath,
123123
viewing:{community:{}},
124124
route:{},
125125
}
@@ -156,7 +156,12 @@ export default class CommunityPage extends React.Component {
156156
repo:{},
157157
user:{},
158158
},
159-
route:{mainPath:community.raw, subPath},
159+
route:{
160+
communityPath:community.raw,
161+
mainPath:community.raw,
162+
threadPath,
163+
subPath:threadPath,
164+
},
160165
tagsBar:{tags:partialTags},
161166
},
162167
contentsThread
@@ -179,7 +184,7 @@ export default class CommunityPage extends React.Component {
179184
viewing:{ community},
180185
route,
181186
}=this.props
182-
const{mainPath, subPath}=route
187+
const{communityPath, threadPath}=route
183188

184189
constseoTitle=
185190
community.raw==='home'
@@ -200,7 +205,7 @@ export default class CommunityPage extends React.Component {
200205
<React.Fragment>
201206
<NextSeo
202207
config={{
203-
url:`${SITE_URL}/${mainPath}/${subPath}`,
208+
url:`${SITE_URL}/${communityPath}/${threadPath}`,
204209
title:seoTitle,
205210
description:`${community.desc}`,
206211
}}

‎utils/functions.js‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import { nilOrEmpty } from './validator'
99
/* eslint-disable */
1010
// TODO: document ?
1111
exportconstGlobal=typeofwindow!=='undefined' ?window :global
12-
exportconstonClient=typeofwindow!=='undefined' ?true :false
1312
/* eslint-enable */
1413

1514
// see https://github.com/ramda/ramda/issues/1361

‎utils/index.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ export {
1313
mapKeys,
1414
getRandomInt,
1515
Global,
16-
onClient,
1716
cutFrom,
1817
prettyNum,
1918
numberWithCommas,
@@ -81,6 +80,7 @@ export {
8180

8281
export{
8382
isServerSide,
83+
isClientSide,
8484
getJwtToken,
8585
ssrPagedSchema,
8686
ssrPagedFilter,

‎utils/route_helper.js‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ const getThirdPath = args => {
6161
*/
6262
constparseSubDomain=args=>{
6363
letcommunityPath=''
64-
if(isServerSide()){
64+
if(isServerSide){
6565
// on server side
6666
const{ subdomains}=args.req
6767
console.log('subdomains: ',subdomains)
@@ -94,20 +94,24 @@ export const parseURL = args => {
9494
letsubPath=''
9595
letthridPath=''
9696
letcommunityPath=parseSubDomain(args)
97+
letthreadPath=''
9798

9899
if(communityPath===''){
99100
mainPath=getMainPath(args)
100101
subPath=getSubPath(args)
101102
thridPath=getThirdPath(args)
102103
communityPath=mainPath
104+
threadPath=subPath
103105
}else{
104106
mainPath=communityPath
105107
subPath=getMainPath(args)
106108
thridPath=getSubPath(args)
109+
threadPath=subPath
107110
}
108111

109112
return{
110113
communityPath,
114+
threadPath,
111115
mainPath,
112116
subPath,
113117
thridPath,

‎utils/ssr_helper.js‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,13 @@ import BStore from './bstore'
88
/*
99
* check if current is on server side
1010
*/
11-
exportconstisServerSide=()=>{
12-
constisOnserver=typeofwindow==='undefined'
13-
returnisOnserver
14-
}
11+
exportconstisServerSide=typeofwindow==='undefined'
12+
exportconstisClientSide=!isServerSide
1513

1614
// get jwt from cookie or localStorage
1715
// props has to be getInitialProps's arg
1816
exportconstgetJwtToken=props=>{
19-
if(isServerSide())returnBStore.cookie.from_req(props.req,'jwtToken')
17+
if(isServerSide)returnBStore.cookie.from_req(props.req,'jwtToken')
2018

2119
returnBStore.get('token')
2220
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp