Skip to content

Commit

Permalink
musician comment bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
miaowing committed Jun 16, 2019
1 parent 06015a2 commit 108ef46
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 61 deletions.
18 changes: 9 additions & 9 deletions src/actions/UserAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ export class UserAction {
dispatch({
type: NETWORK_STATUS,
action: UPDATE_PROPERTY,
path: `${ LOVE }_${ UPDATE_PROPERTY }_musicians`,
path: `${LOVE}_${UPDATE_PROPERTY}_musicians`,
data: { loading: true, nodata: false }
});

dispatch({
type: NETWORK_STATUS,
action: UPDATE_PROPERTY,
path: `${ MUSICIAN }_${ UPDATE_PROPERTY }_followers`,
path: `${MUSICIAN}_${UPDATE_PROPERTY}_followers`,
data: { loading: true, nodata: false }
});

Expand All @@ -52,23 +52,23 @@ export class UserAction {
})) as IUser[];

if (page !== 1) {
const existUsers = get(state(), `musician[${ userId }].followers`, []);
const existUsers = get(state(), `musician[${userId}].followers`, []);
users = existUsers.concat(users);
}

dispatch({ type: MUSICIAN, action: UPDATE_PROPERTY, path: `${ userId }.followers`, data: users });
dispatch({ type: MUSICIAN, action: UPDATE_PROPERTY, path: `${userId}.followers`, data: users });
dispatch({ type: LOVE, action: UPDATE_PROPERTY, path: 'musicians', data: users });

dispatch({
type: NETWORK_STATUS,
action: UPDATE_PROPERTY,
path: `${ LOVE }_${ UPDATE_PROPERTY }_musicians`,
path: `${LOVE}_${UPDATE_PROPERTY}_musicians`,
data: { loading: false, nodata: response.data.data.length === 0 }
});
dispatch({
type: NETWORK_STATUS,
action: UPDATE_PROPERTY,
path: `${ MUSICIAN }_${ UPDATE_PROPERTY }_followers`,
path: `${MUSICIAN}_${UPDATE_PROPERTY}_followers`,
data: { loading: false, nodata: response.data.data.length === 0 }
});
}
Expand Down Expand Up @@ -97,7 +97,7 @@ export class UserAction {
return message.error(response.data.message)
}

dispatch({ type: MUSICIAN, action: UPDATE_PROPERTY, path: `['${ userId }'].isFollow`, data: true });
dispatch({ type: MUSICIAN, action: UPDATE_PROPERTY, path: `['${userId}'].isFollow`, data: true });
}
}

Expand All @@ -113,7 +113,7 @@ export class UserAction {
return message.error(response.data.message)
}

dispatch({ type: MUSICIAN, action: UPDATE_PROPERTY, path: `['${ userId }'].isFollow`, data: false });
dispatch({ type: MUSICIAN, action: UPDATE_PROPERTY, path: `['${userId}'].isFollow`, data: false });
}
}

Expand Down Expand Up @@ -216,7 +216,7 @@ export class UserAction {
public static comment(userId: string, content: string, replyUserId?: string, commentId?: string) {
return async dispatch => {
const url = 'http://mobileapi.5sing.kugou.com/comments/create';
const form = { rootId: userId, content, owner: userId, rootKind: 'guestBoot', replyUserId, commentId };
const form = { rootId: userId, content, owner: userId, rootKind: 'guestBook', replyUserId, commentId };
const response: AxiosResponse<I5singResponse<any>> = await instance.post(
url,
qs.stringify(form)
Expand Down
91 changes: 46 additions & 45 deletions src/components/CommentList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export interface ICommentListProps {
commentLoading?: boolean;
replyLoading?: boolean;
disableChildReply?: boolean;
hideLikeBtn?: boolean;
}

export class CommentList extends React.Component<ICommentListProps> {
Expand Down Expand Up @@ -44,70 +45,70 @@ export class CommentList extends React.Component<ICommentListProps> {
return null;
}
const commentList = comments.map(comment => <Comment
key={ comment.id }
actions={ [
key={comment.id}
actions={[
this.props.hideLikeBtn ? '' : <span>
<Tooltip title="赞">
<Icon type="like"
onClick={() => this.props.onLike(comment.id, !comment.isLike)}
theme={comment.isLike ? 'filled' : 'outlined'}/>
</Tooltip>
<span style={{ paddingLeft: 8, cursor: 'auto' }}>{comment.like}</span>
</span>,
<span>
<Tooltip title="赞">
<Icon type="like"
onClick={ () => this.props.onLike(comment.id, !comment.isLike) }
theme={ comment.isLike ? 'filled' : 'outlined' }/>
</Tooltip>
<span style={ { paddingLeft: 8, cursor: 'auto' } }>{ comment.like }</span>
</span>,
<span>
{ this.state.reply && this.state.reply.id === comment.id ?
<span className={ styles.reply_input }>
<Input.Search enterButton="回复"
onSearch={ content => this.handleOnReply(comment, content) }/>
</span> :
<span onClick={ () => this.handleReply(comment) }> 回复 </span>
}
</span>
] }
author={ <a>{ comment.user.nickname }</a> }
avatar={ <Avatar src={ comment.user.image } alt={ comment.user.nickname }/> }
content={ comment.content }>
{ comment.replies.map(reply => <Comment
key={ reply.id }
actions={ [
{this.state.reply && this.state.reply.id === comment.id ?
<span className={styles.reply_input}>
<Input.Search enterButton="回复"
onSearch={content => this.handleOnReply(comment, content)}/>
</span> :
<span onClick={() => this.handleReply(comment)}> 回复 </span>
}
</span>
]}
author={<a>{comment.user.nickname}</a>}
avatar={<Avatar src={comment.user.image} alt={comment.user.nickname}/>}
content={comment.content}>
{comment.replies.map(reply => <Comment
key={reply.id}
actions={[
<span>
{ this.props.disableChildReply ? '' : this.state.reply && this.state.reply.id === reply.id ?
<span className={ styles.reply_input }>
{this.props.disableChildReply ? '' : this.state.reply && this.state.reply.id === reply.id ?
<span className={styles.reply_input}>
<Input.Search enterButton="回复"
onSearch={ content => this.props.onReply(reply.id, reply.user.id, content) }/>
onSearch={content => this.props.onReply(reply.id, reply.user.id, content)}/>
</span> :
<span onClick={ () => this.handleReply(reply) }> 回复 </span>
<span onClick={() => this.handleReply(reply)}> 回复 </span>
}
</span>
] }
author={ <span>
<a>{ reply.user.nickname }</a> 回复 <a>{ reply.replyUser.nickname }</a>
</span> }
avatar={ <Avatar src={ reply.user.image } alt={ reply.user.nickname }/> }
content={ reply.content }/>) }
]}
author={<span>
<a>{reply.user.nickname}</a> 回复 <a>{reply.replyUser.nickname}</a>
</span>}
avatar={<Avatar src={reply.user.image} alt={reply.user.nickname}/>}
content={reply.content}/>)}
</Comment>);

return this.props.wrap ? <Card title={ title }>
{ commentList }
return this.props.wrap ? <Card title={title}>
{commentList}
</Card> : commentList;
}

render() {
const { comments = [], hots = [] } = this.props;
const content = this.state.comment;
return <div>
<Card title={ this.props.title || '评论' }>
<Card title={this.props.title || '评论'}>
<Editor
loading={ this.props.commentLoading }
onChange={ comment => this.setState({
loading={this.props.commentLoading}
onChange={comment => this.setState({
comment,
replyUser: comment === '' ? null : this.state.reply
}) }
onSubmit={ comment => this.props.onSubmit(comment) }
comment={ content }/>
})}
onSubmit={comment => this.props.onSubmit(comment)}
comment={content}/>
</Card>
{ this.renderComments(hots, '热门') }
{ this.renderComments(comments, '最新') }
{this.renderComments(hots, '热门')}
{this.renderComments(comments, '最新')}
</div>
}
}
15 changes: 8 additions & 7 deletions src/modules/musician/MusicianGuestBook.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,14 @@ export class MusicianGuestBook extends React.Component<IMusicianGuestBookProps>

render() {
const network = get(this.props.net, USER_COMMENT, { nodata: false, loading: true });
return <div style={ { padding: '0 30px' } }>
<EndLoader target="main" onLoad={ () => !network.nodata && this.nextPage() }>
<CommentList comments={ this.props.comments } hots={ [] }
title="留言" wrap={ false } disableChildReply={ true }
onReply={ (commentId, userId, content) => this.comment(content, content, commentId) }
onSubmit={ content => this.comment(content) }/>
<Loading loading={ network.loading } nodata={ network.nodata }/>
return <div style={{ padding: '0 30px' }}>
<EndLoader target="main" onLoad={() => !network.nodata && this.nextPage()}>
<CommentList comments={this.props.comments} hots={[]}
hideLikeBtn={true}
title="留言" wrap={false} disableChildReply={true}
onReply={(commentId, userId, content) => this.comment(content, commentId, userId)}
onSubmit={content => this.comment(content)}/>
<Loading loading={network.loading} nodata={network.nodata}/>
</EndLoader>
</div>
}
Expand Down

0 comments on commit 108ef46

Please sign in to comment.