fixed share link bug
This commit is contained in:
parent
db9eb00a6f
commit
63154d8e23
1 changed files with 25 additions and 3 deletions
28
index.html
28
index.html
|
|
@ -1333,10 +1333,13 @@
|
|||
onclick: () => exportSolve({token, n, solution: s, problem, maxTime,
|
||||
name: solveLabel(token, n)}),
|
||||
}, "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", {
|
||||
class: "mini", type: "button",
|
||||
onclick: () => applyProblem(problem, maxTime),
|
||||
onclick: () => loadParamsIntoForm(problem, maxTime, token),
|
||||
}, "Load parameters into form"));
|
||||
}
|
||||
out.append(actions);
|
||||
|
|
@ -1647,8 +1650,27 @@
|
|||
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
|
||||
// current inputs. Backs the "Load parameters into form" button.
|
||||
// current inputs.
|
||||
function applyProblem(problem, maxTime) {
|
||||
if (!problem) return;
|
||||
const setVal = (id, v) => {
|
||||
|
|
|
|||
Loading…
Reference in a new issue