-
+
+
{renderNumb()}
)
@@ -54,7 +69,7 @@ const TextNumber = (props) => {
}
return (
- {renderCtx()}
+ {renderCtx(className, theme)}
);
}
diff --git a/public/react/src/modules/developer/newOrEditTask/index.js b/public/react/src/modules/developer/newOrEditTask/index.js
index b498abe0d..a67da5bb6 100644
--- a/public/react/src/modules/developer/newOrEditTask/index.js
+++ b/public/react/src/modules/developer/newOrEditTask/index.js
@@ -9,7 +9,7 @@ import './index.scss';
import React, { useEffect } from 'react';
import { connect } from 'react-redux';
import SplitPane from 'react-split-pane';// import { Form } from 'antd';
-import { Button, Modal } from 'antd';
+import { Button } from 'antd';
import LeftPane from './leftpane';
import RightPane from './rightpane';
import { withRouter } from 'react-router';
diff --git a/public/react/src/modules/developer/newOrEditTask/leftpane/index.js b/public/react/src/modules/developer/newOrEditTask/leftpane/index.js
index 781b82699..ec0ca1416 100644
--- a/public/react/src/modules/developer/newOrEditTask/leftpane/index.js
+++ b/public/react/src/modules/developer/newOrEditTask/leftpane/index.js
@@ -11,7 +11,6 @@ import React, { useState, useMemo } from 'react';
// import { Tabs } from 'antd';
import EditorTab from './editorTab';
import PrevTab from './prevTab';
-import CommitTab from './commitTab';
// const { TabPane } = Tabs;
diff --git a/public/react/src/modules/developer/studentStudy/leftpane/comment/index.js b/public/react/src/modules/developer/studentStudy/leftpane/comment/index.js
index ca7160117..46d7b4e38 100644
--- a/public/react/src/modules/developer/studentStudy/leftpane/comment/index.js
+++ b/public/react/src/modules/developer/studentStudy/leftpane/comment/index.js
@@ -3,19 +3,112 @@
* @Author: tangjiang
* @Github:
* @Date: 2019-11-27 09:49:35
- * @LastEditors: tangjiang
- * @LastEditTime: 2019-12-17 17:46:05
+ * @LastEditors : tangjiang
+ * @LastEditTime : 2019-12-24 17:10:14
*/
import './index.scss';
-import React from 'react';
+import React, { useEffect } from 'react';
import Comment from '../../../../../common/components/comment';
+import { connect } from 'react-redux';
+import actions from '../../../../../redux/actions';
+
const CommentTask = (props) => {
+ const {
+ identifier,
+ commentLists,
+ addComment,
+ likeComment,
+ deleteComment,
+ getCommentLists,
+ showOrHideComment,
+ replayChildComment
+ } = props;
+
+ useEffect(() => {
+ if (identifier) {
+ // 获取评论列表数据
+ getCommentLists(identifier);
+ }
+ }, [identifier]);
+
+ // 添加评论
+ const handleAddComment = (ctx) => {
+ console.log('添加的评论内容: ', ctx);
+ addComment(identifier, {
+ comments: {
+ content: ctx
+ }
+ });
+ };
+ // 添加子评论
+ const handleAddChildComment = (parentId, ctx) => {
+ replayChildComment(identifier, {
+ comments: {
+ content: ctx,
+ parent_id: parentId
+ }
+ });
+ }
+ // 删除评论
+ const handleSubmitDeleteComment = (id) => {
+ console.log('删除评论:', identifier, id);
+ deleteComment(identifier, id);
+ }
+
+ // 点赞
+ const handleLikeComment = (id) => {
+ likeComment(identifier, id, {
+ container_type: 'Discuss',
+ type: 1
+ });
+ }
+
+ // 显示或隐藏
+ const handleShowOrHideComment = (id, hidden) => {
+ showOrHideComment(identifier, id, {
+ hidden
+ });
+ }
+
return (
-
+
)
}
-export default CommentTask;
+const mapStateToProps = (state) => {
+ const {
+ commentLists // 评论列表
+ } = state.commentReducer;
+ const {
+ comment_identifier
+ } = state.ojForUserReducer;
+ return {
+ commentLists,
+ identifier: comment_identifier
+ }
+}
+
+const mapDispatchToProps = (dispatch) => ({
+ // getCommentLists: (identifier) => dispatch(action.getCommentLists(identifier))
+ getCommentLists: (identifier) => dispatch(actions.getCommentLists(identifier)),
+ addComment: (identifier, comments) => dispatch(actions.addComment(identifier, comments)),
+ replayChildComment: (identifier, comment) => dispatch(actions.replayChildComment(identifier, comment)),
+ deleteComment: (identifier, id) => dispatch(actions.deleteComment(identifier, id)),
+ likeComment: (identifier, id, params) => dispatch(actions.likeComment(identifier, id, params)),
+ showOrHideComment: (identifier, id, params) => dispatch(actions.showOrHideComment(identifier, id, params)),
+})
+
+export default connect(
+ mapStateToProps,
+ mapDispatchToProps
+)(CommentTask);
diff --git a/public/react/src/modules/developer/studentStudy/leftpane/index.js b/public/react/src/modules/developer/studentStudy/leftpane/index.js
index 347f4b4f8..53e932db1 100644
--- a/public/react/src/modules/developer/studentStudy/leftpane/index.js
+++ b/public/react/src/modules/developer/studentStudy/leftpane/index.js
@@ -3,8 +3,8 @@
* @Author: tangjiang
* @Github:
* @Date: 2019-11-23 11:33:41
- * @LastEditors: tangjiang
- * @LastEditTime: 2019-12-19 18:03:22
+ * @LastEditors : tangjiang
+ * @LastEditTime : 2019-12-24 17:16:54
// */
import './index.scss';
import React, { useState, useEffect, useMemo } from 'react';
@@ -15,12 +15,19 @@ import CommitRecord from './commitRecord';
import TaskDescription from './taskDescription';
import TextNumber from './../../components/textNumber';
import actions from '../../../../redux/actions';
+import CommentForm from '../../../../common/components/comment/CommentForm';
// const { TabPane } = Tabs;
const LeftPane = (props) => {
const { hack, userCodeTab } = props;
- const { pass_count, submit_count } = hack;
+ const {
+ pass_count,
+ submit_count,
+ praises_count, /* 点赞数 */
+ comments_count, /* 评论数*/
+ user_praise // 用户是否点赞
+ } = hack;
const [defaultActiveKey, setDefaultActiveKey] = useState('comment');
const navItem = [
@@ -32,10 +39,10 @@ const LeftPane = (props) => {
title: '提交记录',
key: 'record'
},
- // {
- // title: '评论',
- // key: 'comment'
- // }
+ {
+ title: '评论',
+ key: 'comment'
+ }
];
const Comp = {
@@ -45,7 +52,6 @@ const LeftPane = (props) => {
};
useEffect(() => {
- console.log('====>>>>', userCodeTab);
setDefaultActiveKey(userCodeTab);
}, [userCodeTab])
@@ -69,18 +75,34 @@ const LeftPane = (props) => {
// 点击消息
const handleClickMessage = () => {
- console.log('点击的消息图标---------');
+ // 切换到评论tab
+ setDefaultActiveKey('comment');
}
// 点击点赞
const handleClickLike = () => {
- console.log('点击的Like---------');
- }
+ // 对OJ进行点赞
+ const {id, identifier } = props.hack;
+ props.likeComment(identifier, id, {
+ container_type: 'Hack',
+ type: 1
+ });
+ };
// 点击不喜欢
- const handleClickDisLike = () => {
- console.log('点击的DisLike---------');
- }
+ // const handleClickDisLike = () => {
+ // console.log('点击的DisLike---------');
+ // }
+
+ // 添加评论
+ const handleAddComment = (ctx) => {
+ console.log('添加的评论内容: ', ctx, props.identifier);
+ props.identifier && props.addComment(props.identifier, {
+ comments: {
+ content: ctx
+ }
+ });
+ };
return (
@@ -91,26 +113,46 @@ const LeftPane = (props) => {
{ renderComp }
-
+
+
+
+
+
+
+
+ {/* */}
+
);
}
const mapStateToProps = (state) => {
- const { hack, userCodeTab} = state.ojForUserReducer;
+ const { hack, userCodeTab, comment_identifier} = state.ojForUserReducer;
return {
hack,
- userCodeTab
+ userCodeTab,
+ identifier: comment_identifier
}
}
// changeUserCodeTab
const mapDispatchToProps = (dispatch) => ({
- changeUserCodeTab: (key) => dispatch(actions.changeUserCodeTab(key))
+ changeUserCodeTab: (key) => dispatch(actions.changeUserCodeTab(key)),
+ likeComment: (identifier, id, params) => dispatch(actions.likeComment(identifier, id, params)),
+ addComment: (identifier, comments) => dispatch(actions.addComment(identifier, comments))
});
export default connect(
mapStateToProps,
diff --git a/public/react/src/modules/developer/studentStudy/leftpane/index.scss b/public/react/src/modules/developer/studentStudy/leftpane/index.scss
index b5362429f..2468ba368 100644
--- a/public/react/src/modules/developer/studentStudy/leftpane/index.scss
+++ b/public/react/src/modules/developer/studentStudy/leftpane/index.scss
@@ -21,13 +21,33 @@
background: #fff;
.flex_count,
- .flex_info{
+ .flex_info,
+ .flex_quill{
display: flex;
flex-direction: row;
justify-content: space-between;
}
.flex_info{
- width: 200px;
+ // width: 140px;
+ justify-content: flex-end;
+
+ .like{
+ margin-left: 20px
+ }
+ .like.active{
+ .numb_icon{
+ color: #5091FF;
+ }
+ }
+ }
+
+ .flex_quill{
+ // position: relative;
+ flex: 1;
+ align-items: center;
+ height: 100%;
+ top: 10px;
+ margin-right: 20px;
}
}
diff --git a/public/react/src/redux/actions/actionTypes.js b/public/react/src/redux/actions/actionTypes.js
index 474ecb382..deeb8fa93 100644
--- a/public/react/src/redux/actions/actionTypes.js
+++ b/public/react/src/redux/actions/actionTypes.js
@@ -24,6 +24,7 @@ const types = {
DELETE_TEST_CASE: 'DELETE_TEST_CASE', // 删除测试用例
SAVE_TEST_CASE: 'SAVE_TEST_CASE', // 保存测试用例
SAVE_USE_TEST_CASE_VALUE: 'SAVE_USE_TEST_CASE_VALUE', // 用户自定义测试用例值
+ CHANGE_PUBLISH_VALUE: 'CHANGE_PUBLISH_VALUE', // 改变发布状态值
CLEAR_JSFORM_STORE: 'CLEAR_JSFORM_STORE', // 清空测试用例
SAVE_EDIT_OJ_FORM_AND_TEST_CASE: 'SAVE_EDIT_OJ_FORM_AND_TEST_CASE', // 保存根据id获取的表单及测试用例值
TEST_CODE_STATUS: 'TEST_CODE_STATUS', // 代码调试状态
@@ -53,6 +54,7 @@ const types = {
SAVE_EDITOR_CODE: 'SAVE_EDITOR_CODE', // 保存详情页面中编辑时的代码
CLICK_OPERATE_TYPE: 'CLICK_OPERATE_TYPE', // 点击类型
CLEAR_OJ_FOR_USER_REDUCER: 'CLEAR_OJ_FOR_USER_REDUCER', // 退出时清空 ojForUserReducer保存内容
+ ADD_OJ_LIKE_COUNT: 'ADD_OJ_LIKE_COUNT', // 增加点赞数
/*** jupyter */
GET_JUPYTER_DATA_SETS: 'GET_JUPYTER_DATA_SETS', // jupyter 数据集
GET_JUPYTER_TPI_URL: 'GET_JUPYTER_TPI_URL', // 获取 jupyter url
@@ -67,6 +69,12 @@ const types = {
CHANGE_JYPYTER_TIME: 'CHANGE_JYPYTER_TIME',//增加15分钟
CHANGE_EXTENDED_TIME: 'CHANGE_EXTENDED_TIME',//延时
CHANGE_UPDETA_SPIN: 'CHANGE_UPDETA_SPIN',//加载
+ /*** 评论 */
+ ADD_COMMENTS: 'ADD_COMMENTS', // 添加评论
+ GET_COMMENT_LISTS: 'GET_COMMENT_LISTS', // 获取评论列表
+ REPLAY_CHILD_COMMENTS: 'REPLAY_CHILD_COMMENTS', // 子回复
+ DELETE_COMMENTS: 'DELETE_COMMENTS', // 删除评论
+ SAVE_COMMENT_IDENTIFIER: 'SAVE_COMMENT_IDENTIFIER' // 评论时的identifier
}
export default types;
diff --git a/public/react/src/redux/actions/comment.js b/public/react/src/redux/actions/comment.js
new file mode 100644
index 000000000..7927e3cd6
--- /dev/null
+++ b/public/react/src/redux/actions/comment.js
@@ -0,0 +1,114 @@
+/*
+ * @Description:
+ * @Author: tangjiang
+ * @Github:
+ * @Date: 2019-12-23 10:53:25
+ * @LastEditors : tangjiang
+ * @LastEditTime : 2019-12-24 16:17:00
+ */
+import types from "./actionTypes";
+
+import {
+ fetchAddComment,
+ fetchCommentLists,
+ fetchAddChildComment,
+ fetchDeleteComment,
+ fetchLikeComment,
+ fetchShowOrHideComment
+} from '../../services/commentService';
+
+// 添加评论
+export const addComment = (identifier, comments) => {
+ return (dispatch) => {
+ fetchAddComment(identifier, comments).then(res => {
+ if (res.status === 200) {
+ // 重新加载评论列表
+ dispatch(getCommentLists(identifier));
+ }
+ });
+ }
+};
+
+// 获取评论列表
+export const getCommentLists = (identifier) => {
+ return (dispatch) => {
+ fetchCommentLists(identifier).then(res => {
+ console.log('获取评论列表: ====>>>>', res);
+ if (res.status === 200) {
+ const {data} = res;
+ dispatch({
+ type: types.GET_COMMENT_LISTS,
+ payload: data
+ })
+ }
+ });
+ }
+}
+
+// 子回复
+export const replayChildComment = (identifier, comment) => {
+ return (dispatch) => {
+ fetchAddChildComment(identifier, comment).then(res => {
+ // console.log('添加子评论成功: ====>>>>', res);
+ if (res.status === 200) {
+ // 重新加载评论列表
+ dispatch(getCommentLists(identifier));
+ }
+ });
+ }
+}
+
+// 删除评论
+export const deleteComment = (identifier, delId) => {
+ return (dispatch) => {
+ fetchDeleteComment(identifier, delId).then(res => {
+ if (res.status === 200) {
+ // 重新加载评论列表
+ dispatch(getCommentLists(identifier));
+ }
+ });
+ }
+}
+
+// 点赞
+export const likeComment = (identifier, id, params, cb) => {
+ return (dispatch) => {
+ fetchLikeComment(id, params).then(res => {
+ if (res.status === 200) {
+ // 重新加载评论列表
+ const {container_type} = params;
+ // if (container_type === 'Discuss') {
+ // dispatch(getCommentLists(identifier))
+ // } else if {
+ // }
+ const {praise_count} = res.data;
+ switch (container_type) {
+ case 'Discuss':
+ dispatch(getCommentLists(identifier))
+ break;
+ case 'Hack':
+ dispatch({
+ type: types.ADD_OJ_LIKE_COUNT,
+ payload: praise_count
+ });
+ break;
+ default:
+ break;
+ }
+ }
+ })
+ }
+}
+
+// 显示或隐藏评论
+export const showOrHideComment = (identifier, id, params) => {
+ return (dispatch) => {
+ fetchShowOrHideComment(identifier, id, params).then(res => {
+ if (res.status === 200) {
+ // 重新加载评论列表
+ dispatch(getCommentLists(identifier));
+ }
+ });
+ }
+}
+
diff --git a/public/react/src/redux/actions/index.js b/public/react/src/redux/actions/index.js
index ebea3f5f5..197673f80 100644
--- a/public/react/src/redux/actions/index.js
+++ b/public/react/src/redux/actions/index.js
@@ -65,6 +65,15 @@ import {
getUserInfoForNew
} from './user';
+import {
+ addComment,
+ getCommentLists,
+ replayChildComment,
+ deleteComment,
+ likeComment,
+ showOrHideComment
+} from './comment';
+
import {
getJupyterTpiDataSet,
getJupyterTpiUrl,
@@ -137,6 +146,13 @@ export default {
reset_with_tpi,
addjypertime,
active_with_tpi,
- updataspinning
+ updataspinning,
// isUpdateCodeCtx
+ // 评论
+ addComment,
+ getCommentLists,
+ replayChildComment,
+ deleteComment,
+ likeComment,
+ showOrHideComment,
}
\ No newline at end of file
diff --git a/public/react/src/redux/actions/ojForUser.js b/public/react/src/redux/actions/ojForUser.js
index 8a44677ef..db2b7c300 100644
--- a/public/react/src/redux/actions/ojForUser.js
+++ b/public/react/src/redux/actions/ojForUser.js
@@ -3,8 +3,8 @@
* @Author: tangjiang
* @Github:
* @Date: 2019-11-27 13:42:11
- * @LastEditors: tangjiang
- * @LastEditTime: 2019-12-20 19:30:30
+ * @LastEditors : tangjiang
+ * @LastEditTime : 2019-12-23 11:55:48
*/
import types from "./actionTypes";
import { Base64 } from 'js-base64';
diff --git a/public/react/src/redux/actions/ojForm.js b/public/react/src/redux/actions/ojForm.js
index b4d43812d..68185ed7b 100644
--- a/public/react/src/redux/actions/ojForm.js
+++ b/public/react/src/redux/actions/ojForm.js
@@ -3,8 +3,8 @@
* @Author: tangjiang
* @Github:
* @Date: 2019-11-20 16:35:46
- * @LastEditors: tangjiang
- * @LastEditTime: 2019-12-20 19:54:09
+ * @LastEditors : tangjiang
+ * @LastEditTime : 2019-12-23 10:55:28
*/
import types from './actionTypes';
import CONST from '../../constants';
@@ -86,16 +86,16 @@ const payloadInfo = (key, value, errMsg, validateInfo) => ({
});
// 接口调用成功后,跳转至列表页
-function linkToDev (dispatch, props) {
- toStore('oj_description', '');
- dispatch({
- type: types.IS_MY_SOURCE,
- payload: true
- });
- setTimeout(() => {
- props.history.push('/problems');
- }, 1000);
-}
+// function linkToDev (dispatch, props) {
+// toStore('oj_description', '');
+// dispatch({
+// type: types.IS_MY_SOURCE,
+// payload: true
+// });
+// setTimeout(() => {
+// props.history.push('/problems');
+// }, 1000);
+// }
// 表单提交验证
export const validateOjForm = (props, type) => {
@@ -250,18 +250,24 @@ export const validateOjForm = (props, type) => {
if (type === 'publish') {
// 提示发布信息
publishTask(identifier).then(res => {
+ dispatch({
+ type: types.PUBLISH_LOADING_STATUS,
+ payload: false
+ });
+
if (res.data.status === 0) {
// message.success('发布成功!');
notification.success({
message: '提示',
description: '发布成功!'
});
- linkToDev(dispatch, props);
+ // linkToDev(dispatch, props);
+ // 改变发布状态值 0 => 1
+ dispatch({
+ type: types.CHANGE_PUBLISH_VALUE,
+ payload: 1
+ });
}
- dispatch({
- type: types.PUBLISH_LOADING_STATUS,
- payload: false
- });
}).catch(() => {
dispatch({
type: types.PUBLISH_LOADING_STATUS,
@@ -273,25 +279,32 @@ export const validateOjForm = (props, type) => {
fetchPostOjForm(paramsObj).then(res => {
if (res.status === 200) { // 保存成功后,重新跳转至列表页
if (res.data.status === 0) {
+ // 改变按钮loading状态
+ dispatch({
+ type: types.SUBMIT_LOADING_STATUS,
+ payload: false
+ });
// message.success(paramsObj['submitType'] === 'update' ? '更新成功' : '保存成功');
notification.success({
message: '提示',
description: paramsObj['submitType'] === 'update' ? '更新成功' : '保存成功'
});
- linkToDev(dispatch, props);
- }
- dispatch({
- type: types.SUBMIT_LOADING_STATUS,
- payload: false
+ const {identifier} = res.data;
+ // 保存成功后的identifier
+ identifier && dispatch({
+ type: types.SAVE_OJ_FORM_ID,
+ payload: identifier
});
+ // 保存或更新后,调用start接口
+ // linkToDev(dispatch, props);
}
- }).catch(err => {
- dispatch({
- type: types.SUBMIT_LOADING_STATUS,
- payload: false
- });
- }
- );
+ }}
+ ).catch(err => {
+ dispatch({
+ type: types.SUBMIT_LOADING_STATUS,
+ payload: false
+ });
+ });
}
}
}
@@ -312,7 +325,12 @@ export const handleClickCancelPublish = (props, identifier) => {
message: '提示',
description: '撤销发布成功!'
});
- linkToDev(dispatch, props);
+ // 改变发布状态值
+ dispatch({
+ type: types.CHANGE_PUBLISH_VALUE,
+ payload: 0
+ });
+ // linkToDev(dispatch, props);
}
}
}).catch(() => {
diff --git a/public/react/src/redux/reducers/commentReducer.js b/public/react/src/redux/reducers/commentReducer.js
new file mode 100644
index 000000000..cf56f1965
--- /dev/null
+++ b/public/react/src/redux/reducers/commentReducer.js
@@ -0,0 +1,42 @@
+import types from "../actions/actionTypes";
+
+/*
+ * @Description: 评论reducer
+ * @Author: tangjiang
+ * @Github:
+ * @Date: 2019-12-23 10:35:31
+ * @LastEditors : tangjiang
+ * @LastEditTime : 2019-12-23 14:51:42
+ */
+const initialState = {
+ comments: {
+ content: '' // 评论内容
+ },
+ commentLists: {}, // 评论列表
+ pages: {
+ limit: 20,
+ page: 1
+ }
+};
+
+const commentReducer = (state = initialState, action) => {
+
+ const { payload, type } = action;
+ switch (type) {
+ case types.ADD_COMMENTS:
+ return {
+ ...state
+ }
+ case types.GET_COMMENT_LISTS:
+ return {
+ ...state,
+ commentLists: Object.assign({}, payload)
+ }
+ default:
+ return {
+ ...state
+ }
+ }
+}
+
+export default commentReducer;
diff --git a/public/react/src/redux/reducers/index.js b/public/react/src/redux/reducers/index.js
index 9c28448a3..206f34384 100644
--- a/public/react/src/redux/reducers/index.js
+++ b/public/react/src/redux/reducers/index.js
@@ -14,6 +14,7 @@ import ojForUserReducer from './ojForUserReducer';
import commonReducer from './commonReducer';
import userReducer from './userReducer';
import jupyterReducer from './jupyterReducer';
+import commentReducer from './commentReducer';
export default combineReducers({
testReducer,
@@ -22,5 +23,6 @@ export default combineReducers({
ojForUserReducer,
commonReducer,
userReducer,
- jupyterReducer
+ jupyterReducer,
+ commentReducer
});
diff --git a/public/react/src/redux/reducers/ojForUserReducer.js b/public/react/src/redux/reducers/ojForUserReducer.js
index 7e3740c19..0950d7442 100644
--- a/public/react/src/redux/reducers/ojForUserReducer.js
+++ b/public/react/src/redux/reducers/ojForUserReducer.js
@@ -3,11 +3,12 @@
* @Author: tangjiang
* @Github:
* @Date: 2019-11-27 13:41:48
- * @LastEditors: tangjiang
- * @LastEditTime: 2019-12-20 14:46:07
+ * @LastEditors : tangjiang
+ * @LastEditTime : 2019-12-24 16:35:09
*/
import types from "../actions/actionTypes";
import { Base64 } from 'js-base64';
+import actions from "../actions";
const initialState = {
user_program_identifier: '', // 开启OJ题的唯一标题
@@ -26,6 +27,7 @@ const initialState = {
notice: false, // 通知
hadCodeUpdate: false, // 更新代码
operateType: '', // 点击类型: 调度或提交
+ comment_identifier: '' // 用户评论时使用的 identifier
};
const ojForUserReducer = (state = initialState, action) => {
@@ -50,7 +52,8 @@ const ojForUserReducer = (state = initialState, action) => {
return {
...state,
hack: Object.assign({}, hack),
- test_case: Object.assign({}, test_case)
+ test_case: Object.assign({}, test_case),
+ comment_identifier: hack.identifier
}
case types.COMMIT_RECORD_DETAIL:
let result = action.payload.data;
@@ -179,6 +182,23 @@ const ojForUserReducer = (state = initialState, action) => {
hadCodeUpdate: false, // 更新代码
operateType: '', // 点击类型: 调度或提交
};
+ // 保存评论时用的 identifer
+ case types.SAVE_COMMENT_IDENTIFIER:
+ return {
+ ...state,
+ comment_identifier: actions.payload
+ };
+ // 是否点赞
+ case types.ADD_OJ_LIKE_COUNT:
+ let _count = state.hack.praises_count;
+ let _user_praise = state.hack.user_praise;
+ _count = +action.payload > 0 ? _count + 1 : _count - 1;
+ _user_praise = +action.payload > 0 ? true : false;
+ const _hack = Object.assign({}, state.hack, {praises_count: _count, user_praise: _user_praise});
+ return {
+ ...state,
+ hack: _hack
+ }
default:
return state;
}
diff --git a/public/react/src/redux/reducers/ojFormReducer.js b/public/react/src/redux/reducers/ojFormReducer.js
index 5e76cabee..43e4c2b3d 100644
--- a/public/react/src/redux/reducers/ojFormReducer.js
+++ b/public/react/src/redux/reducers/ojFormReducer.js
@@ -3,8 +3,8 @@
* @Author: tangjiang
* @Github:
* @Date: 2019-11-20 16:40:32
- * @LastEditors: tangjiang
- * @LastEditTime: 2019-12-20 16:40:52
+ * @LastEditors : tangjiang
+ * @LastEditTime : 2019-12-23 10:12:59
*/
import { Base64 } from 'js-base64';
import types from '../actions/actionTypes';
@@ -158,9 +158,10 @@ const ojFormReducer = (state = initialState, action) => {
testCasesValidate: [...tempTestValicate]
};
case types.SAVE_OJ_FORM_ID:
- state.identifier = action.payload;
+ // state.identifier = action.payload;
return {
- ...state
+ ...state,
+ identifier: action.payload
}
case types.SAVE_EDIT_OJ_FORM_AND_TEST_CASE: // 保存编辑的值
/**
@@ -211,6 +212,11 @@ const ojFormReducer = (state = initialState, action) => {
testCodeStatus: hack_sets.length > 0 ? 'userCase' : 'default',
isPublish: status
}
+ case types.CHANGE_PUBLISH_VALUE:
+ return {
+ ...state,
+ isPublish: action.payload
+ };
case types.CLEAR_JSFORM_STORE:
state = Object.assign({}, init);
return {
diff --git a/public/react/src/services/commentService.js b/public/react/src/services/commentService.js
new file mode 100644
index 000000000..47eb347d2
--- /dev/null
+++ b/public/react/src/services/commentService.js
@@ -0,0 +1,45 @@
+/*
+ * @Description: 评论 service
+ * @Author: tangjiang
+ * @Github:
+ * @Date: 2019-12-23 10:43:27
+ * @LastEditors : tangjiang
+ * @LastEditTime : 2019-12-24 17:10:49
+ */
+import axios from 'axios';
+
+// 添加评论
+export async function fetchAddComment (identifier, params) {
+ const url = `/problems/${identifier}/comments.json`;
+ return axios.post(url, params);
+}
+
+// 获取评论列表
+export async function fetchCommentLists (identifier) {
+ const url = `/problems/${identifier}/comments.json`;
+ return axios.get(url);
+}
+
+// 添加子评论
+export async function fetchAddChildComment (identifier, params) {
+ const url = `/problems/${identifier}/comments/reply.json`;
+ return axios.post(url, params);
+}
+
+// 删除评论
+export async function fetchDeleteComment (identifier, id) {
+ const url = `/problems/${identifier}/comments/${id}.json`;
+ return axios.delete(url);
+}
+
+// 点赞
+export async function fetchLikeComment (id, params) {
+ const url = `/discusses/${id}/plus.json`;
+ return axios.post(url, params);
+}
+
+// 显示或隐藏
+export async function fetchShowOrHideComment (identifier, id, params) {
+ const url = `/problems/${identifier}/comments/${id}/hidden.json`;
+ return axios.post(url, params);
+}
\ No newline at end of file