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.

Commit597a68b

Browse files
committed
refactor(ReactionHeaders): set boundery for threads
1 parentd7a3076 commit597a68b

File tree

8 files changed

+62
-58
lines changed

8 files changed

+62
-58
lines changed

‎components/ArticleHeader/index.js‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ const ArticleHeader = ({
5959
<Maybetext={showFavorite}>
6060
<Reaction>
6161
<ReactionAction
62+
active={data.viewerHasFavorited}
6263
onClick={onReaction.bind(
6364
this,
6465
thread,
@@ -84,6 +85,7 @@ const ArticleHeader = ({
8485
<Maybetest={showStar}>
8586
<Reaction>
8687
<ReactionAction
88+
active={data.viewerHasStarred}
8789
onClick={onReaction.bind(
8890
this,
8991
thread,
@@ -93,7 +95,9 @@ const ArticleHeader = ({
9395
)}
9496
>
9597
<LikeIconsrc={`${ICON_CMD}/like.svg`}/>
96-
<ReactionName></ReactionName>
98+
<ReactionName>
99+
{data.viewerHasStarred ?<span>已赞</span> :<span></span>}
100+
</ReactionName>
97101
</ReactionAction>
98102
<ReactionUserNum>{data.starredCount}</ReactionUserNum>
99103
<Divider/>

‎components/ArticleHeader/styles/index.js‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,16 @@ export const Reaction = styled.div`
3131
exportconstPlainAction=styled.div`
3232
display: flex;
3333
align-items: center;
34-
padding: 2px 3px;
34+
border-radius: 5px;
3535
`
3636
exportconstReactionAction=styled(PlainAction)`
37+
background-color:${({ active})=>
38+
active ?theme('article.reactionHoverBg') :''};
39+
padding:${({ active})=>(active ?'2px 5px' :'2px 3px')};
3740
&:hover {
3841
cursor: pointer;
3942
font-weight: bold;
4043
background:${theme('article.reactionHoverBg')};
41-
border-radius: 6px;
4244
}
4345
`
4446
exportconstReactionName=styled.div`

‎containers/ArticleViwer/logic.js‎

Lines changed: 26 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
importSR71from'../../utils/network/sr71'
2+
importRfrom'ramda'
23

34
import{
45
asyncRes,
@@ -28,13 +29,12 @@ let store = null
2829
letsub$=null
2930

3031
exportfunctiononReaction(thread,action,userDid,{ id}){
31-
/*
32-
debug('onReaction thread: ', thread)
33-
debug('onReaction action: ', action)
34-
debug('onReaction userDid: ', userDid)
35-
debug('onReaction id: ', id)
36-
*/
37-
constargs={ id, thread, action}
32+
/* debug('onReaction thread: ', thread) */
33+
/* debug('onReaction action: ', action) */
34+
// debug('onReaction userDid: ', store.isLogin)
35+
/* debug('onReaction id: ', id) */
36+
37+
constargs={ id,thread:R.toUpper(thread), action}
3838

3939
returnuserDid
4040
?sr71$.mutate(S.undoReaction,args)
@@ -62,21 +62,23 @@ function loadJob({ id }) {
6262
constuserHasLogin=store.isLogin
6363
constvariables={ id, userHasLogin}
6464
loading()
65+
debug('loadJob variables: ',variables)
6566
sr71$.query(S.job,variables)
6667
}
6768

68-
functionreloadReactions(article){
69-
constvariables={
70-
id:article.id,
69+
functionreloadReactions({ id}){
70+
switch(store.activeThread){
71+
caseTHREAD.JOB:{
72+
returnsr71$.query(S.jobReactionRes,{ id})
73+
}
74+
default:{
75+
returnsr71$.query(S.postReactionRes,{ id})
76+
}
7177
}
72-
debug('reloadReactions: ',variables)
73-
74-
sr71$.query(S.reactionResult,variables)
7578
}
7679

7780
exportfunctiononEdit(thread){
7881
/* debug('onEdit', store.viewingPost) */
79-
debug('onEdit viewingData: ',store.viewingData)
8082
switch(thread){
8183
caseTHREAD.POST:{
8284
returndispatchEvent(EVENT.PREVIEW_OPEN,{
@@ -118,44 +120,38 @@ const openAttachment = att => {
118120
// ###############################
119121
// Data & Error handlers
120122
// ###############################
121-
122-
functioncontentLoaded(content){
123-
store.setViewing(content)
124-
loading(false)
125-
}
126-
127123
constDataSolver=[
128124
{
129125
match:asyncRes('reaction'),
130126
action:({ reaction})=>{
131-
// TODO: should be trigger
132127
debug('get reaction: ',reaction)
133-
reloadReactions(reaction)
128+
returnreloadReactions(reaction)
134129
},
135130
},
136131
{
137132
match:asyncRes('undoReaction'),
138-
action:({ undoReaction})=>{
139-
debug('get undoReaction: ',undoReaction)
140-
/* const info = res[TYPE.UNDO_REACTION] */
141-
reloadReactions(undoReaction)
142-
},
133+
action:({ undoReaction})=>reloadReactions(undoReaction),
143134
},
144135
{
145136
match:asyncRes(EVENT.PREVIEW_CLOSED),
146137
action:()=>{
147138
sr71$.stop()
148-
/* store.load(TYPE.POST, {}) */
149139
loading(false)
150140
},
151141
},
152142
{
153143
match:asyncRes('post'),
154-
action:({ post})=>contentLoaded({ post}),
144+
action:({ post})=>{
145+
store.setViewing({post:R.merge(store.viewingData,post)})
146+
loading(false)
147+
},
155148
},
156149
{
157150
match:asyncRes('job'),
158-
action:({ job})=>contentLoaded({ job}),
151+
action:({ job})=>{
152+
store.setViewing({job:R.merge(store.viewingData,job)})
153+
loading(false)
154+
},
159155
},
160156
]
161157

‎containers/ArticleViwer/schema.js‎

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,19 @@ const post = gql`
2222
}
2323
}
2424
`
25-
constjob=gql`
25+
constpostReactionRes=gql`
2626
query($id: ID!) {
27+
post(id: $id) {
28+
id
29+
favoritedCount
30+
starredCount
31+
viewerHasFavorited
32+
viewerHasStarred
33+
}
34+
}
35+
`
36+
constjob=gql`
37+
query($id: ID!, $userHasLogin: Boolean!) {
2738
job(id: $id) {
2839
id
2940
title
@@ -40,22 +51,20 @@ const job = gql`
4051
linkAddr
4152
insertedAt
4253
updatedAt
54+
favoritedCount
55+
viewerHasFavorited @include(if: $userHasLogin)
4356
}
4457
}
4558
`
46-
constreactionResult=gql`
59+
constjobReactionRes=gql`
4760
query($id: ID!) {
48-
post(id: $id) {
61+
job(id: $id) {
4962
id
50-
title
5163
favoritedCount
52-
starredCount
5364
viewerHasFavorited
54-
viewerHasStarred
5565
}
5666
}
5767
`
58-
5968
constreaction=gql`
6069
mutation($id: ID!, $action: String!, $thread: CmsThread!) {
6170
reaction(id: $id, action: $action, thread: $thread) {
@@ -74,11 +83,12 @@ const undoReaction = gql`
7483

7584
constschema={
7685
post,
86+
postReactionRes,
7787
job,
88+
jobReactionRes,
7889
// viewerReactions,
7990
reaction,
8091
undoReaction,
81-
reactionResult,
8292
}
8393

8494
exportdefaultschema

‎containers/ArticleViwer/store.js‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ const ArticleViwerStore = t
3838
getviewingData(){
3939
returnself.root.viewingData
4040
},
41+
getactiveThread(){
42+
const{ activeThread}=self.root.viewing
43+
returnactiveThread
44+
},
4145
}))
4246
.actions(self=>({
4347
setViewing(sobj){

‎containers/PostsThread/logic.js‎

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,7 @@ let store = null
3333
letsub$=null
3434

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

4338
exportconstinAnchor=()=>store.setHeaderFix(false)
4439
exportconstoutAnchor=()=>store.setHeaderFix(true)
@@ -94,9 +89,8 @@ export function onTitleSelect(post) {
9489
})
9590
}
9691

97-
exportfunctioncreateContent(){
92+
exportconstcreateContent=()=>
9893
dispatchEvent(EVENT.PREVIEW_OPEN,{type:TYPE.PREVIEW_POST_CREATE})
99-
}
10094

10195
constDataSolver=[
10296
{

‎containers/VideosThread/logic.js‎

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,7 @@ const debug = makeDebugger('L:VideosThread')
3030

3131
letstore=null
3232

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

4035
exportfunctionloadVideos(page=1){
4136
const{ mainPath}=store.curRoute
@@ -62,14 +57,11 @@ export function loadVideos(page = 1) {
6257

6358
exportfunctiononTitleSelect(video){
6459
store.setViewing({ video})
65-
debug('onTitleSelect: ',video)
6660

67-
/*
6861
dispatchEvent(EVENT.PREVIEW_OPEN,{
6962
type:TYPE.PREVIEW_VIDEO_VIEW,
7063
data:video,
7164
})
72-
*/
7365
}
7466

7567
exportfunctioncreateContent(){

‎stores/SharedModel/Job.js‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ export const Job = t.model('Job', {
2727
views:t.optional(t.number,0),
2828
favoritedCount:t.optional(t.number,0),
2929
starredCount:t.optional(t.number,0),
30+
viewerHasFavorited:t.optional(t.boolean,false),
31+
// viewerHasStarred: t.optional(t.boolean, false),
3032

3133
insertedAt:t.optional(t.string,''),
3234
updatedAt:t.optional(t.string,''),

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp