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.

Commit2bab977

Browse files
committed
feat(UserPublishedComments): with different thread & refactor
1 parent77616b9 commit2bab977

File tree

24 files changed

+837
-27
lines changed

24 files changed

+837
-27
lines changed

‎containers/UserContent/index.js‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import React from 'react'
88
import{inject,observer}from'mobx-react'
99

1010
importUserPublishedfrom'../UserPublished'
11+
importUserPublishedCommentsfrom'../UserPublishedComments'
1112
importUserBillingfrom'../UserBilling'
1213
importUserSettingsfrom'../UserSettings'
1314
importUserStaredfrom'../UserStared'
@@ -26,7 +27,7 @@ import * as logic from './logic'
2627
constdebug=makeDebugger('C:UserContent')
2728
/* eslint-enable no-unused-vars */
2829

29-
constfakeThreads=[
30+
consttaberThreads=[
3031
{
3132
title:'发布',
3233
raw:'publish',
@@ -56,7 +57,7 @@ const fakeThreads = [
5657
constTabberContent=({ active})=>{
5758
switch(active){
5859
caseUSER_THREAD.COMMENTS:{
59-
return<h2>COMMENTS</h2>
60+
return<UserPublishedComments/>
6061
}
6162
caseUSER_THREAD.FAVORITES:{
6263
return<UserFavorited/>
@@ -91,7 +92,7 @@ class UserContentContainer extends React.Component {
9192
<MainWrapper>
9293
<TabberWrapperclassName="tabs-with-bottom">
9394
<Tabber
94-
source={fakeThreads}
95+
source={taberThreads}
9596
onChange={logic.tabChange}
9697
active={activeThread}
9798
/>
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
importReactfrom'react'
2+
importTimeAgofrom'timeago-react'
3+
4+
import{MarkDownRender,CommentLoading,EmptyLabel}from'../../components'
5+
import{
6+
Wrapper,
7+
CommentBlock,
8+
CommentDivider,
9+
CommentBox,
10+
CommentHeader,
11+
Avatar,
12+
AvatarInfo,
13+
Nickname,
14+
When,
15+
CommentBody,
16+
}from'./styles/comments_to_post'
17+
18+
importParentfrom'./Parent'
19+
20+
import{uid,TYPE,Trans}from'../../utils'
21+
22+
constCommentsToContent=({ data, thread, curView})=>{
23+
const{ entries}=data
24+
25+
switch(curView){
26+
caseTYPE.RESULT:{
27+
return(
28+
<Wrapper>
29+
{entries.map(comment=>(
30+
<divkey={uid.gen()}>
31+
<CommentBlock>
32+
<Parentdata={comment}thread={thread}/>
33+
<CommentBox>
34+
<CommentHeader>
35+
<Avatarsrc={comment.author.avatar}/>
36+
<AvatarInfo>
37+
<Nickname>{comment.author.nickname}</Nickname>
38+
<When>
39+
评论于:
40+
<TimeAgodatetime={comment.updatedAt}locale="zh_CN"/>
41+
</When>
42+
</AvatarInfo>
43+
</CommentHeader>
44+
<CommentBody>
45+
<MarkDownRenderbody={comment.body}/>
46+
</CommentBody>
47+
</CommentBox>
48+
</CommentBlock>
49+
<CommentDivider/>
50+
</div>
51+
))}
52+
</Wrapper>
53+
)
54+
}
55+
caseTYPE.RESULT_EMPTY:{
56+
return(
57+
<React.Fragment>
58+
<EmptyLabeltext={`未找到评论的${Trans(thread)}信息`}size="large"/>
59+
</React.Fragment>
60+
)
61+
}
62+
default:{
63+
return<CommentLoading/>
64+
}
65+
}
66+
}
67+
68+
exportdefaultCommentsToContent
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
importReactfrom'react'
2+
3+
import{Popover}from'../../components'
4+
5+
import{Wrapper,Logo,PopoverInfo}from'./styles/community_list'
6+
import{uid}from'../../utils'
7+
8+
constCommunityList=({ items})=>(
9+
<Wrapper>
10+
{items.map(community=>(
11+
<Popover
12+
key={uid.gen()}
13+
placement="bottom"
14+
trigger="hover"
15+
content={<PopoverInfo>{community.title}</PopoverInfo>}
16+
>
17+
<div>
18+
<Logosrc={community.logo}/>
19+
</div>
20+
</Popover>
21+
))}
22+
</Wrapper>
23+
)
24+
25+
exportdefaultCommunityList
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
importReactfrom'react'
2+
3+
import{Wrapper,Title}from'./styles/parent'
4+
importCommunityListfrom'./CommunityList'
5+
6+
import{THREAD}from'../../utils'
7+
8+
constParent=({ thread, data})=>{
9+
switch(thread){
10+
caseTHREAD.JOB:{
11+
return(
12+
<Wrapper>
13+
<Title>{data.job.title}</Title>
14+
<CommunityListitems={data.job.communities}/>
15+
</Wrapper>
16+
)
17+
}
18+
caseTHREAD.REPO:{
19+
return(
20+
<Wrapper>
21+
<Title>{data.repo.title}</Title>
22+
<CommunityListitems={data.repo.communities}/>
23+
</Wrapper>
24+
)
25+
}
26+
caseTHREAD.VIDEO:{
27+
return(
28+
<Wrapper>
29+
<Title>{data.video.title}</Title>
30+
<CommunityListitems={data.video.communities}/>
31+
</Wrapper>
32+
)
33+
}
34+
default:{
35+
return(
36+
<Wrapper>
37+
<Title>{data.post.title}</Title>
38+
<CommunityListitems={data.post.communities}/>
39+
</Wrapper>
40+
)
41+
}
42+
}
43+
}
44+
45+
exportdefaultParent
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
*
3+
* UserPublishedComments
4+
*
5+
*/
6+
7+
importReactfrom'react'
8+
import{inject,observer}from'mobx-react'
9+
10+
import{ThreadSelector}from'../../components'
11+
import{ThreadWrapper}from'./styles'
12+
13+
importCommentsToContentfrom'./CommentsToContent'
14+
15+
import{makeDebugger,storePlug}from'../../utils'
16+
17+
import*aslogicfrom'./logic'
18+
/* eslint-disable no-unused-vars */
19+
constdebug=makeDebugger('C:UserPublishedComments')
20+
/* eslint-enable no-unused-vars */
21+
22+
classUserPublishedCommentsContainerextendsReact.Component{
23+
componentWillMount(){
24+
const{ userPublishedComments}=this.props
25+
logic.init(userPublishedComments)
26+
}
27+
28+
render(){
29+
const{ userPublishedComments}=this.props
30+
const{ curThread, curView, pagedCommentsData}=userPublishedComments
31+
32+
const{ totalCount}=pagedCommentsData
33+
// debug('pagedCommentsData-->: ', pagedCommentsData)
34+
35+
return(
36+
<div>
37+
<ThreadWrapper>
38+
<ThreadSelector
39+
active={curThread}
40+
onSelect={logic.onThreadChange}
41+
totalCount={totalCount}
42+
lookLike="box"
43+
/>
44+
</ThreadWrapper>
45+
<CommentsToContent
46+
thread={curThread}
47+
curView={curView}
48+
data={pagedCommentsData}
49+
/>
50+
</div>
51+
)
52+
}
53+
}
54+
55+
exportdefaultinject(storePlug('userPublishedComments'))(
56+
observer(UserPublishedCommentsContainer)
57+
)
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
// import R from 'ramda'
2+
3+
import{
4+
makeDebugger,
5+
$solver,
6+
asyncRes,
7+
asyncErr,
8+
TYPE,
9+
THREAD,
10+
ERR,
11+
pagedFilter,
12+
}from'../../utils'
13+
14+
importSR71from'../../utils/network/sr71'
15+
importSfrom'./schema'
16+
17+
constsr71$=newSR71()
18+
letsub$=null
19+
20+
/* eslint-disable no-unused-vars */
21+
constdebug=makeDebugger('L:UserPublishedComments')
22+
/* eslint-enable no-unused-vars */
23+
24+
letstore=null
25+
26+
constbeforeQuery=page=>{
27+
store.markState({curView:TYPE.LOADING})
28+
// args
29+
return{
30+
userId:store.viewingUser.id,
31+
filter:pagedFilter(page),
32+
}
33+
}
34+
35+
exportfunctionloadPostComments(page=1){
36+
constargs=beforeQuery(page)
37+
sr71$.query(S.publishedPostComments,args)
38+
}
39+
40+
exportfunctionloadJobComments(page=1){
41+
constargs=beforeQuery(page)
42+
sr71$.query(S.publishedJobComments,args)
43+
}
44+
45+
exportfunctionloadVideoComments(page=1){
46+
constargs=beforeQuery(page)
47+
sr71$.query(S.publishedVideoComments,args)
48+
}
49+
50+
exportfunctionloadRepoComments(page=1){
51+
constargs=beforeQuery(page)
52+
sr71$.query(S.publishedRepoComments,args)
53+
}
54+
55+
exportfunctiononThreadChange(curThread){
56+
// TODO: markRoute
57+
store.markState({ curThread})
58+
// reload()
59+
switch(store.curThread){
60+
caseTHREAD.JOB:{
61+
returnloadJobComments()
62+
}
63+
caseTHREAD.VIDEO:{
64+
returnloadVideoComments()
65+
}
66+
caseTHREAD.REPO:{
67+
returnloadRepoComments()
68+
}
69+
default:{
70+
returnloadPostComments()
71+
}
72+
}
73+
}
74+
75+
// ###############################
76+
// Data & Error handlers
77+
// ###############################
78+
79+
constDataSolver=[
80+
{
81+
match:asyncRes('publishedPostComments'),
82+
action:({ publishedPostComments})=>
83+
store.markPagedData(publishedPostComments),
84+
},
85+
{
86+
match:asyncRes('publishedJobComments'),
87+
action:({ publishedJobComments})=>
88+
store.markPagedData(publishedJobComments),
89+
},
90+
{
91+
match:asyncRes('publishedVideoComments'),
92+
action:({ publishedVideoComments})=>
93+
store.markPagedData(publishedVideoComments),
94+
},
95+
{
96+
match:asyncRes('publishedRepoComments'),
97+
action:({ publishedRepoComments})=>{
98+
debug('get publishedRepoComments: ',publishedRepoComments)
99+
store.markPagedData(publishedRepoComments)
100+
},
101+
},
102+
]
103+
104+
constErrSolver=[
105+
{
106+
match:asyncErr(ERR.CRAPHQL),
107+
action:({ details})=>{
108+
debug('ERR.CRAPHQL -->',details)
109+
},
110+
},
111+
{
112+
match:asyncErr(ERR.TIMEOUT),
113+
action:({ details})=>{
114+
debug('ERR.TIMEOUT -->',details)
115+
},
116+
},
117+
{
118+
match:asyncErr(ERR.NETWORK),
119+
action:({ details})=>{
120+
debug('ERR.NETWORK -->',details)
121+
},
122+
},
123+
]
124+
125+
exportfunctioninit(_store){
126+
if(store){
127+
returnloadPostComments()
128+
}
129+
store=_store
130+
131+
debug(store)
132+
if(sub$)sub$.unsubscribe()
133+
sub$=sr71$.data().subscribe($solver(DataSolver,ErrSolver))
134+
135+
loadPostComments()
136+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp