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.

Commite521703

Browse files
committed
refactor(preview content): redirect workflow
1 parenta12fc4f commite521703

File tree

5 files changed

+54
-41
lines changed

5 files changed

+54
-41
lines changed

‎containers/PostsThread/logic.js‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
THREAD,
1414
$solver,
1515
scrollIntoEle,
16-
GA,
16+
//GA,
1717
}from'../../utils'
1818

1919
importSfrom'./schema'
@@ -96,11 +96,14 @@ export function onTitleSelect(data) {
9696
data,
9797
})
9898

99+
store.markRoute({preview:THREAD.POST,id:data.id})
100+
/*
99101
GA.event({
100102
action: data.title,
101103
category: '浏览',
102104
label: '社区',
103105
})
106+
*/
104107
}
105108

106109
exportconstcreateContent=()=>{
@@ -111,8 +114,6 @@ export const createContent = () => {
111114

112115
exportconstonCustomChange=option=>{
113116
dispatchEvent(EVENT.SET_C11N,{data:option})
114-
115-
debug('onCustomChange option: ',option)
116117
store.updateC11N(option)
117118
}
118119

@@ -149,7 +150,10 @@ const DataSolver = [
149150
},
150151
{
151152
match:asyncRes(EVENT.PREVIEW_CLOSED),
152-
action:()=>store.setViewing({post:{}}),
153+
action:()=>{
154+
store.setViewing({post:{}})
155+
store.markRoute({})
156+
},
153157
},
154158
]
155159

‎pages/community.js‎

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,6 @@ async function fetchData(props) {
4747
consttoken=BStore.cookie.from_req(props.req,'jwtToken')
4848
constgqClient=makeGQClient(token)
4949
constuserHasLogin=nilOrEmpty(token)===false
50-
console.log('========= ')
51-
console.log('userHasLogin: ',userHasLogin)
52-
console.log('========= ')
5350

5451
const{ asPath}=props
5552
// schema
@@ -61,14 +58,16 @@ async function fetchData(props) {
6158
/* const thread = getSubPath(props) */
6259

6360
console.log('the page community thread ->: ',thread)
64-
constfilter=addTopicIfNeed(
61+
letfilter=addTopicIfNeed(
6562
{
6663
...queryStringToJSON(asPath,{pagi:'number'}),
6764
community,
6865
},
6966
thread,
7067
topic
7168
)
69+
70+
filter=R.pick(['page','size','community','topic','tag'],filter)
7271
console.log('the page community filter ->: ',filter)
7372

7473
// query data
@@ -108,7 +107,7 @@ export default class PageCommunity extends React.Component {
108107
/* console.log('SSR extractThreadFromPath -> ', extractThreadFromPath(props)) */
109108
constsubPath=getSubPath(props)
110109
constthread=extractThreadFromPath(props)
111-
console.log('getSubPath thread: ',thread)
110+
//console.log('getSubPath thread: ', thread)
112111

113112
letresp
114113
try{
@@ -120,11 +119,6 @@ export default class PageCommunity extends React.Component {
120119

121120
const{ partialTags, community, subscribedCommunities}=resp
122121

123-
// console.log('the gilter', filter)
124-
// console.log('partialTags: ', partialTags)
125-
126-
// const pagedContents =
127-
128122
console.log(
129123
'pages get subscribedCommunities: ',
130124
subscribedCommunities.totalCount

‎pages/post.js‎

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,6 @@ import { Provider } from 'mobx-react'
44
importinitRootStorefrom'../stores/init'
55
import{GAWraper}from'../components'
66

7-
import{
8-
makeGQClient,
9-
queryStringToJSON,
10-
getSubPath,
11-
ROUTE,
12-
THREAD,
13-
}from'../utils'
14-
157
import{
168
ThemeWrapper,
179
MultiLanguage,
@@ -28,19 +20,40 @@ import {
2820

2921
import{P}from'../containers/schemas'
3022

23+
import{
24+
makeGQClient,
25+
queryStringToJSON,
26+
getSubPath,
27+
ROUTE,
28+
THREAD,
29+
BStore,
30+
}from'../utils'
31+
3132
// try to fix safari bug
3233
// see https://github.com/yahoo/react-intl/issues/422
3334
global.Intl=require('intl')
3435

3536
asyncfunctionfetchData(props){
36-
const{ request}=makeGQClient()
37+
consttoken=BStore.cookie.from_req(props.req,'jwtToken')
38+
constgqClient=makeGQClient(token)
39+
3740
// schema
3841
constpostId=getSubPath(props)
3942

4043
// query data
41-
constpost=request(P.post,{id:postId})
44+
constpost=gqClient.request(P.post,{id:postId})
45+
constsubscribedCommunities=gqClient.request(P.subscribedCommunities,{
46+
filter:{
47+
page:1,
48+
size:30,
49+
},
50+
})
4251

43-
return{ ...(awaitpost)}
52+
// TODO: comments
53+
return{
54+
...(awaitpost),
55+
...(awaitsubscribedCommunities),
56+
}
4457
}
4558

4659
exportdefaultclassIndexextendsReact.Component{
@@ -51,12 +64,14 @@ export default class Index extends React.Component {
5164

5265
console.log('SSR (post--) queryStringToJSON: ',queryStringToJSON(asPath))
5366
/* console.log('SSR extractThreadFromPath -> ', extractThreadFromPath(props)) */
54-
const{ post}=awaitfetchData(props)
67+
const{ post, subscribedCommunities}=awaitfetchData(props)
68+
5569
/* const postId = getSubPath(props) */
5670
/* console.log('getSubPath --> thread: ', thread) */
5771

5872
return{
5973
langSetup:{},
74+
account:{userSubscribedCommunities:subscribedCommunities},
6075
route:{mainPath:ROUTE.POST,subPath:post.id},
6176
viewing:{ post,activeThread:THREAD.POST},
6277
/* curPost: { post }, */

‎pages/user.js‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,11 @@ import {
3131
USER_THREAD,
3232
/* BStore, */
3333
ROUTE,
34-
makeDebugger,
3534
pagedFilter,
3635
}from'../utils'
3736

3837
import{P}from'../containers/schemas'
3938

40-
/* eslint-disable no-unused-vars */
41-
constdebug=makeDebugger('page:user')
42-
/* eslint-enable no-unused-vars */
43-
4439
// try to fix safari bug
4540
// see https://github.com/yahoo/react-intl/issues/422
4641
global.Intl=require('intl')
@@ -78,7 +73,7 @@ export default class UserPage extends React.Component {
7873
constquery=queryStringToJSON(asPath)
7974

8075
const{ user, subscribedCommunities}=awaitfetchData(props)
81-
//debug('fetchData user-->: ', user)
76+
//console.log('fetchData user-->: ', user)
8277

8378
return{
8479
langSetup:{},

‎server.js‎

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const next = require('next')
55
constexpress=require('express')
66
constLRUCache=require('lru-cache')
77
constmobxReact=require('mobx-react')
8+
constR=require('ramda')
89

910
constapp=next({ dev,quiet:false})
1011
consthandle=app.getRequestHandler()
@@ -27,56 +28,60 @@ app.prepare().then(() => {
2728
server.get('/_next/:page?',(req,res)=>handle(req,res))
2829

2930
server.get('/',(req,res)=>{
30-
console.log('match me root')
31+
// fconsole.log('match me root')
3132

3233
returnres.redirect(HOME_PAGE)
3334
})
3435

3536
server.get('/user/:userId',(req,res)=>{
36-
console.log('match me user')
37+
//console.log('match me user')
3738
// return app.render(req, res, '/user', req.query)
3839
returnrenderAndCache(req,res,'/user',req.query)
3940
})
4041

4142
server.get('/post/:id',(req,res)=>{
42-
console.log('match me post')
43+
//console.log('match me post')
4344
/* return app.render(req, res, '/post', req.query) */
4445
returnrenderAndCache(req,res,'/post',req.query)
4546
})
4647

4748
server.get('/job/:id',(req,res)=>{
48-
console.log('match me job')
49+
//console.log('match me job')
4950
/* return app.render(req, res, '/job', req.query) */
5051
returnrenderAndCache(req,res,'/job',req.query)
5152
})
5253

5354
server.get('/video/:id',(req,res)=>{
54-
console.log('match me video')
55+
//console.log('match me video')
5556
/* return app.render(req, res, '/video', req.query) */
5657
returnrenderAndCache(req,res,'/video',req.query)
5758
})
5859

5960
server.get('/repo/:id',(req,res)=>{
60-
console.log('match me repo')
61+
//console.log('match me repo')
6162
/* return app.render(req, res, '/repo', req.query) */
6263
returnrenderAndCache(req,res,'/repo',req.query)
6364
})
6465

6566
server.get('/communities',(req,res)=>{
66-
console.log('match me communities index')
67+
//console.log('match me communities index')
6768
/* return app.render(req, res, '/communities', req.query) */
6869
returnres.redirect('/communities/pl')
6970
// return renderAndCache(req, res, '/communities/pl', req.query)
7071
})
7172

7273
server.get('/communities/:category',(req,res)=>{
73-
console.log('match me communities: ',req.query)
74+
//console.log('match me communities: ', req.query)
7475
/* return app.render(req, res, '/communities', req.query) */
7576
returnrenderAndCache(req,res,'/communities',req.query)
7677
})
7778

7879
server.get('/:community/:thread',(req,res)=>{
79-
console.log('match me community')
80+
// console.log('match me community: ', req.query)
81+
if(R.has('preview',req.query)&&R.has('id',req.query)){
82+
const{ preview, id}=req.query
83+
returnres.redirect(`/${preview}/${id}`)
84+
}
8085
/* return app.render(req, res, '/community', req.query) */
8186
returnrenderAndCache(req,res,'/community',req.query)
8287
})

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp