|
|
|
@ -4,7 +4,7 @@
|
|
|
|
|
* @Github:
|
|
|
|
|
* @Date: 2019-11-27 14:59:51
|
|
|
|
|
* @LastEditors: tangjiang
|
|
|
|
|
* @LastEditTime: 2019-12-06 17:17:27
|
|
|
|
|
* @LastEditTime: 2019-12-06 18:48:52
|
|
|
|
|
*/
|
|
|
|
|
import React, { useState, useEffect } from 'react';
|
|
|
|
|
import {connect} from 'react-redux';
|
|
|
|
@ -22,12 +22,14 @@ const RightPane = (props) => {
|
|
|
|
|
hack,
|
|
|
|
|
updateCode,
|
|
|
|
|
saveUserInputCode,
|
|
|
|
|
restoreInitialCode
|
|
|
|
|
restoreInitialCode,
|
|
|
|
|
saveUserCodeForInterval
|
|
|
|
|
} = props;
|
|
|
|
|
|
|
|
|
|
const [editorCode, setEditorCode] = useState('');
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
console.log('1111111');
|
|
|
|
|
setEditorCode(hack.code);
|
|
|
|
|
}, [hack]);
|
|
|
|
|
|
|
|
|
@ -38,22 +40,19 @@ const RightPane = (props) => {
|
|
|
|
|
// updateCode(identifier, submitInput, 'submit');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let timer = null; // 定时器
|
|
|
|
|
// 代码块内容变化时
|
|
|
|
|
const handleCodeChange = (code) => {
|
|
|
|
|
// 保存用户提交的代码块
|
|
|
|
|
// console.log(code);
|
|
|
|
|
// 保存用户代码块
|
|
|
|
|
const { userCode } = props;
|
|
|
|
|
let timer;
|
|
|
|
|
console.log(code);
|
|
|
|
|
if (!timer) {
|
|
|
|
|
timer = setInterval(() => {
|
|
|
|
|
if (userCode && userCode !== code) {
|
|
|
|
|
} else {
|
|
|
|
|
clearInterval(timer);
|
|
|
|
|
timer = null;
|
|
|
|
|
}
|
|
|
|
|
clearInterval(timer);
|
|
|
|
|
timer = null;
|
|
|
|
|
saveUserCodeForInterval(identifier, code);
|
|
|
|
|
}, 3000);
|
|
|
|
|
}
|
|
|
|
|
// 保存用户代码块
|
|
|
|
|
saveUserInputCode(code);
|
|
|
|
|
}
|
|
|
|
|
// 代码调试
|
|
|
|
@ -86,11 +85,10 @@ const RightPane = (props) => {
|
|
|
|
|
|
|
|
|
|
const mapStateToProps = (state) => {
|
|
|
|
|
|
|
|
|
|
const {user_program_identifier, hack, userTestInput, userCode} = state.ojForUserReducer;
|
|
|
|
|
const {user_program_identifier, hack, userTestInput} = state.ojForUserReducer;
|
|
|
|
|
// const { language, code } = hack;
|
|
|
|
|
return {
|
|
|
|
|
hack,
|
|
|
|
|
userCode,
|
|
|
|
|
input: userTestInput,
|
|
|
|
|
submitInput: hack.input,
|
|
|
|
|
identifier: user_program_identifier
|
|
|
|
@ -102,8 +100,10 @@ const mapDispatchToProps = (dispatch) => ({
|
|
|
|
|
submitUserCode: (identifier, inputValue, type) => dispatch(actions.submitUserCode(identifier, inputValue, type)),
|
|
|
|
|
// 更新代码块内容
|
|
|
|
|
updateCode: (identifier, inputValue, type) => dispatch(actions.updateCode(identifier, inputValue, type)),
|
|
|
|
|
// 保存用户代码块
|
|
|
|
|
// 保存用户代码块至Reducer中
|
|
|
|
|
saveUserInputCode: (code) => dispatch(actions.saveUserInputCode(code)),
|
|
|
|
|
// 保存用户代码至后台
|
|
|
|
|
saveUserCodeForInterval: (identifier, code) => dispatch(actions.saveUserCodeForInterval(identifier, code)),
|
|
|
|
|
// 恢复初始代码
|
|
|
|
|
restoreInitialCode: (identifier) => dispatch(actions.restoreInitialCode(identifier)),
|
|
|
|
|
});
|
|
|
|
|