mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-19 17:38:19 +08:00
+nginx.conf; update scratchpad
This commit is contained in:
1 parent
6ad41dc2ae
commit
2d5eef8d08
28 files changed
+206
-230
No files matched your search
@@ -1,28 +1,24 @@
|
||||
import React from 'react';
|
||||
import { connect } from 'react-redux';
|
||||
import Tabs, { TabPane } from 'rc-tabs';
|
||||
import TabContent from 'rc-tabs/lib/TabContent';
|
||||
import ScrollableInkTabBar from 'rc-tabs/lib/ScrollableInkTabBar';
|
||||
|
||||
import i18n from 'vj/utils/i18n';
|
||||
import Icon from 'vj/components/react/IconComponent';
|
||||
import Panel from './PanelComponent';
|
||||
import PanelButton from './PanelButtonComponent';
|
||||
import ScratchpadPretestTabPane from './ScratchpadPretestTabPaneContainer';
|
||||
import DataInput from './DataInputComponent';
|
||||
|
||||
const mapStateToProps = (state) => ({
|
||||
current: state.pretest.current,
|
||||
tabs: state.pretest.tabs,
|
||||
meta: state.pretest.meta,
|
||||
input: state.pretest.input,
|
||||
output: state.pretest.output,
|
||||
rid: state.pretest.rid,
|
||||
});
|
||||
|
||||
const mapDispatchToProps = (dispatch) => ({
|
||||
handleClickClose() {
|
||||
handleDataChange(type, value) {
|
||||
dispatch({
|
||||
type: 'SCRATCHPAD_UI_SET_VISIBILITY',
|
||||
type: 'SCRATCHPAD_PRETEST_DATA_CHANGE',
|
||||
payload: {
|
||||
uiElement: 'pretest',
|
||||
visibility: false,
|
||||
type,
|
||||
value,
|
||||
},
|
||||
});
|
||||
},
|
||||
@@ -41,32 +37,18 @@ export default class ScratchpadPretestContainer extends React.PureComponent {
|
||||
</span>
|
||||
)}
|
||||
>
|
||||
<Tabs
|
||||
className="scratchpad__panel-tab flex-col flex-fill"
|
||||
activeKey={this.props.current}
|
||||
onChange={(tabId) => this.props.handleSwitchData(tabId)}
|
||||
animation="slide-horizontal"
|
||||
renderTabBar={() => (
|
||||
<ScrollableInkTabBar
|
||||
extraContent={(
|
||||
<span>
|
||||
<PanelButton
|
||||
onClick={() => this.props.handleClickClose()}
|
||||
>
|
||||
<Icon name="close" />
|
||||
</PanelButton>
|
||||
</span>
|
||||
)}
|
||||
/>
|
||||
)}
|
||||
renderTabContent={() => <TabContent />}
|
||||
>
|
||||
{this.props.tabs.map((tabId) => (
|
||||
<TabPane tab={this.props.meta[tabId].title} key={tabId}>
|
||||
<ScratchpadPretestTabPane id={tabId} />
|
||||
</TabPane>
|
||||
))}
|
||||
</Tabs>
|
||||
<div className="flex-row flex-fill">
|
||||
<DataInput
|
||||
title={i18n('Input')}
|
||||
value={this.props.input}
|
||||
onChange={(v) => this.props.handleDataChange('input', v)}
|
||||
/>
|
||||
<DataInput
|
||||
title={i18n('Output')}
|
||||
value={this.props.output}
|
||||
onChange={(v) => this.props.handleDataChange('output', v)}
|
||||
/>
|
||||
</div>
|
||||
</Panel>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,49 +0,0 @@
|
||||
import React from 'react';
|
||||
import { connect } from 'react-redux';
|
||||
|
||||
import i18n from 'vj/utils/i18n';
|
||||
import DataInput from './DataInputComponent';
|
||||
|
||||
const mapStateToProps = (state) => ({
|
||||
data: state.pretest.data,
|
||||
});
|
||||
|
||||
const mapDispatchToProps = (dispatch) => ({
|
||||
handleDataChange(id, type, value) {
|
||||
dispatch({
|
||||
type: 'SCRATCHPAD_PRETEST_DATA_CHANGE',
|
||||
payload: {
|
||||
id,
|
||||
type,
|
||||
value,
|
||||
},
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
const mergeProps = (stateProps, dispatchProps, ownProps) => ({
|
||||
...dispatchProps,
|
||||
id: ownProps.id,
|
||||
input: stateProps.data[ownProps.id] ? stateProps.data[ownProps.id].input : '',
|
||||
output: stateProps.data[ownProps.id] ? stateProps.data[ownProps.id].output : '',
|
||||
});
|
||||
|
||||
@connect(mapStateToProps, mapDispatchToProps, mergeProps)
|
||||
export default class ScratchpadPretestTabPaneContainer extends React.PureComponent {
|
||||
render() {
|
||||
return (
|
||||
<div className="flex-row flex-fill">
|
||||
<DataInput
|
||||
title={i18n('Sample Input')}
|
||||
value={this.props.input}
|
||||
onChange={(v) => this.props.handleDataChange(this.props.id, 'input', v)}
|
||||
/>
|
||||
<DataInput
|
||||
title={i18n('Sample Output')}
|
||||
value={this.props.output}
|
||||
onChange={(v) => this.props.handleDataChange(this.props.id, 'output', v)}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,7 @@ const mapStateToProps = (state) => ({
|
||||
pretestVisible: state.ui.pretest.visible,
|
||||
recordsVisible: state.ui.records.visible,
|
||||
isPosting: state.ui.isPosting,
|
||||
isRunning: state.pretest.isRunning,
|
||||
editorLang: state.editor.lang,
|
||||
});
|
||||
|
||||
@@ -36,15 +37,11 @@ const mapDispatchToProps = (dispatch) => ({
|
||||
},
|
||||
postPretest(context) {
|
||||
const state = context.store.getState();
|
||||
const { pretest } = state;
|
||||
const testCases = pretest.tabs;
|
||||
const inputs = testCases.map((tabId) => pretest.data[tabId].input);
|
||||
const outputs = testCases.map((tabId) => pretest.data[tabId].output);
|
||||
const { input } = state.pretest;
|
||||
const req = request.post(Context.postPretestUrl, {
|
||||
lang: state.editor.lang,
|
||||
code: state.editor.code,
|
||||
data_input: inputs,
|
||||
data_output: outputs,
|
||||
input,
|
||||
});
|
||||
dispatch({
|
||||
type: 'SCRATCHPAD_POST_PRETEST',
|
||||
@@ -74,7 +71,7 @@ export default class ScratchpadToolbarContainer extends React.PureComponent {
|
||||
return (
|
||||
<Toolbar>
|
||||
<ToolbarButton
|
||||
disabled={this.props.isPosting || !this.props.pretestValid}
|
||||
disabled={this.props.isPosting || this.props.isRunning}
|
||||
className="scratchpad__toolbar__pretest"
|
||||
onClick={() => this.props.postPretest(this.context)}
|
||||
data-global-hotkey="f9"
|
||||
@@ -113,7 +110,7 @@ export default class ScratchpadToolbarContainer extends React.PureComponent {
|
||||
</ToolbarItem>
|
||||
<ToolbarSplit />
|
||||
<ToolbarButton
|
||||
activated
|
||||
activated={this.props.pretestVisible}
|
||||
onClick={() => this.props.togglePanel('pretest')}
|
||||
data-global-hotkey="alt+p"
|
||||
data-tooltip={`${i18n('Toggle Pretest Panel')} (Alt+P)`}
|
||||
|
||||
@@ -1,41 +1,30 @@
|
||||
import { v4 as uuid } from 'uuid';
|
||||
|
||||
const initialId = uuid();
|
||||
|
||||
export default function reducer(state = {
|
||||
counter: 1,
|
||||
current: initialId,
|
||||
tabs: [initialId],
|
||||
meta: {
|
||||
[initialId]: {
|
||||
id: initialId,
|
||||
title: '#1',
|
||||
},
|
||||
},
|
||||
data: {
|
||||
[initialId]: {
|
||||
id: initialId,
|
||||
title: '#1',
|
||||
input: '',
|
||||
output: '',
|
||||
},
|
||||
},
|
||||
input: '',
|
||||
output: '',
|
||||
rid: null,
|
||||
}, action) {
|
||||
switch (action.type) {
|
||||
case 'SCRATCHPAD_PRETEST_DATA_CHANGE': {
|
||||
const { id, type, value } = action.payload;
|
||||
if (action.type === 'SCRATCHPAD_PRETEST_DATA_CHANGE') {
|
||||
const { type, value } = action.payload;
|
||||
return {
|
||||
...state,
|
||||
data: {
|
||||
...state.data,
|
||||
[id]: {
|
||||
...state.data[id],
|
||||
[type]: value,
|
||||
},
|
||||
},
|
||||
[type]: value,
|
||||
};
|
||||
}
|
||||
default:
|
||||
return state;
|
||||
if (action.type === 'SCRATCHPAD_RECORDS_PUSH') {
|
||||
const { rdoc } = action.payload;
|
||||
if (rdoc._id === state.rid) {
|
||||
return {
|
||||
...state,
|
||||
output: (rdoc.stdout || '') + (rdoc.stderr || ''),
|
||||
rid: null,
|
||||
};
|
||||
}
|
||||
}
|
||||
if (action.type === 'SCRATCHPAD_POST_PRETEST_FULFILLED') {
|
||||
return {
|
||||
...state,
|
||||
rid: action.payload.rid,
|
||||
};
|
||||
}
|
||||
return state;
|
||||
}
|
||||
@@ -15,11 +15,6 @@ export default function reducer(state = {
|
||||
}
|
||||
case 'SCRATCHPAD_RECORDS_PUSH': {
|
||||
const { rdoc } = action.payload;
|
||||
if (rdoc.uid !== UserContext._id
|
||||
|| rdoc.pid !== Context.problemId
|
||||
) {
|
||||
return state;
|
||||
}
|
||||
return {
|
||||
...state,
|
||||
rows: [rdoc._id, ...state.rows],
|
||||
|
||||
Reference in new issue
Block a user