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.

Commitc1c8960

Browse files
committed
refactor(Previewer): content previewer made easy
1 parent06977e4 commitc1c8960

File tree

14 files changed

+72
-53
lines changed

14 files changed

+72
-53
lines changed

‎containers/Comments/logic.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ export const loadComents = (args = {}) => {
4242
markLoading(args.fresh)
4343
store.markState({filterType:args.filter.sort})
4444

45+
debug('pagedComments args: ',args)
4546
sr71$.query(S.pagedComments,args)
4647
}
4748

‎containers/Comments/store.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,8 @@ const CommentsStore = t
107107
returnstripMobx(self.root.viewing.community)
108108
},
109109
getactiveThread(){
110-
const{ activeThread}=self.root.viewing
111-
returnR.toUpper(activeThread)
110+
const{ activeThread, viewingThread}=self.root.viewing
111+
returnR.toUpper(viewingThread||activeThread)
112112
},
113113
getviewingData(){
114114
returnself.root.viewingData

‎containers/JobsThread/logic.js‎

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
EVENT,
88
ERR,
99
TYPE,
10+
THREAD,
1011
$solver,
1112
scrollIntoEle,
1213
// GA,
@@ -31,12 +32,7 @@ const debug = makeDebugger('L:JobsThread')
3132
letstore=null
3233
letsub$=null
3334

34-
constvalidFilter=R.pickBy(
35-
R.compose(
36-
R.not,
37-
R.isEmpty
38-
)
39-
)
35+
constvalidFilter=R.pickBy(R.compose(R.not,R.isEmpty))
4036

4137
exportfunctioninAnchor(){
4238
store.setHeaderFix(false)
@@ -83,11 +79,11 @@ export function onTagSelect(obj) {
8379
loadJobs()
8480
}
8581

86-
exportfunctiononTitleSelect(job){
87-
store.setViewing({ job})
82+
exportfunctiononTitleSelect(data){
8883
dispatchEvent(EVENT.PREVIEW_OPEN,{
8984
type:TYPE.PREVIEW_JOB_VIEW,
90-
data:job,
85+
thread:THREAD.JOB,
86+
data,
9187
})
9288
}
9389

‎containers/Labeler/Selected.js‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import { Wrapper, Item, Hightlight } from './styles/selected'
66
import{uid}from'../../utils'
77

88
constrenderItems=items=>{
9+
if(!items)returnnull
10+
911
if(items.length===1){
1012
return(
1113
<Item>
@@ -22,6 +24,8 @@ const renderItems = items => {
2224
}
2325

2426
constrenderReadonlyItems=items=>{
27+
if(!items)returnnull
28+
2529
if(items.length===1){
2630
return(
2731
<Item>
@@ -32,9 +36,7 @@ const renderReadonlyItems = items => {
3236

3337
return(
3438
<Item>
35-
{items.map(item=>(
36-
<Hightlightkey={uid.gen()}>{item}</Hightlight>
37-
))}
39+
{items.map(item=><Hightlightkey={uid.gen()}>{item}</Hightlight>)}
3840
</Item>
3941
)
4042
}

‎containers/PostsThread/logic.js‎

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
EVENT,
1010
ERR,
1111
TYPE,
12+
THREAD,
1213
$solver,
1314
scrollIntoEle,
1415
GA,
@@ -33,12 +34,7 @@ let store = null
3334
letsub$=null
3435

3536
// TODO: move to utils
36-
constvalidFilter=R.pickBy(
37-
R.compose(
38-
R.not,
39-
R.isEmpty
40-
)
41-
)
37+
constvalidFilter=R.pickBy(R.compose(R.not,R.isEmpty))
4238

4339
exportconstinAnchor=()=>store.setHeaderFix(false)
4440
exportconstoutAnchor=()=>store.setHeaderFix(true)
@@ -78,17 +74,18 @@ export function onTagSelect(tag) {
7874
loadPosts()
7975
}
8076

81-
exportfunctiononTitleSelect(post){
82-
store.setViewing({ post})
83-
/* store.setActive(post) */
84-
debug('onTitleSelect publish post: ',post)
77+
exportfunctiononTitleSelect(data){
78+
/*store.setViewing({ post }) */
79+
debug('onTitleSelect publishpost: ',data)
80+
8581
dispatchEvent(EVENT.PREVIEW_OPEN,{
8682
type:TYPE.PREVIEW_POST_VIEW,
87-
data:post,
83+
thread:THREAD.POST,
84+
data,
8885
})
8986

9087
GA.event({
91-
action:post.title,
88+
action:data.title,
9289
category:'浏览',
9390
label:'社区',
9491
})

‎containers/Preview/logic.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export function closePreview() {
2929
setTimeout(()=>{
3030
store.markState({type:null})
3131
dispatchEvent(EVENT.PREVIEW_CLOSED)
32+
store.setViewing({viewingThread:null})
3233
},200)
3334
}
3435

‎containers/Preview/store.js‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ import { types as t, getParent } from 'mobx-state-tree'
77
importRfrom'ramda'
88

99
import{User}from'../../stores/SharedModel'
10-
import{markStates,TYPE,stripMobx,unholdPage}from'../../utils'
10+
import{markStates,TYPE,stripMobx,unholdPage,THREAD}from'../../utils'
1111

12+
constPREVIEWABLE_THREADS=[THREAD.POST,THREAD.JOB,THREAD.VIDEO,THREAD.REPO]
1213
/* const debug = makeDebugger('S:PreviewStore') */
1314
constTHREAD_CONTENT_CURD_TYPES=[
1415
// post
@@ -83,12 +84,19 @@ const PreviewStore = t
8384
},
8485
}))
8586
.actions(self=>({
86-
open({ type, data}){
87+
open({ type, data, thread}){
8788
self.visible=true
8889
self.type=type
8990

9091
// NOTE: currently the attachment is only used for article-like content
9192
if(data)self.attachment=R.merge({ type},data)
93+
94+
if((thread,R.contains(thread,PREVIEWABLE_THREADS))){
95+
self.setViewing({[thread]:data,viewingThread:thread})
96+
}
97+
},
98+
setViewing(sobj){
99+
self.root.setViewing(sobj)
92100
},
93101
close(){
94102
self.visible=false

‎containers/ReposThread/logic.js‎

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
dispatchEvent,
99
EVENT,
1010
TYPE,
11+
THREAD,
1112
scrollIntoEle,
1213
asyncRes,
1314
}from'../../utils'
@@ -30,12 +31,7 @@ const debug = makeDebugger('L:ReposThread')
3031

3132
letstore=null
3233

33-
constvalidFilter=R.pickBy(
34-
R.compose(
35-
R.not,
36-
R.isEmpty
37-
)
38-
)
34+
constvalidFilter=R.pickBy(R.compose(R.not,R.isEmpty))
3935

4036
exportconstinAnchor=()=>store.setHeaderFix(false)
4137
exportconstoutAnchor=()=>store.setHeaderFix(true)
@@ -63,13 +59,11 @@ export function loadRepos(page = 1) {
6359
store.markRoute({ page})
6460
}
6561

66-
exportfunctiononTitleSelect(repo){
67-
store.setViewing({ repo})
68-
debug('onTitleSelect ---',repo)
69-
62+
exportfunctiononTitleSelect(data){
7063
dispatchEvent(EVENT.PREVIEW_OPEN,{
7164
type:TYPE.PREVIEW_REPO_VIEW,
72-
data:repo,
65+
thread:THREAD.REPO,
66+
data,
7367
})
7468
}
7569

‎containers/UserFavorited/logic.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ const ErrSolver = []
110110
exportfunctioninit(_store){
111111
if(store){
112112
// return loadPosts()
113+
returnfalse
113114
}
114115
store=_store
115116

‎containers/UserPublished/index.js‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,9 @@ class UserPublishedContainer extends React.Component {
4343
data={pagedData}
4444
thread={curThread}
4545
curView={curView}
46-
onPageChange={logic.reload}
4746
emptyPrefix={`未找到${viewingUser.nickname} 发布的`}
47+
onPageChange={logic.reload}
48+
onTitleSelect={logic.onTitleSelect}
4849
/>
4950
</React.Fragment>
5051
)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp