Add saveFailCounter

Fix bug with not clearing noteId
Refactor a class removal and additions
Add script.min.js
This commit is contained in:
Ryan Prather 2024-06-09 20:26:54 -04:00
parent 4d55711190
commit c2c08db342
2 changed files with 17 additions and 8 deletions

View File

@ -8,6 +8,7 @@ let saveTimeout = 15000;
var to = null;
let controller;
var BOOKS = {};
let saveFailCounter = 0;
$(function () {
setHeight();
@ -160,6 +161,7 @@ function newNote() {
document.querySelector('#template').value = 0;
document.querySelector('#passage').value = '';
document.querySelector('#recording').value = '';
document.querySelector('#noteId').value = '';
document.querySelector('#ref-list').innerHTML = '';
document.querySelector('#ref').innerHTML = '';
@ -209,8 +211,7 @@ function saveNote(event) {
})
.done(function (data) {
if (data.msg == 'saved' && !saved) {
saveCheck.classList.remove('saving');
saveCheck.classList.remove('error');
saveCheck.classList.remove('saving', 'error', 'fa-times', 'fa-check');
showSave();
if (noteText == document.querySelector('#notes').value) {
saved = true;
@ -224,17 +225,22 @@ function saveNote(event) {
}
})
.fail(function (xhr, status, error) {
saveCheck.classList.remove('saving');
saveCheck.classList.add('error');
saveFailCounter++;
saveCheck.classList.remove('saving', 'fa-check');
saveCheck.classList.add('fa-times', 'error');
console.error(error);
})
.always(function (xhr, status) {
if (status == 'timeout') {
saveCheck.classList.remove('saving');
saveCheck.classList.add('error');
saveCheck.classList.remove('saving', 'fa-check');
saveCheck.classList.add('error', 'fa-times');
}
clearTimeout(to);
to = setTimeout(saveNote, saveTimeout);
if (saveFailCounter < 5) {
to = setTimeout(saveNote, saveTimeout);
} else {
saveFailCounter = 0;
}
});
}
@ -262,7 +268,8 @@ function isUuidValid(uuid) {
}
function startSave() {
document.querySelector('#save-check').classList.add('saving');
document.querySelector('#save-check').classList.remove('error', 'fa-times', 'fa-check');
document.querySelector('#save-check').classList.add('saving', 'fa-check');
document.querySelector('#save-check').style.opacity = 1;
}
@ -276,6 +283,7 @@ function showSave() {
if (saved) { return; }
var checkmark = document.getElementById("save-check");
checkmark.classList.add('fa-check');
// Schedule the animation to run every 1 second (which is equivalent to a 1-second delay between each iteration)
var si = setInterval(function () {

1
public/js/script.min.js vendored Normal file

File diff suppressed because one or more lines are too long