ui: objective: add contestId for answer cache key

pull/566/merge
undefined 1 year ago
parent 0ae003eba3
commit bea82dbab5
No known key found for this signature in database

@ -229,6 +229,9 @@ const page = new NamedPage(['problem_detail', 'contest_detail_problem', 'homewor
} }
}); });
let cacheKey = `${UserContext._id}/${UiContext.pdoc.domainId}/${UiContext.pdoc.docId}`;
if (UiContext.tdoc?._id && UiContext.tdoc.rule !== 'homework') cacheKey += `@${UiContext.tdoc._id}`;
let setUpdate; let setUpdate;
function ProblemNavigation() { function ProblemNavigation() {
[, setUpdate] = React.useState(0); [, setUpdate] = React.useState(0);
@ -241,11 +244,11 @@ const page = new NamedPage(['problem_detail', 'contest_detail_problem', 'homewor
} }
function saveAns() { function saveAns() {
localStorage.setItem(`objective_${UiContext.domain._id}#${UiContext.pdoc.docId}`, JSON.stringify(ans)); localStorage.setItem(`${cacheKey}#objective`, JSON.stringify(ans));
setUpdate?.((i) => i + 1); setUpdate?.((i) => i + 1);
} }
function loadAns() { function loadAns() {
const saved = localStorage.getItem(`objective_${UiContext.domain._id}#${UiContext.pdoc.docId}`); const saved = localStorage.getItem(`${cacheKey}#objective`);
if (saved) { if (saved) {
Object.assign(ans, JSON.parse(saved)); Object.assign(ans, JSON.parse(saved));
for (const [id, val] of Object.entries(ans)) { for (const [id, val] of Object.entries(ans)) {

Loading…
Cancel
Save