mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
ui: objective: add contestId for answer cache key
This commit is contained in:
1 file changed
+5
-2
@@ -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)) {
|
||||||
|
|||||||
Reference in new issue
Block a user