stability improvements

This commit is contained in:
maaa 2024-06-23 16:49:01 +02:00
parent 8fe7a59fe9
commit fe1d67b6e6
3 changed files with 80 additions and 13 deletions

View File

@ -40,7 +40,7 @@
<div class="vcenter"><img id="newNoteImage" draggable="false" alt="" src="/static/svg/delete.svg"></div> <div class="vcenter"><img id="newNoteImage" draggable="false" alt="" src="/static/svg/delete.svg"></div>
</button> </button>
<div id="notesDiv" class="notesDiv"> <div id="notesDiv" class="notesDiv">
<button class="loadingStuff" id="loadingStuff"></button> <button class="loadingStuff" id="loadingStuff">Meow :3</button>
</div> </div>
</div> </div>

View File

@ -294,10 +294,17 @@ body {
} }
.notesDiv { .notesDiv {
display: flex;
flex-direction: column;
height: calc(100% - 50px); height: calc(100% - 50px);
overflow-y: auto; overflow-y: auto;
} }
.notesDiv #r113 {
background-color: pink !important;
order: -1
}
.notesBar .noteButton, .notesBar .loadingStuff { .notesBar .noteButton, .notesBar .loadingStuff {
width: calc(100% - 7px - 3px); width: calc(100% - 7px - 3px);
height: 35px; height: 35px;

View File

@ -70,6 +70,7 @@ let timer
let waitTime = 400 let waitTime = 400
let indiv = false let indiv = false
let mobile = false let mobile = false
let selectLatestNote = false
if (/Android|iPhone|iPod/i.test(navigator.userAgent)) { if (/Android|iPhone|iPod/i.test(navigator.userAgent)) {
mobile = true mobile = true
@ -457,14 +458,20 @@ function selectNote(nameithink) {
renderMarkDown() renderMarkDown()
clearTimeout(timer); clearTimeout(timer);
timer = setTimeout(() => { timer = setTimeout(() => {
let encryptedTitle = "New note" let preEncryptedTitle = noteBox.value
if (noteBox.value.substring(0, noteBox.value.indexOf("\n")) !== "") {
let firstTitle = noteBox.value.substring(0, noteBox.value.indexOf("\n"));
document.getElementById(nameithink).innerText = firstTitle if (noteBox.value.substring(0, noteBox.value.indexOf("\n")) !== "") {
encryptedTitle = CryptoJS.AES.encrypt(firstTitle, password).toString(); preEncryptedTitle = noteBox.value.substring(0, noteBox.value.indexOf("\n"));
} }
preEncryptedTitle = truncateString(preEncryptedTitle, 15)
document.getElementById(nameithink).innerText = preEncryptedTitle
let encryptedText = CryptoJS.AES.encrypt(noteBox.value, password).toString(); let encryptedText = CryptoJS.AES.encrypt(noteBox.value, password).toString();
let encryptedTitle = CryptoJS.AES.encrypt(preEncryptedTitle, password).toString();
console.log(encryptedTitle)
console.log(encryptedText)
if (selectedNote === nameithink) { if (selectedNote === nameithink) {
fetch(remote + "/api/editnote", { fetch(remote + "/api/editnote", {
@ -496,6 +503,7 @@ function selectNote(nameithink) {
} }
function updateNotes() { function updateNotes() {
console.log("notes updated")
fetch(remote + "/api/listnotes", { fetch(remote + "/api/listnotes", {
method: "POST", method: "POST",
body: JSON.stringify({ body: JSON.stringify({
@ -507,26 +515,57 @@ function updateNotes() {
}) })
.then((response) => { .then((response) => {
async function doStuff() { async function doStuff() {
document.querySelectorAll(".noteButton").forEach((el) => el.remove());
noteBox.readOnly = true noteBox.readOnly = true
selectedNote = 0 selectedNote = 0
if (selectLatestNote == false) {
noteBox.placeholder = "" noteBox.placeholder = ""
}
noteBox.value = "" noteBox.value = ""
clearTimeout(timer) clearTimeout(timer)
updateWordCount() updateWordCount()
renderMarkDown() renderMarkDown()
let responseData = await response.json() let responseData = await response.json()
let decryptedResponseData = []
let highestID = 0
// First decrypt note data, then render
for (let i in responseData) { for (let i in responseData) {
noteData = responseData[i]
let bytes = CryptoJS.AES.decrypt(noteData["title"], password);
let decryptedTitle = bytes.toString(CryptoJS.enc.Utf8);
noteData["title"] = decryptedTitle
if (noteData["id"] > highestID) {
highestID = noteData["id"]
}
decryptedResponseData.push(noteData)
console.log(noteData)
}
document.querySelectorAll(".noteButton").forEach((el) => el.remove());
for (let i in decryptedResponseData) {
let noteData = decryptedResponseData[i]
let noteButton = document.createElement("button"); let noteButton = document.createElement("button");
noteButton.classList.add("noteButton") noteButton.classList.add("noteButton")
notesDiv.append(noteButton) notesDiv.append(noteButton)
let bytes = CryptoJS.AES.decrypt(responseData[i]["title"], password); console.log(noteData["title"])
let originalTitle = bytes.toString(CryptoJS.enc.Utf8);
noteButton.id = responseData[i]["id"] if (noteData["title"] == "") {
noteButton.innerText = truncateString(originalTitle, 15) console.log(noteData["title"])
console.log("case")
noteData["title"] = "New note"
}
noteButton.id = noteData["id"]
noteButton.innerText = truncateString(noteData["title"], 15)
noteButton.addEventListener("click", (event) => { noteButton.addEventListener("click", (event) => {
if (event.ctrlKey) { if (event.ctrlKey) {
@ -534,7 +573,7 @@ function updateNotes() {
method: "POST", method: "POST",
body: JSON.stringify({ body: JSON.stringify({
secretKey: secretkey, secretKey: secretkey,
noteId: responseData[i]["id"] noteId: noteData["id"]
}), }),
headers: { headers: {
"Content-Type": "application/json; charset=UTF-8" "Content-Type": "application/json; charset=UTF-8"
@ -547,11 +586,16 @@ function updateNotes() {
displayError("Something went wrong! Please try again later...") displayError("Something went wrong! Please try again later...")
}) })
} else { } else {
selectNote(responseData[i]["id"]) selectNote(noteData["id"])
} }
}); });
} }
document.querySelectorAll(".loadingStuff").forEach((el) => el.remove()); document.querySelectorAll(".loadingStuff").forEach((el) => el.remove());
if (selectLatestNote == true) {
selectNote(highestID)
selectLatestNote = false
}
} }
doStuff() doStuff()
}); });
@ -561,7 +605,22 @@ updateNotes()
newNote.addEventListener("click", () => { newNote.addEventListener("click", () => {
let noteName = "New note" let noteName = "New note"
selectLatestNote = true
console.log(selectLatestNote)
// create fake item
document.querySelectorAll(".noteButton").forEach((el) => el.classList.remove("selected"));
let noteButton = document.createElement("button");
noteButton.classList.add("noteButton")
notesDiv.append(noteButton)
noteButton.innerText = "New note"
noteButton.style.order = -1
noteButton.classList.add("selected")
noteBox.placeholder = "Type something!"
let encryptedName = CryptoJS.AES.encrypt(noteName, password).toString(CryptoJS.enc.Utf8); let encryptedName = CryptoJS.AES.encrypt(noteName, password).toString(CryptoJS.enc.Utf8);
fetch(remote + "/api/newnote", { fetch(remote + "/api/newnote", {
method: "POST", method: "POST",
body: JSON.stringify({ body: JSON.stringify({
@ -713,6 +772,7 @@ removeBox.addEventListener("click", () => {
if (selectedNote === 0) { if (selectedNote === 0) {
displayError("You need to select a note first!") displayError("You need to select a note first!")
} else { } else {
selectLatestNote = true
fetch(remote + "/api/removenote", { fetch(remote + "/api/removenote", {
method: "POST", method: "POST",
body: JSON.stringify({ body: JSON.stringify({