mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
ui: enhance scratchpad language select
This commit is contained in:
1 parent
3034f5ec79
commit
ae7857a79c
5 files changed
+43
-31
No files matched your search
@@ -42,7 +42,7 @@ const messagePage = new AutoloadPage('messagePage', (pagename) => {
|
||||
}).open();
|
||||
} else if (msg.udoc._id === 1 && msg.mdoc.flag & 4) {
|
||||
new VjNotification({
|
||||
message: 'You received a system message, click here to view.',
|
||||
message: i18n('You received a system message, click here to view.'),
|
||||
duration: 15000,
|
||||
action: () => window.open(`/home/messages?uid=${msg.udoc._id}`, '_blank'),
|
||||
}).show();
|
||||
|
||||
@@ -46,6 +46,8 @@ export default connect(mapStateToProps, mapDispatchToProps)(class MonacoEditor e
|
||||
}
|
||||
}),
|
||||
);
|
||||
window.editor = this.editor;
|
||||
window.monaco = monaco;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,8 +74,11 @@ export default connect(mapStateToProps, mapDispatchToProps)(class MonacoEditor e
|
||||
const { load } = await import('vj/components/monaco/loader');
|
||||
const { monaco } = await load([language]);
|
||||
if (prevProps.language !== language) {
|
||||
monaco.editor.setModelLanguage(model, language);
|
||||
editor.updateOptions({ mode: language });
|
||||
const val = model.getValue();
|
||||
model.dispose();
|
||||
const uri = monaco.Uri.parse(`hydro://${UiContext.pdoc.pid || UiContext.pdoc.docId}.${language}`);
|
||||
this.model = monaco.editor.createModel(val, language, uri);
|
||||
editor.setModel(this.model);
|
||||
}
|
||||
if (editor) {
|
||||
if (prevProps.mainSize !== mainSize
|
||||
|
||||
@@ -66,27 +66,36 @@ const mapDispatchToProps = (dispatch) => ({
|
||||
},
|
||||
});
|
||||
|
||||
const LANGS = {};
|
||||
const prefix = new Set(Object.keys(window.LANGS).filter((i) => i.includes('.')).map((i) => i.split('.')[0]));
|
||||
const domainId = UiContext.pdoc.reference?.domainId || UiContext.pdoc.domainId;
|
||||
for (const key in window.LANGS) {
|
||||
if (prefix.has(key)) continue;
|
||||
if (UiContext.pdoc.config.langs && !UiContext.pdoc.config.langs.includes(key)) continue;
|
||||
if (window.LANGS[key].domain && !window.LANGS[key].domain.includes(domainId)) continue;
|
||||
LANGS[key] = window.LANGS[key];
|
||||
}
|
||||
const keys = Object.keys(LANGS);
|
||||
|
||||
export default connect(mapStateToProps, mapDispatchToProps)(class ScratchpadToolbarContainer extends React.PureComponent {
|
||||
static contextTypes = {
|
||||
store: PropTypes.object,
|
||||
};
|
||||
|
||||
constructor(props) {
|
||||
super(props);
|
||||
if (!LANGS[this.props.editorLang]) {
|
||||
// preference not allowed
|
||||
const key = keys.find((i) => LANGS[i].pretest === this.props.editorLang);
|
||||
this.props.setEditorLanguage(key || Object.keys(LANGS)[0]);
|
||||
}
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
if (this.props.recordsVisible) this.props.loadSubmissions();
|
||||
}
|
||||
|
||||
render() {
|
||||
const LANGS = {};
|
||||
const prefix = new Set(Object.keys(window.LANGS).filter((i) => i.includes('.')).map((i) => i.split('.')[0]));
|
||||
const domainId = UiContext.pdoc.reference?.domainId || UiContext.pdoc.domainId;
|
||||
for (const key in window.LANGS) {
|
||||
if (prefix.has(key)) continue;
|
||||
if (UiContext.pdoc.config.langs && !UiContext.pdoc.config.langs.includes(key)) continue;
|
||||
if (window.LANGS[key].domain && !window.LANGS[key].domain.includes(domainId)) continue;
|
||||
LANGS[key] = window.LANGS[key];
|
||||
}
|
||||
const keys = Object.keys(LANGS);
|
||||
if (!keys.includes(this.props.editorLang)) this.props.setEditorLanguage(keys[0]);
|
||||
let canUsePretest = ['default', 'fileio'].includes(UiContext.pdoc.config?.type);
|
||||
if (UiContext.pdoc.config?.type === 'remote_judge') {
|
||||
if (window.LANGS[this.props.editorLang].pretest) canUsePretest = true;
|
||||
|
||||
@@ -2,24 +2,22 @@ let cacheKey = `${UserContext._id}/${UiContext.pdoc.domainId}/${UiContext.pdoc.d
|
||||
if (UiContext.tdoc?._id && UiContext.tdoc.rule !== 'homework') cacheKey += `@${UiContext.tdoc._id}`;
|
||||
|
||||
export default function reducer(state = {
|
||||
lang: UiContext.codeLang,
|
||||
lang: localStorage.getItem(`${cacheKey}#lang`) || UiContext.codeLang,
|
||||
code: localStorage.getItem(cacheKey) || UiContext.codeTemplate,
|
||||
}, action) {
|
||||
switch (action.type) {
|
||||
case 'SCRATCHPAD_EDITOR_UPDATE_CODE': {
|
||||
if (action.type === 'SCRATCHPAD_EDITOR_UPDATE_CODE') {
|
||||
localStorage.setItem(cacheKey, action.payload);
|
||||
return {
|
||||
...state,
|
||||
code: action.payload,
|
||||
};
|
||||
}
|
||||
case 'SCRATCHPAD_EDITOR_SET_LANG': {
|
||||
if (action.type === 'SCRATCHPAD_EDITOR_SET_LANG') {
|
||||
localStorage.setItem(`${cacheKey}#lang`, action.payload);
|
||||
return {
|
||||
...state,
|
||||
lang: action.payload,
|
||||
};
|
||||
}
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
return state;
|
||||
}
|
||||
Reference in new issue
Block a user