ui: problem_detail: add clear answers button

This commit is contained in:
undefined committed 2024-05-19 18:36:56 +08:00
1 parent 048cfe1c01
commit a8e71c4397
2 files changed
+19 -1

No files matched your search

+2
View File
@@ -84,6 +84,7 @@ Add User: 添加用户
Add: 添加 Add: 添加
additional_file: 附加文件 additional_file: 附加文件
All {0} Contests: 所有 {0} 比赛 All {0} Contests: 所有 {0} 比赛
All changes will be lost. Are you sure to clear all answers?: 所有更改将会丢失。您确定要清除所有答案吗?
All Contests: 所有比赛 All Contests: 所有比赛
All Homeworks: 所有作业 All Homeworks: 所有作业
All Languages: 所有语言 All Languages: 所有语言
@@ -161,6 +162,7 @@ Choose the background image in your profile page.: 选择您资料页面的背
Claim homework: 认领作业 Claim homework: 认领作业
Claim Homework: 认领作业 Claim Homework: 认领作业
Claimed: 已认领 Claimed: 已认领
Clear answers: 清除答案
Clear Marks: 清除标记 Clear Marks: 清除标记
Click here to chat with me: 点击这里与我聊天 Click here to chat with me: 点击这里与我聊天
click to add: 点击添加 click to add: 点击添加
@@ -2,6 +2,7 @@ import $ from 'jquery';
import yaml from 'js-yaml'; import yaml from 'js-yaml';
import React from 'react'; import React from 'react';
import { createRoot } from 'react-dom/client'; import { createRoot } from 'react-dom/client';
import { ConfirmDialog } from 'vj/components/dialog';
import Notification from 'vj/components/notification'; import Notification from 'vj/components/notification';
import { downloadProblemSet } from 'vj/components/zipDownloader'; import { downloadProblemSet } from 'vj/components/zipDownloader';
import { NamedPage } from 'vj/misc/Page'; import { NamedPage } from 'vj/misc/Page';
@@ -246,6 +247,10 @@ const page = new NamedPage(['problem_detail', 'contest_detail_problem', 'homewor
localStorage.setItem(`${cacheKey}#objective`, JSON.stringify(ans)); localStorage.setItem(`${cacheKey}#objective`, JSON.stringify(ans));
setUpdate?.((i) => i + 1); setUpdate?.((i) => i + 1);
} }
function clearAns() {
localStorage.removeItem(`${cacheKey}#objective`);
window.location.reload();
}
function loadAns() { function loadAns() {
const saved = localStorage.getItem(`${cacheKey}#objective`); const saved = localStorage.getItem(`${cacheKey}#objective`);
if (saved) { if (saved) {
@@ -296,9 +301,20 @@ const page = new NamedPage(['problem_detail', 'contest_detail_problem', 'homewor
Notification.error(err.message); Notification.error(err.message);
}); });
}); });
$('.section--problem-sidebar ol.menu').prepend(tpl(<li className="menu__item" id="clearAnswers">
<a className="menu__link" href="javascript:;">
<span className="icon icon-erase" /> {i18n('Clear answers')}
</a>
</li>));
$(document).on('click', '#clearAnswers', async () => {
const result = await new ConfirmDialog({
$body: tpl.typoMsg('All changes will be lost. Are you sure to clear all answers?'),
}).open();
if (result === 'yes') clearAns();
});
} }
const ele = document.createElement('div'); const ele = document.createElement('div');
$(ele).insertBefore($('.scratchpad--hide').get(0)); $('.section--problem-sidebar ol.menu').prepend(ele);
createRoot(ele).render(<ProblemNavigation />); createRoot(ele).render(<ProblemNavigation />);
$('.non-scratchpad--hide').hide(); $('.non-scratchpad--hide').hide();
$('.scratchpad--hide').hide(); $('.scratchpad--hide').hide();