detail接口

dev_hjm^2
hjm 6 years ago
parent 7b556ee4bf
commit 85861a3396

@ -349,8 +349,12 @@ class App extends Component {
{/*课堂*/} {/*课堂*/}
<Route path="/courses" component={CoursesIndex} {...this.props}></Route> <Route path="/courses" component={CoursesIndex} {...this.props}></Route>
{/* <Route path="/forums" component={ForumsIndexComponent}> <Route path="/forums"
</Route> */} render={
(props)=>(<ForumsIndexComponent {...this.props} {...props} {...this.state}></ForumsIndexComponent>)
}
>
</Route>
<Route path="/comment" component={CommentComponent}/> <Route path="/comment" component={CommentComponent}/>
<Route path="/testMaterial" component={TestMaterialDesignComponent}/> <Route path="/testMaterial" component={TestMaterialDesignComponent}/>

@ -90,6 +90,8 @@ class MemoDetail extends Component {
comments: memo_replies comments: memo_replies
}) })
delete response.data.memo_replies; delete response.data.memo_replies;
// reset
response.data.memo.praise_count = response.data.memo.memo_praise_count
this.props.initForumState(response.data) this.props.initForumState(response.data)
// const user = response.data.current_user; // const user = response.data.current_user;
// user.tidding_count = response.data.tidding_count; // user.tidding_count = response.data.tidding_count;
@ -116,7 +118,7 @@ class MemoDetail extends Component {
$('body>#root').off('onMemoDelete') $('body>#root').off('onMemoDelete')
} }
onMemoDelete(memo) { onMemoDelete(memo) {
const deleteUrl = `/api/v1/memos/${memo.id}`; const deleteUrl = `/memos/${memo.id}.json`;
// 获取memo list // 获取memo list
axios.delete(deleteUrl, { axios.delete(deleteUrl, {
// withCredentials: true, // withCredentials: true,
@ -158,14 +160,14 @@ class MemoDetail extends Component {
clickPraise(){ clickPraise(){
const { memo } = this.props; const { memo } = this.props;
const url = `/api/v1/discusses/${memo.id}/plus`; const url = `/discusses/${memo.id}/plus.json`;
console.log(url) console.log(url)
axios.post(url, { axios.post(url, {
container_type: 'Memo', container_type: 'Memo',
type: 1 // "踩0赞1" type: 1 // "踩0赞1"
}, },
{ {
withCredentials: true // withCredentials: true
} }
).then((response) => { ).then((response) => {
console.log(response); console.log(response);
@ -223,7 +225,8 @@ class MemoDetail extends Component {
this.createNewComment(commentContent, id, editor); this.createNewComment(commentContent, id, editor);
return; return;
} }
const url = `/memos/${id}/reply.json`; // /${id}
const url = `/memos/reply.json`;
const { comments } = this.state; const { comments } = this.state;
const user = this._getUser(); const user = this._getUser();
/* /*
@ -235,12 +238,14 @@ class MemoDetail extends Component {
commentContent = commentContent.replace(/(\n<p>\n\t<br \/>\n<\/p>)*$/g,''); commentContent = commentContent.replace(/(\n<p>\n\t<br \/>\n<\/p>)*$/g,'');
} }
axios.post(url, { axios.post(url, {
parent_id: id,
content: commentContent content: commentContent
}, },
{ {
withCredentials: true // withCredentials: true
} }
).then((response) => { ).then((response) => {
response.data.memo = response.data
if (response.data.memo) { if (response.data.memo) {
let newDiscuss = response.data.memo; let newDiscuss = response.data.memo;
@ -303,12 +308,12 @@ class MemoDetail extends Component {
if (childCommentId) { if (childCommentId) {
deleteCommentId = childCommentId; deleteCommentId = childCommentId;
} }
const url = `/api/v1/memos/${deleteCommentId}` const url = `/memos/${deleteCommentId}.json`
let comments = this.state.comments; let comments = this.state.comments;
axios.delete(url, axios.delete(url,
{ {
withCredentials: true // withCredentials: true
} }
).then((response) => { ).then((response) => {
// TODO 删除成功或失败 // TODO 删除成功或失败
@ -346,7 +351,7 @@ class MemoDetail extends Component {
const { comments } = this.state; const { comments } = this.state;
const commentIndex = this._findById(discussId, comments); const commentIndex = this._findById(discussId, comments);
const url = `/api/v1/discusses/${discussId}/plus` const url = `/discusses/${discussId}/plus.json`
axios.post(url, { axios.post(url, {
// id: discussId, // id: discussId,
// container_id: challenge.id, // container_id: challenge.id,
@ -354,7 +359,7 @@ class MemoDetail extends Component {
type: comments[commentIndex].user_praise === true ? 0 : 1, // "踩0赞1" type: comments[commentIndex].user_praise === true ? 0 : 1, // "踩0赞1"
}, },
{ {
withCredentials: true // withCredentials: true
} }
).then((response) => { ).then((response) => {
if (response.data.praise_count === 0 || response.data.praise_count) { if (response.data.praise_count === 0 || response.data.praise_count) {
@ -379,7 +384,7 @@ class MemoDetail extends Component {
handleComment = childComment; handleComment = childComment;
} }
let handleCommentId = handleComment.id; let handleCommentId = handleComment.id;
const url = `/api/v1/discusses/${handleCommentId}/reward_code` const url = `/discusses/${handleCommentId}/reward_code.json`
axios.post(url, { axios.post(url, {
id: handleCommentId, id: handleCommentId,
@ -389,7 +394,7 @@ class MemoDetail extends Component {
user_id: handleComment.user_id user_id: handleComment.user_id
}, },
{ {
withCredentials: true // withCredentials: true
} }
).then((response) => { ).then((response) => {
if (response.data && response.data.code) { if (response.data && response.data.code) {
@ -423,7 +428,7 @@ class MemoDetail extends Component {
const id = item.id const id = item.id
const { showSnackbar } = this.props; const { showSnackbar } = this.props;
const user = this._getUser(); const user = this._getUser();
const url = `/api/v1/memos/${id}/hidden` const url = `/memos/${id}/hidden.json`
const { comments } = this.state; const { comments } = this.state;
const commentIndex = this._findById(id, comments); const commentIndex = this._findById(id, comments);
@ -432,7 +437,7 @@ class MemoDetail extends Component {
hidden: !comment.hidden ? "1" : "0" hidden: !comment.hidden ? "1" : "0"
}, },
{ {
withCredentials: true // withCredentials: true
} }
).then((response) => { ).then((response) => {
if (response.data.status === -1) { if (response.data.status === -1) {
@ -473,10 +478,12 @@ class MemoDetail extends Component {
return; return;
} }
} }
const url = `/memos/${memo.id}/reply.json`; // /${memo.id}
const url = `/memos/reply.json`;
let { comments } = this.state; let { comments } = this.state;
const user = this._getUser(); const user = this._getUser();
axios.post(url, { axios.post(url, {
parent_id: memo.id,
content: content content: content
}, },
{ {
@ -488,6 +495,7 @@ class MemoDetail extends Component {
return; return;
} }
if (response.data) { if (response.data) {
response.data.memo = response.data
const newMemo = response.data.memo; const newMemo = response.data.memo;
// ke // ke
editor.html && editor.html(''); editor.html && editor.html('');
@ -536,12 +544,12 @@ class MemoDetail extends Component {
let { comments, pageCount } = this.state; let { comments, pageCount } = this.state;
let { memo } = this.props; let { memo } = this.props;
const user = this._getUser(); const user = this._getUser();
const url = `/api/v1/memos/${memo.id}/more_reply?page=${pageCount}`; const url = `/memos/${memo.id}/more_reply.json?page=${pageCount}`;
axios.get(url, { axios.get(url, {
}, },
{ {
withCredentials: true // withCredentials: true
} }
).then((response) => { ).then((response) => {
if (response.data.status === -1) { if (response.data.status === -1) {
@ -608,9 +616,8 @@ class MemoDetail extends Component {
const { memo, author_info } = this.props; const { memo, author_info } = this.props;
const newMemo = Object.assign({}, memo); const newMemo = Object.assign({}, memo);
const _reward = parseInt(inputVal) const _reward = parseInt(inputVal)
const newMemoUrl = `/api/v1/memos/${memo.id}/update`
const url = `/api/v1/discusses/${memo.id}/reward_code` const url = `/discusses/${memo.id}/reward_code.json`
axios.post(url, { axios.post(url, {
id: memo.id, id: memo.id,

@ -42,7 +42,7 @@ class MemoDetailMDEditor extends Component {
window.__tt = 400; window.__tt = 400;
setTimeout(() => { setTimeout(() => {
var commentMDEditor = window.create_editorMD_4comment("memo_comment_editorMd", '', this.props.height || 240, placeholder, imageUrl, () => { var commentMDEditor = window.create_editorMD_4comment("memo_comment_editorMd", '', this.props.height || 240, placeholder, imageUrl, () => {
commentMDEditor.focus() // commentMDEditor.focus()
this.isMDInited = true this.isMDInited = true
this.initDrag() this.initDrag()

@ -15,6 +15,7 @@ import Upload from 'rc-upload';
import axios from 'axios' import axios from 'axios'
import 'antd/lib/select/style/index.css' import 'antd/lib/select/style/index.css'
import TPMMDEditor from '../tpm/challengesnew/TPMMDEditor'
import { getUrl } from 'educoder' import { getUrl } from 'educoder'
const Option = Select.Option; const Option = Select.Option;
@ -130,6 +131,7 @@ const languageSeparator = '/'
class MemoNew extends Component { class MemoNew extends Component {
constructor(props) { constructor(props) {
super(props) super(props)
this.mdRef = React.createRef();
// https://testbdweb.trustie.net/uploads.js?attachment_id=1&filename=jqui.js // https://testbdweb.trustie.net/uploads.js?attachment_id=1&filename=jqui.js
// https://ant.design/components/upload-cn/ // https://ant.design/components/upload-cn/
@ -179,7 +181,7 @@ class MemoNew extends Component {
} }
let mdVal; let mdVal;
try { try {
mdVal = this.taskpass_editormd.getValue() mdVal = this.mdRef.current.getValue()
} catch (e) { } catch (e) {
showSnackbar('编辑器还未加载完毕,请稍后') showSnackbar('编辑器还未加载完毕,请稍后')
@ -205,6 +207,7 @@ class MemoNew extends Component {
// collect attachments // collect attachments
const $ = window.$; const $ = window.$;
const attachmentsMap = {}; const attachmentsMap = {};
const attachmentIds = []
$('#attachments_fields .attachment').each(( index, item ) => { $('#attachments_fields .attachment').each(( index, item ) => {
const filename = $(item).find('.upload_filename').val(); const filename = $(item).find('.upload_filename').val();
// $($('#attachments_fields .attachment')[0]).find('input:nth-child(6)').val() // $($('#attachments_fields .attachment')[0]).find('input:nth-child(6)').val()
@ -215,13 +218,14 @@ class MemoNew extends Component {
token, token,
attachment_id attachment_id
} }
attachmentIds.push(attachment_id)
}) })
if (currentMemoId) { if (currentMemoId) {
this.updateMemo(attachmentsMap) this.updateMemo(attachmentIds)
} else { } else {
this.newMemo(attachmentsMap) this.newMemo(attachmentIds)
} }
} }
onCancel() { onCancel() {
@ -235,20 +239,20 @@ class MemoNew extends Component {
} }
updateMemo(attachmentsMap) { updateMemo(attachmentsMap) {
const { memoSubject, memoRepertoire, memoLanguage, memoType, currentMemoId, content } = this.state; const { memoSubject, memoRepertoire, memoLanguage, memoType, currentMemoId, content } = this.state;
const mdVal = this.taskpass_editormd.getValue() const mdVal = this.mdRef.current.getValue()
console.log('isContentEdit: ', mdVal === content); console.log('isContentEdit: ', mdVal === content);
const newMemoUrl = `/api/v1/memos/${currentMemoId}/update` const newMemoUrl = `/memos/${currentMemoId}.json`
axios.post(newMemoUrl, { axios.put(newMemoUrl, {
content_changed: this.contentChanged, content_changed: this.contentChanged,
tags: memoLanguage, tags: memoLanguage,
memo:{ // memo:{
subject: memoSubject , subject: memoSubject ,
content: mdVal, content: mdVal,
forum_id: memoType, forum_id: memoType,
repertoire_name: memoRepertoire, repertoire_name: memoRepertoire,
// language: memoLanguage.join(languageSeparator), // language: memoLanguage.join(languageSeparator),
// //
}, // },
attachments: attachmentsMap attachments: attachmentsMap
}, { }, {
// withCredentials: true, // withCredentials: true,
@ -267,18 +271,18 @@ class MemoNew extends Component {
} }
newMemo(attachmentsMap) { newMemo(attachmentsMap) {
const { memoSubject, memoRepertoire, memoLanguage, memoType } = this.state; const { memoSubject, memoRepertoire, memoLanguage, memoType } = this.state;
const mdVal = this.taskpass_editormd.getValue() const mdVal = this.mdRef.current.getValue()
const newMemoUrl = `/api/v1/memos/create` const newMemoUrl = `/memos.json`
axios.post(newMemoUrl, { axios.post(newMemoUrl, {
tags: memoLanguage, tags: memoLanguage,
memo:{ // memo:{
subject: memoSubject , subject: memoSubject ,
content: mdVal, content: mdVal,
forum_id: memoType, forum_id: memoType,
repertoire_name: memoRepertoire, // repertoire_name: memoRepertoire,
}, // },
attachments: attachmentsMap attachments: attachmentsMap
}, { }, {
// withCredentials: true, // withCredentials: true,
@ -296,7 +300,7 @@ class MemoNew extends Component {
}) })
} }
componentDidMount() { componentDidMount() {
const newMemoUrl = `/api/v1/memos/new` const newMemoUrl = `/memos/new.json`
axios.get(newMemoUrl,{ axios.get(newMemoUrl,{
// withCredentials: true, // withCredentials: true,
}) })
@ -336,7 +340,7 @@ class MemoNew extends Component {
const { match } = this.props const { match } = this.props
const memoId = match.params.memoId; const memoId = match.params.memoId;
if (memoId) { if (memoId) {
const memoUrl = `/api/v1/memos/${match.params.memoId}/edit`; const memoUrl = `/memos/${match.params.memoId}/edit.json`;
axios.get(memoUrl,{ axios.get(memoUrl,{
// withCredentials: true, // withCredentials: true,
}) })
@ -344,10 +348,12 @@ class MemoNew extends Component {
const tag_list = response.data.tag_list const tag_list = response.data.tag_list
if (tag_list) { if (tag_list) {
// this.setState({...response.data}) // this.setState({...response.data})
const { content, forum_id, id, tag, repertoire_name, subject, const { content, forum_id, id, repertoire_name, subject,
current_user, tag_list, attachments_url } = response.data; current_user, tag_list, attachments_url, memo_tags } = response.data;
this.initMD(content); this.initMD(content);
// this.onRepertoiresChange(repertoire_name) // this.onRepertoiresChange(repertoire_name)
// tag -> memo_tags
const tag = memo_tags;
let memoLanguage = [] let memoLanguage = []
if (tag) { if (tag) {
memoLanguage = tag.map((item, index) => { memoLanguage = tag.map((item, index) => {
@ -355,7 +361,7 @@ class MemoNew extends Component {
}) })
} }
this.setState({ this.setState({
currentMemoId: id, currentMemoId: memoId,
memoSubject: subject, memoSubject: subject,
memoType: forum_id, memoType: forum_id,
memoRepertoire: repertoire_name, memoRepertoire: repertoire_name,
@ -377,7 +383,7 @@ class MemoNew extends Component {
window.$("html,body").animate({"scrollTop":0}) window.$("html,body").animate({"scrollTop":0})
this.props.initForumState({ this.props.initForumState({
current_user, // current_user,
tag_list tag_list
}) })
} }
@ -394,6 +400,8 @@ class MemoNew extends Component {
} }
initMD(initValue) { initMD(initValue) {
return;
this.contentChanged = false; this.contentChanged = false;
const placeholder = ""; const placeholder = "";
// amp; // amp;
@ -566,9 +574,12 @@ class MemoNew extends Component {
<div className="df"> <div className="df">
<span className="mr30 color-orange pt10">*</span> <span className="mr30 color-orange pt10">*</span>
<div className="flex1 mr20"> <div className="flex1 mr20">
<div className="flex1 break_word show_content_grey new_li" id="memoMD"> <TPMMDEditor ref={this.mdRef} placeholder={''} watch={false}
mdID={'memoMD'} initValue={this.state.content} className="memoMD">
</TPMMDEditor>
{/* <div className="flex1 break_word show_content_grey new_li" id="memoMD">
<textarea style={{'display':'none'}}></textarea> <textarea style={{'display':'none'}}></textarea>
</div> </div> */}
<p id="e_tip_memoNew" className="edu-txt-right color-grey-cd font-12"></p> <p id="e_tip_memoNew" className="edu-txt-right color-grey-cd font-12"></p>
<p id="e_tips_memoNew" className="edu-txt-right color-grey-cd font-12"></p> <p id="e_tips_memoNew" className="edu-txt-right color-grey-cd font-12"></p>
</div> </div>

Loading…
Cancel
Save