Keep transfer settings sub-tab after embed soft-reload of manual transfer.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -235,9 +235,57 @@
|
|||||||
const parts = [];
|
const parts = [];
|
||||||
if (qs) parts.push(qs);
|
if (qs) parts.push(qs);
|
||||||
parts.push("embed=1");
|
parts.push("embed=1");
|
||||||
|
if (tab === "settings") {
|
||||||
|
try {
|
||||||
|
const st = new URLSearchParams(location.search).get("settings_tab");
|
||||||
|
if (st) parts.push("settings_tab=" + encodeURIComponent(st));
|
||||||
|
} catch (_) {}
|
||||||
|
}
|
||||||
return url + "?" + parts.join("&");
|
return url + "?" + parts.join("&");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function setSettingsSubTabInUrl(key) {
|
||||||
|
if (!key) return;
|
||||||
|
try {
|
||||||
|
const q = new URLSearchParams(location.search);
|
||||||
|
q.set("tab", "settings");
|
||||||
|
q.set("settings_tab", key);
|
||||||
|
q.set("embed", "1");
|
||||||
|
history.replaceState(null, "", "/embed?" + q.toString());
|
||||||
|
} catch (_) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
function activateSettingsSubTab(key) {
|
||||||
|
if (!key) return;
|
||||||
|
setSettingsSubTabInUrl(key);
|
||||||
|
const pane = tabPanes.get("settings") || document;
|
||||||
|
const radio = pane.querySelector(
|
||||||
|
'input.env-tab-radio[data-settings-tab="' + key + '"]'
|
||||||
|
);
|
||||||
|
if (radio) radio.checked = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function formActionPath(form) {
|
||||||
|
try {
|
||||||
|
return new URL(form.action || "", location.href).pathname.replace(/\/$/, "") || "/";
|
||||||
|
} catch (_) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function maybeKeepSettingsSubTabAfterForm(form) {
|
||||||
|
const path = formActionPath(form);
|
||||||
|
if (path === "/manual_transfer") {
|
||||||
|
setSettingsSubTabInUrl("transfer");
|
||||||
|
return "transfer";
|
||||||
|
}
|
||||||
|
if (path.indexOf("/api/options/transfer") >= 0 || path.indexOf("/api/options/cross-transfer") >= 0) {
|
||||||
|
setSettingsSubTabInUrl("options_transfer");
|
||||||
|
return "options_transfer";
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
async function fetchTabHtml(tab) {
|
async function fetchTabHtml(tab) {
|
||||||
const r = await fetch(embedPageUrl(tab), {
|
const r = await fetch(embedPageUrl(tab), {
|
||||||
credentials: "same-origin",
|
credentials: "same-origin",
|
||||||
@@ -400,14 +448,15 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
const fd = new FormData(form);
|
const fd = new FormData(form);
|
||||||
|
const keepSub = maybeKeepSettingsSubTabAfterForm(form);
|
||||||
return fetch(form.action, {
|
return fetch(form.action, {
|
||||||
method: form.method || "POST",
|
method: form.method || "POST",
|
||||||
body: fd,
|
body: fd,
|
||||||
credentials: "same-origin",
|
credentials: "same-origin",
|
||||||
redirect: "manual",
|
redirect: "manual",
|
||||||
})
|
})
|
||||||
.then(() => reloadCurrentTab())
|
.then(() => reloadCurrentTab().then(() => activateSettingsSubTab(keepSub)))
|
||||||
.catch(() => reloadCurrentTab());
|
.catch(() => reloadCurrentTab().then(() => activateSettingsSubTab(keepSub)));
|
||||||
}
|
}
|
||||||
|
|
||||||
function patchApplyListWindow() {
|
function patchApplyListWindow() {
|
||||||
@@ -466,14 +515,15 @@
|
|||||||
if (CUSTOM_SUBMIT_FORM_IDS.has(form.id)) return;
|
if (CUSTOM_SUBMIT_FORM_IDS.has(form.id)) return;
|
||||||
ev.preventDefault();
|
ev.preventDefault();
|
||||||
const fd = new FormData(form);
|
const fd = new FormData(form);
|
||||||
|
const keepSub = maybeKeepSettingsSubTabAfterForm(form);
|
||||||
fetch(form.action, {
|
fetch(form.action, {
|
||||||
method: form.method || "POST",
|
method: form.method || "POST",
|
||||||
body: fd,
|
body: fd,
|
||||||
credentials: "same-origin",
|
credentials: "same-origin",
|
||||||
redirect: "manual",
|
redirect: "manual",
|
||||||
})
|
})
|
||||||
.then(() => reloadCurrentTab())
|
.then(() => reloadCurrentTab().then(() => activateSettingsSubTab(keepSub)))
|
||||||
.catch(() => reloadCurrentTab());
|
.catch(() => reloadCurrentTab().then(() => activateSettingsSubTab(keepSub)));
|
||||||
},
|
},
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -120,6 +120,6 @@ window.__INSTANCE_DISPLAY__ = {{ display | tojson }};
|
|||||||
</script>
|
</script>
|
||||||
<script src="/static/instance_settings_prefs.js?v=15"></script>
|
<script src="/static/instance_settings_prefs.js?v=15"></script>
|
||||||
<script src="/static/instance_live.js?v=6"></script>
|
<script src="/static/instance_live.js?v=6"></script>
|
||||||
<script src="/static/instance_embed.js?v=27"></script>
|
<script src="/static/instance_embed.js?v=28"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
Reference in New Issue
Block a user