forked from hydro-dev/Hydro
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproblem_submit.page.tsx
More file actions
57 lines (52 loc) · 2.25 KB
/
Copy pathproblem_submit.page.tsx
File metadata and controls
57 lines (52 loc) · 2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import $ from 'jquery';
import React from 'react';
import ReactDOM from 'react-dom/client';
import { renderLanguageSelect } from 'vj/components/languageselect';
import { NamedPage } from 'vj/misc/Page';
import { getAvailableLangs, i18n, tpl } from 'vj/utils';
const page = new NamedPage(['problem_submit', 'contest_detail_problem_submit', 'homework_detail_problem_submit'], async () => {
const { config } = UiContext.pdoc;
if (config.type === 'submit_answer') {
$('[name="lang"]').val('_');
return;
}
const availableLangs = getAvailableLangs(UiContext.submitableLangs);
const mainLangs = {};
const preferences = [UserContext.codeLang || ''];
for (const key in availableLangs) {
if (config.langs && !config.langs.filter((i) => i === key || i.startsWith(`${key}.`)).length) continue;
if (window.LANGS[key].pretest === preferences[0]) preferences.push(key);
if (!key.includes('.')) mainLangs[key] = window.LANGS[key].display;
else {
const a = key.split('.')[0];
mainLangs[a] = window.LANGS[a].display;
}
}
for (const key in availableLangs) {
if (config.langs && !config.langs.filter((i) => i === key || i.startsWith(`${key}.`)).length) continue;
if (typeof window.LANGS[key]?.pretest === 'string' && window.LANGS[key].pretest.split('.')[0] === preferences[0].split('.')[0]) {
preferences.push(key);
}
}
renderLanguageSelect(
document.getElementById('codelang-selector'),
'[name="lang"]',
availableLangs,
mainLangs,
preferences,
);
if (localStorage.getItem('submit-hint') === 'dismiss') return;
$(tpl`<div name="hint" class="typo"></div>`).prependTo('[name="submit_section"]');
const root = ReactDOM.createRoot(document.querySelector('[name="hint"]'));
function ignore() {
root.unmount();
localStorage.setItem('submit-hint', 'dismiss');
}
root.render(<blockquote className="note">
<p>{i18n('This page is only for pasting code from other sources.')}</p>
<p>{i18n("To get a better editing experience, with code highlighting and test runs, \
please go back to the problem detail page and use 'Open Scratchpad' button.")}</p>
<a onClick={() => root.unmount()}>{i18n('Dismiss')}</a> / <a onClick={ignore}>{i18n("Don't show again")}</a>
</blockquote>);
});
export default page;