dev_local_scyd
parent
fc4a68932c
commit
fac2c50d17
@ -1,296 +1,299 @@
|
|||||||
import React,{ Component } from "react";
|
import React,{ Component } from "react";
|
||||||
import { Pagination } from "antd";
|
import { Pagination } from "antd";
|
||||||
|
|
||||||
import update from 'immutability-helper'
|
import update from 'immutability-helper'
|
||||||
import axios from 'axios'
|
import axios from 'axios'
|
||||||
import MemoDetailMDEditor from '../../../forums/MemoDetailMDEditor'
|
import MemoDetailMDEditor from '../../../forums/MemoDetailMDEditor'
|
||||||
|
|
||||||
import '../../../forums/Post.css'
|
import '../../../forums/Post.css'
|
||||||
import '../../../forums/RightSection.css'
|
import '../../../forums/RightSection.css'
|
||||||
import {ImageLayerOfCommentHOC} from '../../../page/layers/ImageLayerOfCommentHOC'
|
import {ImageLayerOfCommentHOC} from '../../../page/layers/ImageLayerOfCommentHOC'
|
||||||
|
|
||||||
import Comments from '../../../comment/Comments'
|
import Comments from '../../../comment/Comments'
|
||||||
// import './GraduateTopicReply.css'
|
// import './GraduateTopicReply.css'
|
||||||
import '../../common/courseMessage.css'
|
import '../../common/courseMessage.css'
|
||||||
import { generateComments, generateChildComments, _findById, handleContentBeforeCreateNew, addNewComment
|
import { generateComments, generateChildComments, _findById, handleContentBeforeCreateNew, addNewComment
|
||||||
, addSecondLevelComment, NEED_TO_WRITE_CONTENT, handleContentBeforeCreateSecondLevelComment
|
, addSecondLevelComment, NEED_TO_WRITE_CONTENT, handleContentBeforeCreateSecondLevelComment
|
||||||
, handleDeleteComment, handleCommentPraise, handleHiddenComment } from '../../common/CommentsHelper'
|
, handleDeleteComment, handleCommentPraise, handleHiddenComment } from '../../common/CommentsHelper'
|
||||||
const REPLY_PAGE_COUNT = 10
|
const REPLY_PAGE_COUNT = 10
|
||||||
const $ = window.$;
|
const $ = window.$;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
相比较GraduateTopicReply 改动的地方
|
相比较GraduateTopicReply 改动的地方
|
||||||
列表接口名 /graduation_tasks/${graduation_topic_id}/show_comment.json?parent_id=${parent.id}&limit=500
|
列表接口名 /graduation_tasks/${graduation_topic_id}/show_comment.json?parent_id=${parent.id}&limit=500
|
||||||
回复类型名 jour_type: this.props.jour_type,
|
回复类型名 jour_type: this.props.jour_type,
|
||||||
*/
|
*/
|
||||||
class CommonReply extends Component{
|
class CommonReply extends Component{
|
||||||
constructor(props){
|
constructor(props){
|
||||||
super(props);
|
super(props);
|
||||||
this.state={
|
this.state={
|
||||||
pageCount: 1
|
pageCount: 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount(){
|
componentDidMount(){
|
||||||
this.fetchReplies()
|
this.fetchReplies()
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
_getUser() {
|
_getUser() {
|
||||||
const { current_user } = this.props;
|
const { current_user } = this.props;
|
||||||
current_user.user_url = `/users/${current_user.login}`;
|
current_user.user_url = `/users/${current_user.login}`;
|
||||||
return current_user;
|
return current_user;
|
||||||
}
|
}
|
||||||
_findById = _findById
|
_findById = _findById
|
||||||
createNewComment = (commentContent, id, editor) => {
|
createNewComment = (commentContent, id, editor) => {
|
||||||
const graduation_topic_id = this.props.memo.id
|
const graduation_topic_id = this.props.memo.id
|
||||||
|
|
||||||
let content = handleContentBeforeCreateNew(commentContent);
|
let content = handleContentBeforeCreateNew(commentContent);
|
||||||
const { memo } = this.props;
|
const { memo } = this.props;
|
||||||
const url = `/users/reply_message.json`;
|
const url = `/users/reply_message.json`;
|
||||||
|
|
||||||
let { comments } = this.state;
|
let { comments } = this.state;
|
||||||
axios.post(url, {
|
axios.post(url, {
|
||||||
journals_for_message: {
|
journals_for_message: {
|
||||||
jour_type: this.props.jour_type,
|
jour_type: this.props.jour_type,
|
||||||
jour_id: graduation_topic_id,
|
jour_id: graduation_topic_id,
|
||||||
notes: content,
|
notes: content,
|
||||||
// m_parent_id
|
// m_parent_id
|
||||||
reply_id: memo.user_id || this.state.homework_user_id
|
reply_id: memo.user_id || this.state.homework_user_id
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
).then((response) => {
|
).then((response) => {
|
||||||
if (response.data.status === -1) {
|
if (response.data.status === -1) {
|
||||||
console.error('服务端异常')
|
console.error('服务端异常')
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// this.props.showNotification('帖子发表成功')
|
// this.props.showNotification('帖子发表成功')
|
||||||
|
|
||||||
if (response.data && response.data.id) {
|
if (response.data && response.data.id) {
|
||||||
const _id = response.data.id;
|
const _id = response.data.id;
|
||||||
// md
|
let mycontent= response.data.content;
|
||||||
editor.setValue && editor.setValue('')
|
|
||||||
this.refs.editor.close && this.refs.editor.close()
|
// md
|
||||||
|
editor.setValue && editor.setValue('')
|
||||||
const user = this._getUser();
|
this.refs.editor.close && this.refs.editor.close()
|
||||||
const isSuperAdmin = this.props.isSuperAdmin()
|
|
||||||
|
const user = this._getUser();
|
||||||
this.setState({
|
const isSuperAdmin = this.props.isSuperAdmin()
|
||||||
comments: addNewComment(this.state.comments, _id, content, user, isSuperAdmin, this),
|
|
||||||
total_count: this.state.total_count + 1
|
this.setState({
|
||||||
})
|
comments: addNewComment(this.state.comments, _id, mycontent, user, isSuperAdmin, this),
|
||||||
this.refs.editor.showEditor();
|
total_count: this.state.total_count + 1
|
||||||
|
})
|
||||||
}
|
this.refs.editor.showEditor();
|
||||||
}).catch((error) => {
|
|
||||||
console.log(error)
|
}
|
||||||
})
|
}).catch((error) => {
|
||||||
}
|
console.log(error)
|
||||||
replyComment = (commentContent, id, editor) => {
|
})
|
||||||
const { showNotification } = this.props;
|
}
|
||||||
// if (!commentContent || commentContent.length === 0) {
|
replyComment = (commentContent, id, editor) => {
|
||||||
// showNotification(NEED_TO_WRITE_CONTENT)
|
const { showNotification } = this.props;
|
||||||
// return;
|
// if (!commentContent || commentContent.length === 0) {
|
||||||
// }
|
// showNotification(NEED_TO_WRITE_CONTENT)
|
||||||
|
// return;
|
||||||
if (this.props.memo.id === id ) { // 回复帖子
|
// }
|
||||||
this.createNewComment(commentContent, id, editor);
|
|
||||||
return;
|
if (this.props.memo.id === id ) { // 回复帖子
|
||||||
}
|
this.createNewComment(commentContent, id, editor);
|
||||||
const url = `/users/reply_message.json`;
|
return;
|
||||||
|
}
|
||||||
const { comments } = this.state;
|
const url = `/users/reply_message.json`;
|
||||||
const user = this._getUser();
|
|
||||||
const graduation_topic_id = this.props.memo.id
|
const { comments } = this.state;
|
||||||
const commentIndex = this._findById(id, comments);
|
const user = this._getUser();
|
||||||
let comment = comments[commentIndex];
|
const graduation_topic_id = this.props.memo.id
|
||||||
|
const commentIndex = this._findById(id, comments);
|
||||||
commentContent = handleContentBeforeCreateSecondLevelComment(commentContent)
|
let comment = comments[commentIndex];
|
||||||
axios.post(url, {
|
|
||||||
journals_for_message: {
|
commentContent = handleContentBeforeCreateSecondLevelComment(commentContent)
|
||||||
// 'GraduationTask'
|
axios.post(url, {
|
||||||
jour_type: this.props.jour_type,
|
journals_for_message: {
|
||||||
jour_id: graduation_topic_id,
|
// 'GraduationTask'
|
||||||
notes: commentContent,
|
jour_type: this.props.jour_type,
|
||||||
m_parent_id: id,
|
jour_id: graduation_topic_id,
|
||||||
reply_id: comment.user_id
|
notes: commentContent,
|
||||||
}
|
m_parent_id: id,
|
||||||
},
|
reply_id: comment.user_id
|
||||||
{
|
}
|
||||||
}
|
},
|
||||||
).then((response) => {
|
{
|
||||||
if (response.data.id) {
|
}
|
||||||
let newId = response.data.id;
|
).then((response) => {
|
||||||
|
if (response.data.id) {
|
||||||
const newMemo2 = Object.assign({}, this.props.memo);
|
let newId = response.data.id;
|
||||||
newMemo2.total_count = newMemo2.total_count + 1;
|
let mycontent= response.data.content;
|
||||||
|
|
||||||
this.setState({
|
const newMemo2 = Object.assign({}, this.props.memo);
|
||||||
comments: addSecondLevelComment(comments, comment, commentIndex, newId, commentContent, user, editor),
|
newMemo2.total_count = newMemo2.total_count + 1;
|
||||||
memo: newMemo2,
|
|
||||||
total_count: this.state.total_count + 1
|
this.setState({
|
||||||
|
comments: addSecondLevelComment(comments, comment, commentIndex, newId, mycontent, user, editor),
|
||||||
})
|
memo: newMemo2,
|
||||||
}
|
total_count: this.state.total_count + 1
|
||||||
|
|
||||||
}).catch((error) => {
|
})
|
||||||
console.log(error)
|
}
|
||||||
})
|
|
||||||
}
|
}).catch((error) => {
|
||||||
|
console.log(error)
|
||||||
loadMoreChildComments = (parent) => {
|
})
|
||||||
const graduation_topic_id = this.props.memo.id
|
}
|
||||||
const course_id = this.props.course_id
|
|
||||||
const url = `/${this.props.apiRouteName}/${graduation_topic_id}/show_comment.json?parent_id=${parent.id}&limit=500`
|
loadMoreChildComments = (parent) => {
|
||||||
axios.get(url,{
|
const graduation_topic_id = this.props.memo.id
|
||||||
})
|
const course_id = this.props.course_id
|
||||||
.then((response) => {
|
const url = `/${this.props.apiRouteName}/${graduation_topic_id}/show_comment.json?parent_id=${parent.id}&limit=500`
|
||||||
const { comments } = response.data
|
axios.get(url,{
|
||||||
|
})
|
||||||
|
.then((response) => {
|
||||||
// const memo = Object.assign({}, this.state.memo)
|
const { comments } = response.data
|
||||||
// memo.sum_replies_count = sum_replies_count;
|
|
||||||
this.setState({
|
|
||||||
// memo,
|
// const memo = Object.assign({}, this.state.memo)
|
||||||
comments: generateChildComments(comments, this.state.comments, parent, this.transformReply)
|
// memo.sum_replies_count = sum_replies_count;
|
||||||
})
|
this.setState({
|
||||||
}).catch((error) => {
|
// memo,
|
||||||
console.log(error)
|
comments: generateChildComments(comments, this.state.comments, parent, this.transformReply)
|
||||||
})
|
})
|
||||||
}
|
}).catch((error) => {
|
||||||
|
console.log(error)
|
||||||
onPaginationChange = (pageCount) => {
|
})
|
||||||
this.setState({ pageCount }, () => {
|
}
|
||||||
this.fetchReplies()
|
|
||||||
})
|
onPaginationChange = (pageCount) => {
|
||||||
}
|
this.setState({ pageCount }, () => {
|
||||||
|
this.fetchReplies()
|
||||||
fetchReplies = () => {
|
})
|
||||||
const graduation_topic_id = this.props.memo.id
|
}
|
||||||
const course_id = this.props.course_id
|
|
||||||
const url = `/${this.props.apiRouteName}/${graduation_topic_id}/show_comment.json?page=${this.state.pageCount}`
|
fetchReplies = () => {
|
||||||
// page limit parent_id
|
const graduation_topic_id = this.props.memo.id
|
||||||
axios.get(url,{
|
const course_id = this.props.course_id
|
||||||
})
|
const url = `/${this.props.apiRouteName}/${graduation_topic_id}/show_comment.json?page=${this.state.pageCount}`
|
||||||
.then((response) => {
|
// page limit parent_id
|
||||||
const { comments, messages_count, homework_user_id, parent_messages_count } = response.data
|
axios.get(url,{
|
||||||
|
})
|
||||||
this.setState({
|
.then((response) => {
|
||||||
comments: generateComments(comments, this.transformReply),
|
const { comments, messages_count, homework_user_id, parent_messages_count } = response.data
|
||||||
// : this.state.comments.concat(comments),
|
|
||||||
total_count: parent_messages_count,
|
this.setState({
|
||||||
homework_user_id
|
comments: generateComments(comments, this.transformReply),
|
||||||
})
|
// : this.state.comments.concat(comments),
|
||||||
}).catch((error) => {
|
total_count: parent_messages_count,
|
||||||
console.log(error)
|
homework_user_id
|
||||||
})
|
})
|
||||||
}
|
}).catch((error) => {
|
||||||
|
console.log(error)
|
||||||
transformReply = (reply, children = []) => {
|
})
|
||||||
const isAdmin = this.props.isAdmin()
|
}
|
||||||
const isSuperAdmin = this.props.isSuperAdmin()
|
|
||||||
return {
|
transformReply = (reply, children = []) => {
|
||||||
admin: isAdmin, //
|
const isAdmin = this.props.isAdmin()
|
||||||
isSuperAdmin: isSuperAdmin,
|
const isSuperAdmin = this.props.isSuperAdmin()
|
||||||
permission: true, //
|
return {
|
||||||
children: children,
|
admin: isAdmin, //
|
||||||
hidden: reply.hidden,
|
isSuperAdmin: isSuperAdmin,
|
||||||
id: reply.id,
|
permission: true, //
|
||||||
image_url: reply.author.image_url,
|
children: children,
|
||||||
reward: null, //
|
hidden: reply.hidden,
|
||||||
time: reply.time, // moment(reply.created_on).fromNow(),
|
id: reply.id,
|
||||||
user_id: reply.author.id,
|
image_url: reply.author.image_url,
|
||||||
user_login: reply.author.login,
|
reward: null, //
|
||||||
user_praise: reply.user_praise,
|
time: reply.time, // moment(reply.created_on).fromNow(),
|
||||||
username: reply.author.name,
|
user_id: reply.author.id,
|
||||||
content: reply.content,
|
user_login: reply.author.login,
|
||||||
praise_count: reply.praise_count,
|
user_praise: reply.user_praise,
|
||||||
child_message_count: reply.child_message_count
|
username: reply.author.name,
|
||||||
}
|
content: reply.content,
|
||||||
}
|
praise_count: reply.praise_count,
|
||||||
|
child_message_count: reply.child_message_count
|
||||||
// 公共接口 --- 删除回复
|
}
|
||||||
deleteComment = (parrentComment, childCommentId) => {
|
}
|
||||||
handleDeleteComment(this, parrentComment, childCommentId, 'journals_for_message')
|
|
||||||
}
|
// 公共接口 --- 删除回复
|
||||||
// 公共接口 --- 回复点赞
|
deleteComment = (parrentComment, childCommentId) => {
|
||||||
commentPraise = (discussId) => {
|
handleDeleteComment(this, parrentComment, childCommentId, 'journals_for_message')
|
||||||
handleCommentPraise(this, discussId, 'journals_for_message')
|
}
|
||||||
}
|
// 公共接口 --- 回复点赞
|
||||||
// 公共接口 --- 隐藏回复
|
commentPraise = (discussId) => {
|
||||||
hiddenComment = (item, childCommentId) => {
|
handleCommentPraise(this, discussId, 'journals_for_message')
|
||||||
handleHiddenComment(this, item, childCommentId, 'journals_for_message')
|
}
|
||||||
}
|
// 公共接口 --- 隐藏回复
|
||||||
|
hiddenComment = (item, childCommentId) => {
|
||||||
showCommentInput = () => {
|
handleHiddenComment(this, item, childCommentId, 'journals_for_message')
|
||||||
this.refs.editor.showEditor();
|
}
|
||||||
}
|
|
||||||
initReply = (parent) => {
|
showCommentInput = () => {
|
||||||
if (!parent.isAllChildrenLoaded) {
|
this.refs.editor.showEditor();
|
||||||
this.loadMoreChildComments(parent)
|
}
|
||||||
}
|
initReply = (parent) => {
|
||||||
}
|
if (!parent.isAllChildrenLoaded) {
|
||||||
|
this.loadMoreChildComments(parent)
|
||||||
render(){
|
}
|
||||||
let { total_count, comments, pageCount } = this.state
|
}
|
||||||
const { current_user, memo } = this.props
|
|
||||||
|
render(){
|
||||||
return(
|
let { total_count, comments, pageCount } = this.state
|
||||||
<div style={{background: 'rgb(255, 255, 255)', marginTop: '20px'}} className="course-message">
|
const { current_user, memo } = this.props
|
||||||
<style>{`
|
|
||||||
.course-message .commentInput {
|
return(
|
||||||
padding-bottom: 56px !important;
|
<div style={{background: 'rgb(255, 255, 255)', marginTop: '20px'}} className="course-message">
|
||||||
}
|
<style>{`
|
||||||
.course-message .commentInput.mockInputWrapper {
|
.course-message .commentInput {
|
||||||
padding-bottom: 20px !important;
|
padding-bottom: 56px !important;
|
||||||
}
|
}
|
||||||
.course-message .memoReplies {
|
.course-message .commentInput.mockInputWrapper {
|
||||||
/* border-top: 1px solid #EDEDED; */
|
padding-bottom: 20px !important;
|
||||||
padding-bottom: 30px;
|
}
|
||||||
}
|
.course-message .memoReplies {
|
||||||
`}</style>
|
/* border-top: 1px solid #EDEDED; */
|
||||||
<MemoDetailMDEditor ref="editor" memo={memo} usingMockInput={true} placeholder="说点什么"
|
padding-bottom: 30px;
|
||||||
height={160} showError={true} imageExpand={true}
|
}
|
||||||
replyComment={this.replyComment}
|
`}</style>
|
||||||
commentsLength={comments ? comments.length : 0}
|
<MemoDetailMDEditor ref="editor" memo={memo} usingMockInput={true} placeholder="说点什么"
|
||||||
></MemoDetailMDEditor>
|
height={160} showError={true} imageExpand={true}
|
||||||
{/* bor-bottom-greyE */}
|
replyComment={this.replyComment}
|
||||||
<div className="padding40 memoReplies commentsDelegateParent"
|
commentsLength={comments ? comments.length : 0}
|
||||||
style={{ display: (comments && !!comments.length) ? 'block' : 'none' }}>
|
></MemoDetailMDEditor>
|
||||||
<div className="replies_count">
|
{/* bor-bottom-greyE */}
|
||||||
<span className="labal">全部回复</span>
|
<div className="padding40 memoReplies commentsDelegateParent"
|
||||||
<span className="count">{total_count}</span>
|
style={{ display: (comments && !!comments.length) ? 'block' : 'none' }}>
|
||||||
</div>
|
<div className="replies_count">
|
||||||
|
<span className="labal">全部回复</span>
|
||||||
<Comments comments={comments} user={current_user}
|
<span className="count">{total_count}</span>
|
||||||
replyComment={this.replyComment}
|
</div>
|
||||||
deleteComment={this.deleteComment}
|
|
||||||
commentPraise={this.commentPraise}
|
<Comments comments={comments} user={current_user}
|
||||||
rewardCode={this.rewardCode}
|
replyComment={this.replyComment}
|
||||||
hiddenComment={this.hiddenComment}
|
deleteComment={this.deleteComment}
|
||||||
|
commentPraise={this.commentPraise}
|
||||||
usingAntdModal={true}
|
rewardCode={this.rewardCode}
|
||||||
isChildCommentPagination={true}
|
hiddenComment={this.hiddenComment}
|
||||||
loadMoreChildComments={this.loadMoreChildComments}
|
|
||||||
initReply={this.initReply}
|
usingAntdModal={true}
|
||||||
showRewardButton={false}
|
isChildCommentPagination={true}
|
||||||
onlySuperAdminCouldHide={true}
|
loadMoreChildComments={this.loadMoreChildComments}
|
||||||
></Comments>
|
initReply={this.initReply}
|
||||||
|
showRewardButton={false}
|
||||||
|
onlySuperAdminCouldHide={true}
|
||||||
{/* { true ? :
|
></Comments>
|
||||||
<div className="memoMore">
|
|
||||||
<div className="writeCommentBtn" onClick={this.showCommentInput}>写评论</div>
|
|
||||||
</div>} */}
|
{/* { true ? :
|
||||||
</div>
|
<div className="memoMore">
|
||||||
|
<div className="writeCommentBtn" onClick={this.showCommentInput}>写评论</div>
|
||||||
{ total_count > REPLY_PAGE_COUNT &&
|
</div>} */}
|
||||||
<div className="memoMore">
|
</div>
|
||||||
<Pagination showQuickJumper onChange={this.onPaginationChange} current={pageCount} total={total_count} pageSize={10}/>
|
|
||||||
<div className="writeCommentBtn" onClick={this.showCommentInput}>写评论</div>
|
{ total_count > REPLY_PAGE_COUNT &&
|
||||||
</div> }
|
<div className="memoMore">
|
||||||
</div>
|
<Pagination showQuickJumper onChange={this.onPaginationChange} current={pageCount} total={total_count} pageSize={10}/>
|
||||||
)
|
<div className="writeCommentBtn" onClick={this.showCommentInput}>写评论</div>
|
||||||
}
|
</div> }
|
||||||
}
|
</div>
|
||||||
export default ImageLayerOfCommentHOC() (CommonReply);
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
export default ImageLayerOfCommentHOC() (CommonReply);
|
||||||
|
@ -1,271 +1,273 @@
|
|||||||
import React,{ Component } from "react";
|
import React,{ Component } from "react";
|
||||||
import { Pagination } from "antd";
|
import { Pagination } from "antd";
|
||||||
|
|
||||||
import update from 'immutability-helper'
|
import update from 'immutability-helper'
|
||||||
import axios from 'axios'
|
import axios from 'axios'
|
||||||
import MemoDetailMDEditor from '../../../forums/MemoDetailMDEditor'
|
import MemoDetailMDEditor from '../../../forums/MemoDetailMDEditor'
|
||||||
|
|
||||||
import '../../../forums/Post.css'
|
import '../../../forums/Post.css'
|
||||||
import '../../../forums/RightSection.css'
|
import '../../../forums/RightSection.css'
|
||||||
import {ImageLayerOfCommentHOC} from '../../../page/layers/ImageLayerOfCommentHOC'
|
import {ImageLayerOfCommentHOC} from '../../../page/layers/ImageLayerOfCommentHOC'
|
||||||
|
|
||||||
import Comments from '../../../comment/Comments'
|
import Comments from '../../../comment/Comments'
|
||||||
import './GraduateTopicReply.css'
|
import './GraduateTopicReply.css'
|
||||||
import '../../common/courseMessage.css'
|
import '../../common/courseMessage.css'
|
||||||
import { generateComments, generateChildComments, _findById, handleContentBeforeCreateNew, addNewComment
|
import { generateComments, generateChildComments, _findById, handleContentBeforeCreateNew, addNewComment
|
||||||
, addSecondLevelComment, NEED_TO_WRITE_CONTENT, handleContentBeforeCreateSecondLevelComment
|
, addSecondLevelComment, NEED_TO_WRITE_CONTENT, handleContentBeforeCreateSecondLevelComment
|
||||||
, handleDeleteComment, handleCommentPraise, handleHiddenComment } from '../../common/CommentsHelper'
|
, handleDeleteComment, handleCommentPraise, handleHiddenComment } from '../../common/CommentsHelper'
|
||||||
const REPLY_PAGE_COUNT = 10
|
const REPLY_PAGE_COUNT = 10
|
||||||
const $ = window.$;
|
const $ = window.$;
|
||||||
class GraduateTopicReply extends Component{
|
class GraduateTopicReply extends Component{
|
||||||
constructor(props){
|
constructor(props){
|
||||||
super(props);
|
super(props);
|
||||||
this.state={
|
this.state={
|
||||||
pageCount: 1
|
pageCount: 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount(){
|
componentDidMount(){
|
||||||
this.fetchReplies()
|
this.fetchReplies()
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
_getUser() {
|
_getUser() {
|
||||||
const { current_user } = this.props;
|
const { current_user } = this.props;
|
||||||
current_user.user_url = `/users/${current_user.login}`;
|
current_user.user_url = `/users/${current_user.login}`;
|
||||||
return current_user;
|
return current_user;
|
||||||
}
|
}
|
||||||
_findById = _findById
|
_findById = _findById
|
||||||
createNewComment = (commentContent, id, editor) => {
|
createNewComment = (commentContent, id, editor) => {
|
||||||
const graduation_topic_id = this.props.memo.id
|
const graduation_topic_id = this.props.memo.id
|
||||||
|
|
||||||
let content = handleContentBeforeCreateNew(commentContent);
|
let content = handleContentBeforeCreateNew(commentContent);
|
||||||
const { memo } = this.props;
|
const { memo } = this.props;
|
||||||
const url = `/users/reply_message.json`;
|
const url = `/users/reply_message.json`;
|
||||||
|
|
||||||
let { comments } = this.state;
|
let { comments } = this.state;
|
||||||
axios.post(url, {
|
axios.post(url, {
|
||||||
journals_for_message: {
|
journals_for_message: {
|
||||||
jour_type: 'GraduationTopic',
|
jour_type: 'GraduationTopic',
|
||||||
jour_id: graduation_topic_id,
|
jour_id: graduation_topic_id,
|
||||||
notes: content,
|
notes: content,
|
||||||
// m_parent_id
|
// m_parent_id
|
||||||
reply_id: memo.user_id
|
reply_id: memo.user_id
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
).then((response) => {
|
).then((response) => {
|
||||||
if (response.data.status === -1) {
|
if (response.data.status === -1) {
|
||||||
console.error('服务端异常')
|
console.error('服务端异常')
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// this.props.showNotification('帖子发表成功')
|
// this.props.showNotification('帖子发表成功')
|
||||||
|
|
||||||
if (response.data && response.data.id) {
|
if (response.data && response.data.id) {
|
||||||
const _id = response.data.id;
|
const _id = response.data.id;
|
||||||
// md
|
let mycontent= response.data.content;
|
||||||
editor.setValue && editor.setValue('')
|
// md
|
||||||
|
editor.setValue && editor.setValue('')
|
||||||
const user = this._getUser();
|
|
||||||
this.setState({
|
const user = this._getUser();
|
||||||
comments: addNewComment(this.state.comments, _id, content, user, this.props.isSuperAdmin(), this),
|
this.setState({
|
||||||
total_count: this.state.total_count + 1
|
comments: addNewComment(this.state.comments, _id, mycontent, user, this.props.isSuperAdmin(), this),
|
||||||
})
|
total_count: this.state.total_count + 1
|
||||||
this.refs.editor.showEditor();
|
})
|
||||||
|
this.refs.editor.showEditor();
|
||||||
}
|
|
||||||
}).catch((error) => {
|
}
|
||||||
console.log(error)
|
}).catch((error) => {
|
||||||
})
|
console.log(error)
|
||||||
}
|
})
|
||||||
replyComment = (commentContent, id, editor) => {
|
}
|
||||||
const { showNotification } = this.props;
|
replyComment = (commentContent, id, editor) => {
|
||||||
// if (!commentContent || commentContent.length === 0) {
|
const { showNotification } = this.props;
|
||||||
// showNotification(NEED_TO_WRITE_CONTENT)
|
// if (!commentContent || commentContent.length === 0) {
|
||||||
// return;
|
// showNotification(NEED_TO_WRITE_CONTENT)
|
||||||
// }
|
// return;
|
||||||
|
// }
|
||||||
if (this.props.memo.id === id ) { // 回复帖子
|
|
||||||
this.createNewComment(commentContent, id, editor);
|
if (this.props.memo.id === id ) { // 回复帖子
|
||||||
return;
|
this.createNewComment(commentContent, id, editor);
|
||||||
}
|
return;
|
||||||
const url = `/users/reply_message.json`;
|
}
|
||||||
|
const url = `/users/reply_message.json`;
|
||||||
const { comments } = this.state;
|
|
||||||
const user = this._getUser();
|
const { comments } = this.state;
|
||||||
const graduation_topic_id = this.props.memo.id
|
const user = this._getUser();
|
||||||
const commentIndex = this._findById(id, comments);
|
const graduation_topic_id = this.props.memo.id
|
||||||
let comment = comments[commentIndex];
|
const commentIndex = this._findById(id, comments);
|
||||||
|
let comment = comments[commentIndex];
|
||||||
commentContent = handleContentBeforeCreateSecondLevelComment(commentContent)
|
|
||||||
axios.post(url, {
|
commentContent = handleContentBeforeCreateSecondLevelComment(commentContent)
|
||||||
journals_for_message: {
|
axios.post(url, {
|
||||||
jour_type: 'GraduationTopic',
|
journals_for_message: {
|
||||||
jour_id: graduation_topic_id,
|
jour_type: 'GraduationTopic',
|
||||||
notes: commentContent,
|
jour_id: graduation_topic_id,
|
||||||
m_parent_id: id,
|
notes: commentContent,
|
||||||
reply_id: comment.user_id
|
m_parent_id: id,
|
||||||
}
|
reply_id: comment.user_id
|
||||||
},
|
}
|
||||||
{
|
},
|
||||||
}
|
{
|
||||||
).then((response) => {
|
}
|
||||||
if (response.data.id) {
|
).then((response) => {
|
||||||
let newId = response.data.id;
|
if (response.data.id) {
|
||||||
|
let newId = response.data.id;
|
||||||
this.setState({
|
let mycontent= response.data.content;
|
||||||
comments: addSecondLevelComment(comments, comment, commentIndex, newId, commentContent, user, editor)
|
|
||||||
})
|
this.setState({
|
||||||
|
comments: addSecondLevelComment(comments, comment, commentIndex, newId, mycontent, user, editor)
|
||||||
const newMemo2 = Object.assign({}, this.props.memo);
|
})
|
||||||
newMemo2.total_count = newMemo2.total_count + 1;
|
|
||||||
this.setState({
|
const newMemo2 = Object.assign({}, this.props.memo);
|
||||||
memo: newMemo2
|
newMemo2.total_count = newMemo2.total_count + 1;
|
||||||
})
|
this.setState({
|
||||||
}
|
memo: newMemo2
|
||||||
|
})
|
||||||
}).catch((error) => {
|
}
|
||||||
console.log(error)
|
|
||||||
})
|
}).catch((error) => {
|
||||||
}
|
console.log(error)
|
||||||
|
})
|
||||||
loadMoreChildComments = (parent) => {
|
}
|
||||||
const graduation_topic_id = this.props.memo.id
|
|
||||||
const course_id = this.props.course_id
|
loadMoreChildComments = (parent) => {
|
||||||
const url = `/courses/${course_id}/graduation_topics/${graduation_topic_id}/show_comment.json?parent_id=${parent.id}&limit=500`
|
const graduation_topic_id = this.props.memo.id
|
||||||
axios.get(url,{
|
const course_id = this.props.course_id
|
||||||
})
|
const url = `/courses/${course_id}/graduation_topics/${graduation_topic_id}/show_comment.json?parent_id=${parent.id}&limit=500`
|
||||||
.then((response) => {
|
axios.get(url,{
|
||||||
const { comments } = response.data
|
})
|
||||||
|
.then((response) => {
|
||||||
|
const { comments } = response.data
|
||||||
// const memo = Object.assign({}, this.state.memo)
|
|
||||||
// memo.sum_replies_count = sum_replies_count;
|
|
||||||
this.setState({
|
// const memo = Object.assign({}, this.state.memo)
|
||||||
// memo,
|
// memo.sum_replies_count = sum_replies_count;
|
||||||
comments: generateChildComments(comments, this.state.comments, parent, this.transformReply)
|
this.setState({
|
||||||
})
|
// memo,
|
||||||
}).catch((error) => {
|
comments: generateChildComments(comments, this.state.comments, parent, this.transformReply)
|
||||||
console.log(error)
|
})
|
||||||
})
|
}).catch((error) => {
|
||||||
}
|
console.log(error)
|
||||||
|
})
|
||||||
onPaginationChange = (pageCount) => {
|
}
|
||||||
this.setState({ pageCount }, () => {
|
|
||||||
this.fetchReplies()
|
onPaginationChange = (pageCount) => {
|
||||||
})
|
this.setState({ pageCount }, () => {
|
||||||
}
|
this.fetchReplies()
|
||||||
|
})
|
||||||
fetchReplies = () => {
|
}
|
||||||
const graduation_topic_id = this.props.memo.id
|
|
||||||
const course_id = this.props.course_id
|
fetchReplies = () => {
|
||||||
const url = `/courses/${course_id}/graduation_topics/${graduation_topic_id}/show_comment.json?page=${this.state.pageCount}`
|
const graduation_topic_id = this.props.memo.id
|
||||||
// page limit parent_id
|
const course_id = this.props.course_id
|
||||||
axios.get(url,{
|
const url = `/courses/${course_id}/graduation_topics/${graduation_topic_id}/show_comment.json?page=${this.state.pageCount}`
|
||||||
})
|
// page limit parent_id
|
||||||
.then((response) => {
|
axios.get(url,{
|
||||||
const { comments, messages_count } = response.data
|
})
|
||||||
|
.then((response) => {
|
||||||
this.setState({
|
const { comments, messages_count } = response.data
|
||||||
comments: generateComments(comments, this.transformReply),
|
|
||||||
// : this.state.comments.concat(comments),
|
this.setState({
|
||||||
total_count: messages_count
|
comments: generateComments(comments, this.transformReply),
|
||||||
})
|
// : this.state.comments.concat(comments),
|
||||||
}).catch((error) => {
|
total_count: messages_count
|
||||||
console.log(error)
|
})
|
||||||
})
|
}).catch((error) => {
|
||||||
}
|
console.log(error)
|
||||||
|
})
|
||||||
transformReply = (reply, children = []) => {
|
}
|
||||||
const isAdmin = this.props.isAdmin()
|
|
||||||
const isSuperAdmin = this.props.isSuperAdmin()
|
transformReply = (reply, children = []) => {
|
||||||
return {
|
const isAdmin = this.props.isAdmin()
|
||||||
isSuperAdmin: isSuperAdmin,
|
const isSuperAdmin = this.props.isSuperAdmin()
|
||||||
admin: isAdmin, //
|
return {
|
||||||
permission: true, //
|
isSuperAdmin: isSuperAdmin,
|
||||||
children: children,
|
admin: isAdmin, //
|
||||||
child_message_count: reply.child_message_count,
|
permission: true, //
|
||||||
hidden: reply.hidden,
|
children: children,
|
||||||
id: reply.id,
|
child_message_count: reply.child_message_count,
|
||||||
image_url: reply.author.image_url,
|
hidden: reply.hidden,
|
||||||
reward: null, //
|
id: reply.id,
|
||||||
time: reply.time, // moment(reply.created_on).fromNow(),
|
image_url: reply.author.image_url,
|
||||||
user_id: reply.author.id,
|
reward: null, //
|
||||||
user_login: reply.author.login,
|
time: reply.time, // moment(reply.created_on).fromNow(),
|
||||||
user_praise: reply.user_praise,
|
user_id: reply.author.id,
|
||||||
username: reply.author.name,
|
user_login: reply.author.login,
|
||||||
content: reply.content,
|
user_praise: reply.user_praise,
|
||||||
praise_count: reply.praise_count
|
username: reply.author.name,
|
||||||
}
|
content: reply.content,
|
||||||
}
|
praise_count: reply.praise_count
|
||||||
|
}
|
||||||
// 公共接口 --- 删除回复
|
}
|
||||||
deleteComment = (parrentComment, childCommentId) => {
|
|
||||||
handleDeleteComment(this, parrentComment, childCommentId, 'journals_for_message')
|
// 公共接口 --- 删除回复
|
||||||
}
|
deleteComment = (parrentComment, childCommentId) => {
|
||||||
// 公共接口 --- 回复点赞
|
handleDeleteComment(this, parrentComment, childCommentId, 'journals_for_message')
|
||||||
commentPraise = (discussId) => {
|
}
|
||||||
handleCommentPraise(this, discussId, 'journals_for_message')
|
// 公共接口 --- 回复点赞
|
||||||
}
|
commentPraise = (discussId) => {
|
||||||
// 公共接口 --- 隐藏回复
|
handleCommentPraise(this, discussId, 'journals_for_message')
|
||||||
hiddenComment = (item, childCommentId) => {
|
}
|
||||||
handleHiddenComment(this, item, childCommentId, 'journals_for_message')
|
// 公共接口 --- 隐藏回复
|
||||||
}
|
hiddenComment = (item, childCommentId) => {
|
||||||
|
handleHiddenComment(this, item, childCommentId, 'journals_for_message')
|
||||||
showCommentInput = () => {
|
}
|
||||||
this.refs.editor.showEditor();
|
|
||||||
}
|
showCommentInput = () => {
|
||||||
initReply = (parent) => {
|
this.refs.editor.showEditor();
|
||||||
if (!parent.isAllChildrenLoaded) {
|
}
|
||||||
this.loadMoreChildComments(parent)
|
initReply = (parent) => {
|
||||||
}
|
if (!parent.isAllChildrenLoaded) {
|
||||||
}
|
this.loadMoreChildComments(parent)
|
||||||
|
}
|
||||||
render(){
|
}
|
||||||
let { total_count, comments, pageCount } = this.state
|
|
||||||
const { current_user, memo } = this.props
|
render(){
|
||||||
|
let { total_count, comments, pageCount } = this.state
|
||||||
return(
|
const { current_user, memo } = this.props
|
||||||
<React.Fragment>
|
|
||||||
<MemoDetailMDEditor ref="editor" memo={memo} usingMockInput={true} placeholder="说点什么"
|
return(
|
||||||
height={160} showError={true}></MemoDetailMDEditor>
|
<React.Fragment>
|
||||||
|
<MemoDetailMDEditor ref="editor" memo={memo} usingMockInput={true} placeholder="说点什么"
|
||||||
<div className="padding40 bor-bottom-greyE memoReplies commentsDelegateParent"
|
height={160} showError={true}></MemoDetailMDEditor>
|
||||||
style={{ display: (comments && !!comments.length) ? 'block' : 'none' }}>
|
|
||||||
<div className="replies_count">
|
<div className="padding40 bor-bottom-greyE memoReplies commentsDelegateParent"
|
||||||
<span className="labal">全部回复</span>
|
style={{ display: (comments && !!comments.length) ? 'block' : 'none' }}>
|
||||||
<span className="count">{total_count}</span>
|
<div className="replies_count">
|
||||||
</div>
|
<span className="labal">全部回复</span>
|
||||||
|
<span className="count">{total_count}</span>
|
||||||
<Comments comments={comments} user={current_user}
|
</div>
|
||||||
replyComment={this.replyComment}
|
|
||||||
deleteComment={this.deleteComment}
|
<Comments comments={comments} user={current_user}
|
||||||
commentPraise={this.commentPraise}
|
replyComment={this.replyComment}
|
||||||
rewardCode={this.rewardCode}
|
deleteComment={this.deleteComment}
|
||||||
hiddenComment={this.hiddenComment}
|
commentPraise={this.commentPraise}
|
||||||
|
rewardCode={this.rewardCode}
|
||||||
usingAntdModal={true}
|
hiddenComment={this.hiddenComment}
|
||||||
isChildCommentPagination={true}
|
|
||||||
loadMoreChildComments={this.loadMoreChildComments}
|
usingAntdModal={true}
|
||||||
initReply={this.initReply}
|
isChildCommentPagination={true}
|
||||||
showRewardButton={false}
|
loadMoreChildComments={this.loadMoreChildComments}
|
||||||
|
initReply={this.initReply}
|
||||||
onlySuperAdminCouldHide={true}
|
showRewardButton={false}
|
||||||
></Comments>
|
|
||||||
|
onlySuperAdminCouldHide={true}
|
||||||
|
></Comments>
|
||||||
{/* { true ? :
|
|
||||||
<div className="memoMore">
|
|
||||||
<div className="writeCommentBtn" onClick={this.showCommentInput}>写评论</div>
|
{/* { true ? :
|
||||||
</div>} */}
|
<div className="memoMore">
|
||||||
</div>
|
<div className="writeCommentBtn" onClick={this.showCommentInput}>写评论</div>
|
||||||
|
</div>} */}
|
||||||
{ total_count > REPLY_PAGE_COUNT &&
|
</div>
|
||||||
<div className="memoMore">
|
|
||||||
<Pagination showQuickJumper onChange={this.onPaginationChange} current={pageCount} total={total_count} pageSize={10}/>
|
{ total_count > REPLY_PAGE_COUNT &&
|
||||||
<div className="writeCommentBtn" onClick={this.showCommentInput}>写评论</div>
|
<div className="memoMore">
|
||||||
</div> }
|
<Pagination showQuickJumper onChange={this.onPaginationChange} current={pageCount} total={total_count} pageSize={10}/>
|
||||||
</React.Fragment>
|
<div className="writeCommentBtn" onClick={this.showCommentInput}>写评论</div>
|
||||||
)
|
</div> }
|
||||||
}
|
</React.Fragment>
|
||||||
}
|
)
|
||||||
export default ImageLayerOfCommentHOC() (GraduateTopicReply);
|
}
|
||||||
|
}
|
||||||
|
export default ImageLayerOfCommentHOC() (GraduateTopicReply);
|
||||||
|
Loading…
Reference in new issue