fuck you i aint commiting with actual messages
This commit is contained in:
parent
af461666f2
commit
2616417011
3 changed files with 49 additions and 10 deletions
|
|
@ -1,11 +1,19 @@
|
|||
const textarea = document.getElementById("editor");
|
||||
const status = document.getElementById("status");
|
||||
const error = document.getElementById("error");
|
||||
|
||||
fetch("/api/" + noteName)
|
||||
.then(res => res.ok ? res.text() : "")
|
||||
.then(res => {
|
||||
if (!res.ok) throw new Error("Failed to load note. Status: " + res.status);
|
||||
return res.text();
|
||||
})
|
||||
.then(text => {
|
||||
textarea.value = text;
|
||||
status.textContent = "Loaded";
|
||||
})
|
||||
.catch(err => {
|
||||
error.textContent = "Error loading note: " + err.message;
|
||||
status.textContent = "Load failed";
|
||||
});
|
||||
|
||||
let timeout;
|
||||
|
|
@ -21,17 +29,21 @@ textarea.addEventListener("input", () => {
|
|||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ content: text })
|
||||
}).then(res => {
|
||||
})
|
||||
.then(async res => {
|
||||
if (res.ok) {
|
||||
last = text;
|
||||
status.textContent = "Saved";
|
||||
} else {
|
||||
status.textContent = "Save failed";
|
||||
const msg = await res.text();
|
||||
status.textContent = "Save failed: " + msg;
|
||||
}
|
||||
})
|
||||
.catch(err => {
|
||||
status.textContent = "Save failed: " + err.message;
|
||||
});
|
||||
} else {
|
||||
status.textContent = "No changes";
|
||||
}
|
||||
}, 500);
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue