diff --git a/packages/ui-default/locales/zh.yaml b/packages/ui-default/locales/zh.yaml index e27286206..5f9a70d02 100644 --- a/packages/ui-default/locales/zh.yaml +++ b/packages/ui-default/locales/zh.yaml @@ -84,6 +84,7 @@ Add User: 添加用户 Add: 添加 additional_file: 附加文件 All {0} Contests: 所有 {0} 比赛 +All changes will be lost. Are you sure to clear all answers?: 所有更改将会丢失。您确定要清除所有答案吗? All Contests: 所有比赛 All Homeworks: 所有作业 All Languages: 所有语言 @@ -161,6 +162,7 @@ Choose the background image in your profile page.: 选择您资料页面的背 Claim homework: 认领作业 Claim Homework: 认领作业 Claimed: 已认领 +Clear answers: 清除答案 Clear Marks: 清除标记 Click here to chat with me: 点击这里与我聊天 click to add: 点击添加 diff --git a/packages/ui-default/pages/problem_detail.page.jsx b/packages/ui-default/pages/problem_detail.page.jsx index 1816d650f..2d6c01be1 100644 --- a/packages/ui-default/pages/problem_detail.page.jsx +++ b/packages/ui-default/pages/problem_detail.page.jsx @@ -2,6 +2,7 @@ import $ from 'jquery'; import yaml from 'js-yaml'; import React from 'react'; import { createRoot } from 'react-dom/client'; +import { ConfirmDialog } from 'vj/components/dialog'; import Notification from 'vj/components/notification'; import { downloadProblemSet } from 'vj/components/zipDownloader'; 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)); setUpdate?.((i) => i + 1); } + function clearAns() { + localStorage.removeItem(`${cacheKey}#objective`); + window.location.reload(); + } function loadAns() { const saved = localStorage.getItem(`${cacheKey}#objective`); if (saved) { @@ -296,9 +301,20 @@ const page = new NamedPage(['problem_detail', 'contest_detail_problem', 'homewor Notification.error(err.message); }); }); + $('.section--problem-sidebar ol.menu').prepend(tpl(
  • + + {i18n('Clear answers')} + +
  • )); + $(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'); - $(ele).insertBefore($('.scratchpad--hide').get(0)); + $('.section--problem-sidebar ol.menu').prepend(ele); createRoot(ele).render(); $('.non-scratchpad--hide').hide(); $('.scratchpad--hide').hide();