From 26b78bcfb31ff8e82ae73c2b6a31a49bb4bd9cdd Mon Sep 17 00:00:00 2001 From: hjm <63528605@qq.com> Date: Wed, 21 Aug 2019 16:12:05 +0800 Subject: [PATCH 1/2] =?UTF-8?q?updateFile=E5=88=87=E6=8D=A2=E5=85=B3?= =?UTF-8?q?=E5=8D=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/react/src/modules/page/MainContentContainer.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/public/react/src/modules/page/MainContentContainer.js b/public/react/src/modules/page/MainContentContainer.js index 33257703d..3dc3d07d4 100644 --- a/public/react/src/modules/page/MainContentContainer.js +++ b/public/react/src/modules/page/MainContentContainer.js @@ -230,6 +230,7 @@ class MainContentContainer extends Component { && prevProps.game.identifier !== game.identifier) { // 切换关卡时,停止轮训 this.oldGameIdentifier = prevProps.game.identifier; + this.doFileUpdateRequestOnCodeMirrorBlur(prevProps) } } @@ -384,8 +385,8 @@ class MainContentContainer extends Component { } - doFileUpdateRequestOnCodeMirrorBlur = () => { - var fileUpdatePromise = this.doFileUpdateRequest(true) + doFileUpdateRequestOnCodeMirrorBlur = (props) => { + var fileUpdatePromise = this.doFileUpdateRequest(true, undefined, props) if (fileUpdatePromise) { fileUpdatePromise.then((resData) => { if (resData.status === -1) { // 保存文件出现异常 @@ -494,7 +495,8 @@ class MainContentContainer extends Component { } // forTest true 是评测时触发的file_update - doFileUpdateRequest(checkIfCodeChanged, forTest) { + doFileUpdateRequest(checkIfCodeChanged, forTest, props) { + const _props = props || this.props; const { codeStatus } = this.state; if (!forTest && codeStatus !== UPDATED) { // 已修改状态才能保存 return; @@ -519,7 +521,7 @@ class MainContentContainer extends Component { }) return null; } - const { challenge, output_sets, onRunCodeTestFinish, myshixun } = this.props + const { challenge, output_sets, onRunCodeTestFinish, myshixun } = _props // var url = `${locationPath}/file_update?path=${encodeURIComponent(challenge.path)}` var url = `/myshixuns/${myshixun.identifier}/update_file.json` From b7634406e92f7b40fce6cfe07c16969aeb3d007a Mon Sep 17 00:00:00 2001 From: hjm <63528605@qq.com> Date: Thu, 22 Aug 2019 10:17:10 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E5=88=87=E6=8D=A2=E5=85=B3=E5=8D=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/react/src/modules/page/MainContentContainer.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/public/react/src/modules/page/MainContentContainer.js b/public/react/src/modules/page/MainContentContainer.js index 3dc3d07d4..a51f00902 100644 --- a/public/react/src/modules/page/MainContentContainer.js +++ b/public/react/src/modules/page/MainContentContainer.js @@ -224,13 +224,15 @@ class MainContentContainer extends Component { } componentDidUpdate(prevProps, prevState, snapshot) { - const { game } = this.props + const { game, challenge } = this.props if (game && prevProps.game && prevProps.game.identifier !== game.identifier) { // 切换关卡时,停止轮训 this.oldGameIdentifier = prevProps.game.identifier; this.doFileUpdateRequestOnCodeMirrorBlur(prevProps) + } else if (challenge && (challenge.pathIndex || prevProps.challenge.pathIndex) && challenge.pathIndex != prevProps.challenge.pathIndex) { + this.doFileUpdateRequestOnCodeMirrorBlur(prevProps) } }