Skip to content

Commit

Permalink
Set selectedArchive only when actually ready
Browse files Browse the repository at this point in the history
  • Loading branch information
Jaifroid committed Oct 17, 2023
1 parent 837c757 commit 6262e25
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions www/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -1232,11 +1232,8 @@ function setLocalArchiveFromArchiveList () {
}
}
resetCssCache();
selectedArchive = zimArchiveLoader.loadArchiveFromDeviceStorage(selectedStorage, archiveDirectory, function () {
settingsStore.setItem('lastSelectedArchive', archiveDirectory, Infinity);
// The archive is set : go back to home page to start searching
document.getElementById('btnHome').click();
}, function (message, label) {
settingsStore.setItem('lastSelectedArchive', archiveDirectory, Infinity);
zimArchiveLoader.loadArchiveFromDeviceStorage(selectedStorage, archiveDirectory, archiveReadyCallback, function (message, label) {
// callbackError which is called in case of an error
uiUtil.systemAlert(message, label);
});
Expand Down Expand Up @@ -1339,17 +1336,24 @@ function setLocalArchiveFromFileList (files) {
}
}
resetCssCache();
selectedArchive = null;
selectedArchive = zimArchiveLoader.loadArchiveFromFiles(files, function () {
// The archive is set : go back to home page to start searching
document.getElementById('btnHome').click();
document.getElementById('downloadInstruction').style.display = 'none';
}, function (message, label) {
zimArchiveLoader.loadArchiveFromFiles(files, archiveReadyCallback, function (message, label) {
// callbackError which is called in case of an error
uiUtil.systemAlert(message, label);
});
}

/**
* Functions to be run immediately after the archive is loaded
*
* @param {ZIMArchive} archive The ZIM archive
*/
function archiveReadyCallback (archive) {
selectedArchive = archive;
// The archive is set: go back to home page to start searching
document.getElementById('btnHome').click();
document.getElementById('downloadInstruction').style.display = 'none';
}

/**
* Sets the localArchive from the File selects populated by user
*/
Expand Down

0 comments on commit 6262e25

Please sign in to comment.