Skip to content

Commit

Permalink
Fix file loading
Browse files Browse the repository at this point in the history
  • Loading branch information
ondryaso committed Nov 3, 2024
1 parent 6b1abec commit 8ebbe65
Showing 1 changed file with 21 additions and 21 deletions.
42 changes: 21 additions & 21 deletions frontend/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -973,7 +973,7 @@ function makeFile() {
}
});
} // checked
function restoreFile() {
async function restoreFile() {
// Year
if (file.year) {
year = file.year;
Expand Down Expand Up @@ -1020,23 +1020,23 @@ function restoreFile() {
renderSubjects();
lastLoadedSubjects = [];
lessons = [];
loadLessons().then(function () {
// Lessons
$.each(file.custom, function (i, les) {
lessons.push(les);
});
$.each(file.selected, function (i, les) {
if (typeof lessons.find(x => x.id === les) != "undefined") {
lessons.find(x => x.id === les).selected = true;
}
});
$.each(file.deleted, function (i, les) {
if (typeof lessons.find(x => x.id === les) != "undefined") {
lessons.find(x => x.id === les).deleted = true;
}
});
renderAll();
await loadLessons();

// Lessons
$.each(file.custom, function (i, les) {
lessons.push(les);
});
$.each(file.selected, function (i, les) {
if (typeof lessons.find(x => x.id === les) != "undefined") {
lessons.find(x => x.id === les).selected = true;
}
});
$.each(file.deleted, function (i, les) {
if (typeof lessons.find(x => x.id === les) != "undefined") {
lessons.find(x => x.id === les).deleted = true;
}
});
renderAll();
} // checked

function downloadJSON() {
Expand Down Expand Up @@ -1073,10 +1073,10 @@ function loadJSON() {

var reader = new FileReader();
reader.readAsText($(".json_load_input")[0].files[0], "UTF-8");
reader.onload = function (e) {
reader.onload = async function (e) {
try {
file = JSON.parse(e.target.result);
restoreFile();
await restoreFile();
storeLocalStorage();
} catch (e) {
// Parse error
Expand Down Expand Up @@ -1182,15 +1182,15 @@ function storeLocalStorage() {
// Store
localStorage.setItem("schedule", JSON.stringify(file));
} // checked
function loadLocalStorage() {
async function loadLocalStorage() {
if (localStorage.getItem("schedule") != null) {
// Load
try {
file = JSON.parse(localStorage.getItem("schedule"));
} catch { }

// Restore
restoreFile();
await restoreFile();
}
} // checked

Expand Down

0 comments on commit 8ebbe65

Please sign in to comment.