From 85861a339681da0d2d66cd0c9b8e40d43a751a8a Mon Sep 17 00:00:00 2001 From: hjm <63528605@qq.com> Date: Thu, 1 Aug 2019 16:16:03 +0800 Subject: [PATCH] =?UTF-8?q?detail=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/react/src/App.js | 8 ++- public/react/src/modules/forums/MemoDetail.js | 43 ++++++++------- .../src/modules/forums/MemoDetailMDEditor.js | 2 +- public/react/src/modules/forums/MemoNew.js | 53 +++++++++++-------- 4 files changed, 64 insertions(+), 42 deletions(-) diff --git a/public/react/src/App.js b/public/react/src/App.js index 895016ff7..6e7ba3330 100644 --- a/public/react/src/App.js +++ b/public/react/src/App.js @@ -349,8 +349,12 @@ class App extends Component { {/*课堂*/} - {/* - */} + () + } + > + diff --git a/public/react/src/modules/forums/MemoDetail.js b/public/react/src/modules/forums/MemoDetail.js index d340a5014..f950037f4 100644 --- a/public/react/src/modules/forums/MemoDetail.js +++ b/public/react/src/modules/forums/MemoDetail.js @@ -90,6 +90,8 @@ class MemoDetail extends Component { comments: memo_replies }) delete response.data.memo_replies; + // reset + response.data.memo.praise_count = response.data.memo.memo_praise_count this.props.initForumState(response.data) // const user = response.data.current_user; // user.tidding_count = response.data.tidding_count; @@ -116,7 +118,7 @@ class MemoDetail extends Component { $('body>#root').off('onMemoDelete') } onMemoDelete(memo) { - const deleteUrl = `/api/v1/memos/${memo.id}`; + const deleteUrl = `/memos/${memo.id}.json`; // 获取memo list axios.delete(deleteUrl, { // withCredentials: true, @@ -158,14 +160,14 @@ class MemoDetail extends Component { clickPraise(){ const { memo } = this.props; - const url = `/api/v1/discusses/${memo.id}/plus`; + const url = `/discusses/${memo.id}/plus.json`; console.log(url) axios.post(url, { container_type: 'Memo', type: 1 // "踩0;赞1" }, { - withCredentials: true + // withCredentials: true } ).then((response) => { console.log(response); @@ -223,7 +225,8 @@ class MemoDetail extends Component { this.createNewComment(commentContent, id, editor); return; } - const url = `/memos/${id}/reply.json`; + // /${id} + const url = `/memos/reply.json`; const { comments } = this.state; const user = this._getUser(); /* @@ -235,12 +238,14 @@ class MemoDetail extends Component { commentContent = commentContent.replace(/(\n

\n\t
\n<\/p>)*$/g,''); } axios.post(url, { + parent_id: id, content: commentContent }, { - withCredentials: true + // withCredentials: true } ).then((response) => { + response.data.memo = response.data if (response.data.memo) { let newDiscuss = response.data.memo; @@ -303,12 +308,12 @@ class MemoDetail extends Component { if (childCommentId) { deleteCommentId = childCommentId; } - const url = `/api/v1/memos/${deleteCommentId}` + const url = `/memos/${deleteCommentId}.json` let comments = this.state.comments; axios.delete(url, { - withCredentials: true + // withCredentials: true } ).then((response) => { // TODO 删除成功或失败 @@ -346,7 +351,7 @@ class MemoDetail extends Component { const { comments } = this.state; const commentIndex = this._findById(discussId, comments); - const url = `/api/v1/discusses/${discussId}/plus` + const url = `/discusses/${discussId}/plus.json` axios.post(url, { // id: discussId, // container_id: challenge.id, @@ -354,7 +359,7 @@ class MemoDetail extends Component { type: comments[commentIndex].user_praise === true ? 0 : 1, // "踩0;赞1" }, { - withCredentials: true + // withCredentials: true } ).then((response) => { if (response.data.praise_count === 0 || response.data.praise_count) { @@ -379,7 +384,7 @@ class MemoDetail extends Component { handleComment = childComment; } let handleCommentId = handleComment.id; - const url = `/api/v1/discusses/${handleCommentId}/reward_code` + const url = `/discusses/${handleCommentId}/reward_code.json` axios.post(url, { id: handleCommentId, @@ -389,7 +394,7 @@ class MemoDetail extends Component { user_id: handleComment.user_id }, { - withCredentials: true + // withCredentials: true } ).then((response) => { if (response.data && response.data.code) { @@ -423,7 +428,7 @@ class MemoDetail extends Component { const id = item.id const { showSnackbar } = this.props; const user = this._getUser(); - const url = `/api/v1/memos/${id}/hidden` + const url = `/memos/${id}/hidden.json` const { comments } = this.state; const commentIndex = this._findById(id, comments); @@ -432,7 +437,7 @@ class MemoDetail extends Component { hidden: !comment.hidden ? "1" : "0" }, { - withCredentials: true + // withCredentials: true } ).then((response) => { if (response.data.status === -1) { @@ -473,10 +478,12 @@ class MemoDetail extends Component { return; } } - const url = `/memos/${memo.id}/reply.json`; + // /${memo.id} + const url = `/memos/reply.json`; let { comments } = this.state; const user = this._getUser(); axios.post(url, { + parent_id: memo.id, content: content }, { @@ -488,6 +495,7 @@ class MemoDetail extends Component { return; } if (response.data) { + response.data.memo = response.data const newMemo = response.data.memo; // ke editor.html && editor.html(''); @@ -536,12 +544,12 @@ class MemoDetail extends Component { let { comments, pageCount } = this.state; let { memo } = this.props; 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, { }, { - withCredentials: true + // withCredentials: true } ).then((response) => { if (response.data.status === -1) { @@ -608,9 +616,8 @@ class MemoDetail extends Component { const { memo, author_info } = this.props; const newMemo = Object.assign({}, memo); 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, { id: memo.id, diff --git a/public/react/src/modules/forums/MemoDetailMDEditor.js b/public/react/src/modules/forums/MemoDetailMDEditor.js index f15a19e20..00a87274d 100644 --- a/public/react/src/modules/forums/MemoDetailMDEditor.js +++ b/public/react/src/modules/forums/MemoDetailMDEditor.js @@ -42,7 +42,7 @@ class MemoDetailMDEditor extends Component { window.__tt = 400; setTimeout(() => { var commentMDEditor = window.create_editorMD_4comment("memo_comment_editorMd", '', this.props.height || 240, placeholder, imageUrl, () => { - commentMDEditor.focus() + // commentMDEditor.focus() this.isMDInited = true this.initDrag() diff --git a/public/react/src/modules/forums/MemoNew.js b/public/react/src/modules/forums/MemoNew.js index 3e7464dc1..98d95ddce 100644 --- a/public/react/src/modules/forums/MemoNew.js +++ b/public/react/src/modules/forums/MemoNew.js @@ -15,6 +15,7 @@ import Upload from 'rc-upload'; import axios from 'axios' import 'antd/lib/select/style/index.css' +import TPMMDEditor from '../tpm/challengesnew/TPMMDEditor' import { getUrl } from 'educoder' const Option = Select.Option; @@ -130,6 +131,7 @@ const languageSeparator = '/' class MemoNew extends Component { constructor(props) { super(props) + this.mdRef = React.createRef(); // https://testbdweb.trustie.net/uploads.js?attachment_id=1&filename=jqui.js // https://ant.design/components/upload-cn/ @@ -179,7 +181,7 @@ class MemoNew extends Component { } let mdVal; try { - mdVal = this.taskpass_editormd.getValue() + mdVal = this.mdRef.current.getValue() } catch (e) { showSnackbar('编辑器还未加载完毕,请稍后') @@ -205,6 +207,7 @@ class MemoNew extends Component { // collect attachments const $ = window.$; const attachmentsMap = {}; + const attachmentIds = [] $('#attachments_fields .attachment').each(( index, item ) => { const filename = $(item).find('.upload_filename').val(); // $($('#attachments_fields .attachment')[0]).find('input:nth-child(6)').val() @@ -215,13 +218,14 @@ class MemoNew extends Component { token, attachment_id } + attachmentIds.push(attachment_id) }) if (currentMemoId) { - this.updateMemo(attachmentsMap) + this.updateMemo(attachmentIds) } else { - this.newMemo(attachmentsMap) + this.newMemo(attachmentIds) } } onCancel() { @@ -235,20 +239,20 @@ class MemoNew extends Component { } updateMemo(attachmentsMap) { 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); - const newMemoUrl = `/api/v1/memos/${currentMemoId}/update` - axios.post(newMemoUrl, { + const newMemoUrl = `/memos/${currentMemoId}.json` + axios.put(newMemoUrl, { content_changed: this.contentChanged, tags: memoLanguage, - memo:{ + // memo:{ subject: memoSubject , content: mdVal, forum_id: memoType, repertoire_name: memoRepertoire, // language: memoLanguage.join(languageSeparator), // - }, + // }, attachments: attachmentsMap }, { // withCredentials: true, @@ -267,18 +271,18 @@ class MemoNew extends Component { } newMemo(attachmentsMap) { 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, { tags: memoLanguage, - memo:{ + // memo:{ subject: memoSubject , content: mdVal, forum_id: memoType, - repertoire_name: memoRepertoire, + // repertoire_name: memoRepertoire, - }, + // }, attachments: attachmentsMap }, { // withCredentials: true, @@ -296,7 +300,7 @@ class MemoNew extends Component { }) } componentDidMount() { - const newMemoUrl = `/api/v1/memos/new` + const newMemoUrl = `/memos/new.json` axios.get(newMemoUrl,{ // withCredentials: true, }) @@ -336,7 +340,7 @@ class MemoNew extends Component { const { match } = this.props const memoId = match.params.memoId; if (memoId) { - const memoUrl = `/api/v1/memos/${match.params.memoId}/edit`; + const memoUrl = `/memos/${match.params.memoId}/edit.json`; axios.get(memoUrl,{ // withCredentials: true, }) @@ -344,10 +348,12 @@ class MemoNew extends Component { const tag_list = response.data.tag_list if (tag_list) { // this.setState({...response.data}) - const { content, forum_id, id, tag, repertoire_name, subject, - current_user, tag_list, attachments_url } = response.data; + const { content, forum_id, id, repertoire_name, subject, + current_user, tag_list, attachments_url, memo_tags } = response.data; this.initMD(content); // this.onRepertoiresChange(repertoire_name) + // tag -> memo_tags + const tag = memo_tags; let memoLanguage = [] if (tag) { memoLanguage = tag.map((item, index) => { @@ -355,7 +361,7 @@ class MemoNew extends Component { }) } this.setState({ - currentMemoId: id, + currentMemoId: memoId, memoSubject: subject, memoType: forum_id, memoRepertoire: repertoire_name, @@ -377,7 +383,7 @@ class MemoNew extends Component { window.$("html,body").animate({"scrollTop":0}) this.props.initForumState({ - current_user, + // current_user, tag_list }) } @@ -394,6 +400,8 @@ class MemoNew extends Component { } initMD(initValue) { + return; + this.contentChanged = false; const placeholder = ""; // amp; @@ -566,9 +574,12 @@ class MemoNew extends Component {

*
-
+ + + {/*
-
+
*/}