fix done btn on edit
This commit is contained in:
@@ -226,14 +226,17 @@
|
||||
return;
|
||||
}
|
||||
|
||||
isSaving = true;
|
||||
hideConflict();
|
||||
setStatus("Saving");
|
||||
|
||||
if (!window.MDHubSync) {
|
||||
isSaving = false;
|
||||
setStatus("Queued");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
var result = await window.MDHubSync.saveDocument(path, value, baseHash);
|
||||
if (result.status === "saved") {
|
||||
lastSavedValue = value;
|
||||
@@ -245,15 +248,23 @@
|
||||
}
|
||||
}
|
||||
setStatus("Saved");
|
||||
isSaving = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if (result.status === "conflict") {
|
||||
showConflict(result.conflict, value);
|
||||
isSaving = false;
|
||||
return;
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
<p class="eyebrow">Editing</p>
|
||||
<h1>{{ .Title }}</h1>
|
||||
</div>
|
||||
<a class="document-edit-link" href="/docs/{{ trimMd .Path }}">Done</a>
|
||||
<a class="document-edit-link" href="/docs/{{ trimMd .Path }}" data-done-link>Done</a>
|
||||
</div>
|
||||
<details class="document-meta-panel">
|
||||
<summary>
|
||||
|
||||
Reference in New Issue
Block a user