fixed share link bug

This commit is contained in:
Pagwin 2026-06-20 22:18:39 -04:00
parent db9eb00a6f
commit 63154d8e23

View file

@ -1333,10 +1333,13 @@
onclick: () => exportSolve({token, n, solution: s, problem, maxTime, onclick: () => exportSolve({token, n, solution: s, problem, maxTime,
name: solveLabel(token, n)}), name: solveLabel(token, n)}),
}, "Export")); }, "Export"));
if (problem) { // The problem may be on hand (a solve queued from this tab) or, for a
// solve opened via a share link, fetched from the server by token on
// click — the same lazy lookup exportSolve uses.
if (problem || token) {
actions.append(" ", el("button", { actions.append(" ", el("button", {
class: "mini", type: "button", class: "mini", type: "button",
onclick: () => applyProblem(problem, maxTime), onclick: () => loadParamsIntoForm(problem, maxTime, token),
}, "Load parameters into form")); }, "Load parameters into form"));
} }
out.append(actions); out.append(actions);
@ -1647,8 +1650,27 @@
reader.readAsText(file); reader.readAsText(file);
} }
// Backs the "Load parameters into form" button. Uses the problem we
// already hold for a locally-queued solve, otherwise fetches it from the
// server by token (a share-link viewer never had it locally).
async function loadParamsIntoForm(problem, maxTime, token) {
let prob = problem, mt = maxTime;
if (!prob && token) {
try {
const r = await fetch("/solve/" + encodeURIComponent(token));
if (r.ok) prob = (await r.json()).problem;
} catch (e) {/* fall through: nothing to load */}
}
if (!prob) {
document.getElementById("error").textContent =
"Could not load this solve's parameters (it may have been evicted).";
return;
}
applyProblem(prob, mt);
}
// Load a problem's input parameters back into the form, replacing the // Load a problem's input parameters back into the form, replacing the
// current inputs. Backs the "Load parameters into form" button. // current inputs.
function applyProblem(problem, maxTime) { function applyProblem(problem, maxTime) {
if (!problem) return; if (!problem) return;
const setVal = (id, v) => { const setVal = (id, v) => {