feat: enhance sync functionality with unsynced answer detection and UI updates

This commit is contained in:
Ross
2026-06-29 11:49:45 +01:00
parent 499707f946
commit 253b0bc183
2 changed files with 22 additions and 3 deletions
+20 -2
View File
@@ -119,8 +119,26 @@ export function initSync(exam_details, URLS) {
clearInterval(syncInterval);
}
// Set initial state
updateSyncUI("saved");
// Check if there are unsynced answers at startup
db.answers
.where({
aid: exam_details.aid,
cid: exam_details.cid,
eid: exam_details.eid,
})
.filter(ans => ans.synced === false)
.toArray()
.then(unsynced => {
if (unsynced && unsynced.length > 0) {
updateSyncUI("failed"); // Unsynced answers exist; they aren't accepted by server yet
performSync(exam_details, URLS);
} else {
updateSyncUI("saved");
}
})
.catch(() => {
updateSyncUI("saved");
});
// Run periodic sync every 15 seconds
syncInterval = setInterval(() => {