Toggle navigation
Toggle navigation
This project
Loading...
Sign in
mobile
/
YH_RNComponent
·
Commits
Go to a project
GitLab
Go to group
Project
Activity
Files
Commits
Pipelines
0
Builds
0
Graphs
Milestones
Issues
0
Merge Requests
0
Members
Labels
Wiki
Forks
Network
Create a new issue
Download as
Email Patches
Plain Diff
Browse Files
Authored by
孙凯
8 years ago
Commit
0154d0ae4eff098b90a41f0f19611fa074acfc87
1 parent
7cad7f6e
add 评论 review chenlin
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
81 additions
and
15 deletions
js/guang/components/detail/Comments.js
js/guang/components/detail/Detail.js
js/guang/constants/actionTypes.js
js/guang/containers/DetailContainer.js
js/guang/reducers/detail/detailActions.js
js/guang/reducers/detail/detailInitialState.js
js/guang/reducers/detail/detailReducer.js
js/guang/components/detail/Comments.js
View file @
0154d0a
...
...
@@ -57,7 +57,7 @@ export default class Comments extends React.Component {
<
Text
style
=
{
styles
.
time
}
>
{
create_time
}
<
/Text
>
<
/View
>
<
View
style
=
{
styles
.
commentView
}
>
<
TouchableOpacity
onPress
=
{()
=>
{
this
.
props
.
on
Comment
&&
this
.
props
.
on
Comment
(
id
)}}
>
<
TouchableOpacity
onPress
=
{()
=>
{
this
.
props
.
on
PressComment
&&
this
.
props
.
onPress
Comment
(
id
)}}
>
{
relayTo
?
<
Text
style
=
{
styles
.
commentText
}
>
回复
<
Text
style
=
{
styles
.
replayName
}
>
{
relayToUsername
}
<
/Text
>
...
...
js/guang/components/detail/Detail.js
View file @
0154d0a
...
...
@@ -19,6 +19,7 @@ import LoadingIndicator from '../../../common/components/LoadingIndicator';
import
RecommentProducts
from
'./RecommentProducts'
;
import
Comments
from
'./Comments'
;
import
CommentsTitle
from
'./CommentsTitle'
;
import
LoadMoreIndicator
from
'../../../common/components/LoadMoreIndicator'
;
import
ReactNative
,
{
View
,
...
...
@@ -44,7 +45,7 @@ export default class Detail extends Component {
this
.
renderRow
=
this
.
renderRow
.
bind
(
this
);
this
.
renderHeader
=
this
.
renderHeader
.
bind
(
this
);
this
.
scrollTo
=
this
.
scrollTo
.
bind
(
this
);
this
.
_on
Comment
=
this
.
_on
Comment
.
bind
(
this
);
this
.
_on
PressComment
=
this
.
_onPress
Comment
.
bind
(
this
);
this
.
_onSubmitEditing
=
this
.
_onSubmitEditing
.
bind
(
this
);
this
.
listView
=
null
;
this
.
dataSource
=
new
ListView
.
DataSource
({
...
...
@@ -117,7 +118,7 @@ export default class Detail extends Component {
this
.
setState
({
replyTo
:
0
});
}
_onComment
(
id
){
_on
Press
Comment
(
id
){
this
.
setState
({
replyTo
:
id
});
this
.
refs
.
textInput
&&
this
.
refs
.
textInput
.
focus
();
}
...
...
@@ -201,7 +202,7 @@ export default class Detail extends Component {
);
}
else
if
(
sectionID
==
'comments'
){
return
(
<
Comments
resource
=
{
rowData
}
onThumbsUp
=
{
this
.
props
.
addPraiseForComments
}
on
Comment
=
{
this
.
_on
Comment
}
/
>
<
Comments
resource
=
{
rowData
}
onThumbsUp
=
{
this
.
props
.
addPraiseForComments
}
on
PressComment
=
{
this
.
_onPress
Comment
}
/
>
);
}
else
if
(
sectionID
==
'space'
){
return
(
...
...
@@ -250,6 +251,10 @@ export default class Detail extends Component {
let
isFavorIcon
=
isFavor
==
'Y'
?
require
(
'../../image/sc_icon.png'
)
:
require
(
'../../image/wsc_icon.png'
);
let
isPraiseIcon
=
isPraise
==
'Y'
?
require
(
'../../image/sc_icon.png'
)
:
require
(
'../../image/wsc_icon.png'
);
let
comlist
=
commentsList
?
commentsList
.
toJS
():
null
;
let
isLoadingMore
=
comlist
&&
comlist
.
isFetching
&&
comlist
.
page
>
0
;
let
endReached
=
comlist
?
comlist
.
endReached
:
false
;
return
(
<
View
style
=
{
styles
.
container
}
>
{
!
isFetching
?
<
Animated
.
View
style
=
{{
width
:
width
,
height
:
height
-
64
,
marginTop
:
this
.
state
.
viewMarginTop
}}
>
...
...
@@ -263,6 +268,21 @@ export default class Detail extends Component {
renderRow
=
{
this
.
renderRow
}
renderHeader
=
{
this
.
renderHeader
}
keyboardDismissMode
=
{
'on-drag'
}
renderFooter
=
{()
=>
{
if
(
endReached
)
{
return
<
View
style
=
{
styles
.
placeholder
}
/>
;
}
else
{
return
<
LoadMoreIndicator
isVisible
=
{
isLoadingMore
}
animating
=
{
true
}
/>
;
}
}}
onEndReached
=
{()
=>
{
if
(
comlist
&&
comlist
.
data
&&
comlist
.
data
.
length
>
0
)
{
this
.
props
.
onEndReached
&&
this
.
props
.
onEndReached
();
}
}}
/
>
<
View
style
=
{{
width
:
width
,
height
:
1
,
backgroundColor
:
'#e5e5e5'
,}}
/
>
<
View
style
=
{
styles
.
commtentBottomView
}
>
...
...
@@ -275,11 +295,11 @@ export default class Detail extends Component {
clearButtonMode
=
'while-editing'
ref
=
'textInput'
/>
<
TouchableOpacity
onPress
=
{()
=>
{
this
.
props
.
onPressConcerns
&&
this
.
props
.
onPressConcerns
(
isFavor
)}
this
.
props
.
onPressConcerns
&&
this
.
props
.
onPressConcerns
(
isFavor
==
'Y'
?
'N'
:
'Y'
)}
}
>
<
Image
style
=
{
styles
.
favIcon
}
source
=
{
isFavorIcon
}
/
>
<
/TouchableOpacity
>
<
TouchableOpacity
onPress
=
{()
=>
{
this
.
props
.
addPraiseForArtivle
&&
this
.
props
.
addPraiseForArtivle
(
isPraise
)}}
>
<
TouchableOpacity
onPress
=
{()
=>
{
this
.
props
.
addPraiseForArtivle
&&
this
.
props
.
addPraiseForArtivle
(
isPraise
==
'Y'
?
'N'
:
'Y'
)}}
>
<
Image
style
=
{
styles
.
thumbsUpIcon
}
source
=
{
isPraiseIcon
}
/
>
<
/TouchableOpacity
>
<
/View
>
...
...
@@ -331,4 +351,8 @@ let styles = StyleSheet.create({
width
:
20
,
marginLeft
:
20
,
},
placeholder
:
{
width
,
height
:
15
,
},
});
...
...
js/guang/constants/actionTypes.js
View file @
0154d0a
...
...
@@ -92,4 +92,6 @@ export default keyMirror({
CANCEL_FAVORITE_REQUEST
:
null
,
CANCEL_FAVORITE_SUCCESS
:
null
,
CANCEL_FAVORITE_FAILURE
:
null
,
RESET_COMMENTS_LIST_PAGE_INFO
:
null
,
});
...
...
js/guang/containers/DetailContainer.js
View file @
0154d0a
...
...
@@ -63,7 +63,7 @@ class DetailContainer extends Component {
this
.
_onSubmitForComment
=
this
.
_onSubmitForComment
.
bind
(
this
);
this
.
_addPraiseForArtivle
=
this
.
_addPraiseForArtivle
.
bind
(
this
);
this
.
_addPraiseForComments
=
this
.
_addPraiseForComments
.
bind
(
this
);
this
.
_onEndReached
=
this
.
_onEndReached
.
bind
(
this
);
}
componentDidMount
()
{
...
...
@@ -85,15 +85,19 @@ class DetailContainer extends Component {
}
_onPressConcerns
(
isFav
){
if
(
isFav
==
'
N
'
)
{
if
(
isFav
==
'
Y
'
)
{
this
.
props
.
actions
.
addFavorite
();
}
else
{
this
.
props
.
actions
.
cancelFavorite
();
}
}
_onEndReached
()
{
this
.
props
.
actions
.
getCommentsList
();
}
_addPraiseForArtivle
(
isPraise
){
if
(
isPraise
==
'
N
'
)
{
if
(
isPraise
==
'
Y
'
)
{
this
.
props
.
actions
.
praiseForArtivle
();
}
else
{
this
.
props
.
actions
.
cancelPraiseForArtivle
();
...
...
@@ -260,6 +264,8 @@ class DetailContainer extends Component {
onSubmitForComment
=
{
this
.
_onSubmitForComment
}
addPraiseForArtivle
=
{
this
.
_addPraiseForArtivle
}
addPraiseForComments
=
{
this
.
_addPraiseForComments
}
onEndReached
=
{
this
.
_onEndReached
}
/
>
<
/View
>
);
...
...
js/guang/reducers/detail/detailActions.js
View file @
0154d0a
...
...
@@ -81,6 +81,9 @@ const {
CANCEL_FAVORITE_REQUEST
,
CANCEL_FAVORITE_SUCCESS
,
CANCEL_FAVORITE_FAILURE
,
RESET_COMMENTS_LIST_PAGE_INFO
,
}
=
require
(
'../../constants/actionTypes'
).
default
;
export
function
setArticleId
(
id
)
{
...
...
@@ -713,6 +716,12 @@ function parseWeChatData(json) {
}
}
function
resetCommentsListPageInfo
()
{
return
{
type
:
RESET_COMMENTS_LIST_PAGE_INFO
,
}
}
function
getCommentsListRequest
()
{
return
{
type
:
GET_COMMENTS_LIST_REQUEST
,
...
...
@@ -737,7 +746,12 @@ export function getCommentsList() {
return
(
dispatch
,
getState
)
=>
{
let
{
app
,
detail
}
=
getState
();
let
{
articleId
,
article
,
commentsList
}
=
detail
;
let
page
=
commentsList
.
page
;
if
(
commentsList
.
isFetching
||
commentsList
.
endReached
||
commentsList
.
error
)
{
return
;
}
let
page
=
commentsList
.
page
+
1
;
let
list
=
commentsList
.
data
;
let
limit
=
commentsList
.
limit
;
let
total_page
=
commentsList
.
total_page
;
...
...
@@ -748,7 +762,7 @@ export function getCommentsList() {
dispatch
(
getCommentsListRequest
());
return
new
DetailService
(
app
.
serviceHost
).
getCommentsList
(
articleId
,
page
,
limit
)
.
then
(
json
=>
{
let
param
=
parseCommentsData
(
json
)
let
param
=
parseCommentsData
(
list
,
json
)
dispatch
(
getCommentsListSuccess
(
param
));
})
.
catch
(
error
=>
{
...
...
@@ -757,23 +771,32 @@ export function getCommentsList() {
};
}
function
parseCommentsData
(
json
)
{
function
parseCommentsData
(
list
,
json
)
{
let
oldList
=
list
?
list
.
toJS
():[];
let
data
=
[];
let
page
=
1
;
let
page
=
0
;
let
total
=
0
;
let
total_page
=
0
;
let
endReached
=
0
;
if
(
json
)
{
data
=
json
.
list
;
page
=
json
.
page
;
total
=
json
.
total
;
total_page
=
json
.
total_page
;
endReached
=
json
.
page
==
json
.
total_page
;
}
if
(
json
.
page
>
1
)
{
data
=
[...
oldList
,
...
json
.
list
];
}
return
{
data
,
page
,
total
,
total_page
,
endReached
,
}
}
...
...
@@ -808,6 +831,8 @@ export function addCommentsForArtivle(content,replyTo) {
dispatch
(
addCommentsForArtivleRequest
());
return
new
DetailService
(
app
.
serviceHost
).
addCommentsForArtivle
(
article_id
,
uid
,
content
,
replyTo
)
.
then
(
json
=>
{
dispatch
(
resetCommentsListPageInfo
());
dispatch
(
getCommentsList
());
dispatch
(
addCommentsForArtivleSuccess
(
json
));
})
.
catch
(
error
=>
{
...
...
@@ -884,7 +909,6 @@ export function addPraiseForComments(comment_id,praise) {
let
{
app
,
detail
}
=
getState
();
let
{
articleId
,
article
}
=
detail
;
let
article_id
=
articleId
;
dispatch
(
addPraiseForCommentsRequest
());
return
new
DetailService
(
app
.
serviceHost
).
addPraiseForComments
(
comment_id
,
praise
,
article_id
)
.
then
(
json
=>
{
...
...
js/guang/reducers/detail/detailInitialState.js
View file @
0154d0a
...
...
@@ -47,10 +47,11 @@ let InitialState = Record({
isFetching
:
false
,
error
:
null
,
data
:
List
(),
page
:
1
,
page
:
0
,
total
:
0
,
total_page
:
0
,
limit
:
10
,
endReached
:
false
,
})),
addComment
:
new
(
Record
({
isFetching
:
false
,
...
...
js/guang/reducers/detail/detailReducer.js
View file @
0154d0a
...
...
@@ -79,6 +79,8 @@ const {
CANCEL_FAVORITE_SUCCESS
,
CANCEL_FAVORITE_FAILURE
,
RESET_COMMENTS_LIST_PAGE_INFO
,
}
=
require
(
'../../constants/actionTypes'
).
default
;
const
initialState
=
new
InitialState
;
...
...
@@ -226,12 +228,19 @@ export default function detailReducer(state=initialState, action) {
.
setIn
([
'commentsList'
,
'page'
],
action
.
payload
.
page
)
.
setIn
([
'commentsList'
,
'total'
],
action
.
payload
.
total
)
.
setIn
([
'commentsList'
,
'total_page'
],
action
.
payload
.
total_page
)
.
setIn
([
'commentsList'
,
'endReached'
],
action
.
payload
.
endReached
)
.
setIn
([
'commentsList'
,
'data'
],
Immutable
.
fromJS
(
action
.
payload
.
data
));
}
case
GET_COMMENTS_LIST_FAILURE
:
{
return
state
.
setIn
([
'commentsList'
,
'isFetching'
],
false
)
.
setIn
([
'commentsList'
,
'error'
],
action
.
payload
);
}
case
RESET_COMMENTS_LIST_PAGE_INFO
:
{
return
state
.
setIn
([
'commentsList'
,
'page'
],
0
)
.
setIn
([
'commentsList'
,
'total_page'
],
0
)
.
setIn
([
'commentsList'
,
'total'
],
0
)
.
setIn
([
'commentsList'
,
'endReached'
],
false
);
}
//资讯添加评论
case
ADD_COMMENTS_FOR_ARTIVLE_REQUEST
:
{
return
state
.
setIn
([
'addComment'
,
'isFetching'
],
true
)
...
...
Please
register
or
login
to post a comment