fix done btn on edit

This commit is contained in:
2026-06-09 21:06:26 -04:00
parent 6c30fd8b63
commit 6f646c2505
2 changed files with 105 additions and 17 deletions

View File

@@ -226,34 +226,45 @@
return;
}
isSaving = true;
hideConflict();
setStatus("Saving");
if (!window.MDHubSync) {
isSaving = false;
setStatus("Queued");
return;
}
var result = await window.MDHubSync.saveDocument(path, value, baseHash);
if (result.status === "saved") {
lastSavedValue = value;
if (hashEl && result.result && result.result.hash) {
hashEl.textContent = result.result.hash;
baseHash = result.result.hash;
if (documentShell) {
documentShell.setAttribute("data-document-hash", result.result.hash);
try {
var result = await window.MDHubSync.saveDocument(path, value, baseHash);
if (result.status === "saved") {
lastSavedValue = value;
if (hashEl && result.result && result.result.hash) {
hashEl.textContent = result.result.hash;
baseHash = result.result.hash;
if (documentShell) {
documentShell.setAttribute("data-document-hash", result.result.hash);
}
}
setStatus("Saved");
isSaving = false;
return;
}
setStatus("Saved");
return;
}
if (result.status === "conflict") {
showConflict(result.conflict, value);
return;
}
if (result.status === "conflict") {
showConflict(result.conflict, value);
isSaving = false;
return;
}
setStatus("Queued");
setStatus("Queued");
} catch (err) {
setStatus("Queued");
throw err;
} finally {
isSaving = false;
}
}
async function applyResolvedConflict() {
@@ -571,6 +582,83 @@
restorePendingConflict();
var doneLink = document.querySelector("[data-done-link]");
var isSaving = false;
if (doneLink) {
doneLink.addEventListener("click", function (event) {
var currentValue = getEditorValue();
var href = doneLink.getAttribute("href");
// If there's an unresolved conflict, warn the user
if (currentConflict) {
event.preventDefault();
setStatus("Conflict");
if (conflictNotice) {
conflictNotice.scrollIntoView({ behavior: "smooth", block: "center" });
}
return;
}
// If nothing changed, allow normal navigation
if (currentValue === lastSavedValue) {
return;
}
// Unsaved changes — cancel any pending timer and save immediately
event.preventDefault();
if (saveTimer) {
clearTimeout(saveTimer);
saveTimer = null;
}
if (isSaving) {
// Already saving, just wait and then navigate
waitForSaveThenNavigate(href);
return;
}
isSaving = true;
setStatus("Saving");
saveNow()
.then(function () {
isSaving = false;
window.location.href = href;
})
.catch(function () {
isSaving = false;
setStatus("Queued");
// If save fails, ask user if they want to leave anyway
if (window.confirm("Could not save. Leave without saving?")) {
window.location.href = href;
}
});
});
}
function waitForSaveThenNavigate(href) {
var checkInterval = setInterval(function () {
if (!isSaving) {
clearInterval(checkInterval);
window.location.href = href;
}
}, 100);
// Timeout after 10 seconds
setTimeout(function () {
clearInterval(checkInterval);
}, 10000);
}
// Warn on browser unload if there are unsaved changes
window.addEventListener("beforeunload", function (e) {
if (getEditorValue() !== lastSavedValue || currentConflict) {
e.preventDefault();
e.returnValue = "";
}
});
document.addEventListener("keydown", function (e) {
if ((e.metaKey || e.ctrlKey) && e.key === "s") {
e.preventDefault();