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.

Commitb27f50b

Browse files
committed
feat(Video): add reactions
1 parentaa68389 commitb27f50b

File tree

8 files changed

+113
-134
lines changed

8 files changed

+113
-134
lines changed

‎containers/VideoViewer/Header.js‎

Lines changed: 0 additions & 33 deletions
This file was deleted.

‎containers/VideoViewer/index.js‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@
77
importReactfrom'react'
88
import{inject,observer}from'mobx-react'
99

10+
import{ArticleHeader}from'../../components'
11+
1012
import{Wrapper}from'./styles'
1113

1214
importPlayWindowfrom'./PlayWindow'
1315
importInfoBoardfrom'./InfoBoard'
1416

15-
import{makeDebugger,storePlug}from'../../utils'
16-
17-
importHeaderfrom'./Header'
1817
importBodyHeaderfrom'./BodyHeader'
1918

19+
import{makeDebugger,storePlug,THREAD}from'../../utils'
2020
import*aslogicfrom'./logic'
2121
/* eslint-disable no-unused-vars */
2222
constdebug=makeDebugger('C:VideoViewer')
@@ -25,7 +25,6 @@ const debug = makeDebugger('C:VideoViewer')
2525
classVideoViewerContainerextendsReact.Component{
2626
componentWillMount(){
2727
const{ videoViewer, attachment}=this.props
28-
debug('attachment: ',attachment)
2928
logic.init(videoViewer,attachment)
3029
}
3130

@@ -35,7 +34,12 @@ class VideoViewerContainer extends React.Component {
3534

3635
return(
3736
<Wrapper>
38-
<Headerdata={viewingData}/>
37+
<ArticleHeader
38+
data={viewingData}
39+
author={viewingData.author}
40+
onReaction={logic.onReaction}
41+
thread={THREAD.VIDEO}
42+
/>
3943
<BodyHeader/>
4044
<PlayWindowposter={viewingData.poster}/>
4145
<InfoBoarddata={viewingData}/>

‎containers/VideoViewer/logic.js‎

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
1-
//import R from 'ramda'
1+
importRfrom'ramda'
22

3-
import{makeDebugger,$solver,asyncErr,ERR,TYPE}from'../../utils'
3+
import{
4+
makeDebugger,
5+
$solver,
6+
asyncRes,
7+
asyncErr,
8+
ERR,
9+
TYPE,
10+
}from'../../utils'
411
importSR71from'../../utils/network/sr71'
512

6-
//import S from './schema'
13+
importSfrom'./schema'
714

815
constsr71$=newSR71()
916
letsub$=null
@@ -14,12 +21,33 @@ const debug = makeDebugger('L:VideoViewer')
1421

1522
letstore=null
1623

17-
exportfunctionsomeMethod(){}
24+
functionloadVideo({ id}){
25+
constuserHasLogin=store.isLogin
26+
constvariables={ id, userHasLogin}
27+
/* loading() */
28+
sr71$.query(S.video,variables)
29+
}
30+
31+
exportfunctiononReaction(thread,action,userDid,{ id}){
32+
/*
33+
debug('onReaction thread: ', thread)
34+
debug('onReaction action: ', action)
35+
debug('onReaction userDid: ', store.isLogin)
36+
debug('onReaction id: ', id)
37+
*/
38+
39+
constargs={ id,thread:R.toUpper(thread), action}
40+
41+
returnuserDid
42+
?sr71$.mutate(S.undoReaction,args)
43+
:sr71$.mutate(S.reaction,args)
44+
}
1845

1946
constopenAttachment=att=>{
2047
if(!att)returnfalse
2148
const{ type}=att
2249
if(type===TYPE.PREVIEW_VIDEO_VIEW){
50+
loadVideo(att)
2351
store.setViewing({video:att})
2452
}
2553
}
@@ -28,7 +56,20 @@ const openAttachment = att => {
2856
// Data & Error handlers
2957
// ###############################
3058

31-
constDataSolver=[]
59+
constDataSolver=[
60+
{
61+
match:asyncRes('video'),
62+
action:({ video})=>{
63+
store.setViewing({video:R.merge(store.viewingData,video)})
64+
/* loading(false) */
65+
},
66+
},
67+
{
68+
match:asyncRes('reaction'),
69+
action:({ reaction})=>
70+
sr71$.query(S.videoReactionRes,{id:reaction.id}),
71+
},
72+
]
3273
constErrSolver=[
3374
{
3475
match:asyncErr(ERR.CRAPHQL),

‎containers/VideoViewer/schema.js‎

Lines changed: 49 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,64 @@
11
importgqlfrom'graphql-tag'
22

3-
constsimpleMutation=gql`
4-
mutation($id: ID!) {
5-
post(id: $id) {
3+
constvideo=gql`
4+
query($id: ID!, $userHasLogin: Boolean!) {
5+
video(id: $id) {
66
id
7+
title
8+
poster
9+
desc
10+
duration
11+
author {
12+
id
13+
nickname
14+
avatar
15+
}
16+
source
17+
link
18+
originalAuthor
19+
originalAuthorLink
20+
views
21+
publishAt
22+
insertedAt
23+
updatedAt
24+
favoritedCount
25+
starredCount
26+
viewerHasFavorited @include(if: $userHasLogin)
27+
viewerHasStarred @include(if: $userHasLogin)
728
}
829
}
930
`
10-
constsimpleQuery=gql`
11-
query($filter: filter!) {
12-
post(id: $id) {
31+
constvideoReactionRes=gql`
32+
query($id: ID!) {
33+
video(id: $id) {
34+
id
35+
favoritedCount
36+
starredCount
37+
viewerHasFavorited
38+
viewerHasStarred
39+
}
40+
}
41+
`
42+
constreaction=gql`
43+
mutation($id: ID!, $action: String!, $thread: CmsThread!) {
44+
reaction(id: $id, action: $action, thread: $thread) {
45+
id
46+
}
47+
}
48+
`
49+
constundoReaction=gql`
50+
mutation($id: ID!, $action: String!, $thread: CmsThread!) {
51+
undoReaction(id: $id, action: $action, thread: $thread) {
1352
id
1453
}
1554
}
1655
`
1756

1857
constschema={
19-
simpleMutation,
20-
simpleQuery,
58+
video,
59+
reaction,
60+
undoReaction,
61+
videoReactionRes,
2162
}
2263

2364
exportdefaultschema

‎containers/VideoViewer/store.js‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,15 @@ import { markStates, makeDebugger } from '../../utils'
1111
constdebug=makeDebugger('S:VideoViewer')
1212
/* eslint-enable no-unused-vars */
1313

14-
// NOTE: add me to ../../stores/index && ../../stores/RootStore/index
1514
constVideoViewer=t
1615
.model('VideoViewer',{})
1716
.views(self=>({
1817
getroot(){
1918
returngetParent(self)
2019
},
20+
getisLogin(){
21+
returnself.root.account.isLogin
22+
},
2123
getviewingData(){
2224
returnself.root.viewingData
2325
},

‎containers/VideoViewer/styles/body_header.js‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@ export const Wrapper = styled.div`
88
width: 100%;
99
display: flex;
1010
justify-content: space-between;
11-
align-items: flex-start;
12-
padding: 10px 35px;
13-
padding-bottom: 5px;
11+
align-items: center;
12+
padding: 8px 32px;
1413
`
1514
exportconstMoreWrapper=styled.div`
1615
display: flex;

‎containers/VideoViewer/styles/header.js‎

Lines changed: 0 additions & 79 deletions
This file was deleted.

‎stores/SharedModel/Video.js‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ export const Video = t.model('Video', {
2727
communities:t.optional(t.array(Community),[]),
2828
tags:t.optional(t.array(Tag),[]),
2929
/* comments: t.optional(t.array(Comment), []), */
30+
favoritedCount:t.optional(t.number,0),
31+
starredCount:t.optional(t.number,0),
32+
viewerHasFavorited:t.optional(t.boolean,false),
33+
viewerHasStarred:t.optional(t.boolean,false),
3034

3135
publishAt:t.maybeNull(t.string),
3236
insertedAt:t.optional(t.string,''),

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp