Skip to content

Commit a935f95

Browse files
committed
Download content pack even when there is content
Change the assumption for showing the welcome screens: before, when there was content in the database it was assumed to be already downloaded and the download was skipped. Now rely on the presence of a DOWNLOAD_COMPLETED state persisted. Fix #863
1 parent 637be03 commit a935f95

1 file changed

Lines changed: 27 additions & 31 deletions

File tree

  • kolibri_explore_plugin/assets/src/modules/topicsRoot

kolibri_explore_plugin/assets/src/modules/topicsRoot/handlers.js

Lines changed: 27 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,10 @@ function _fetchCarouselNodes(store) {
128128
);
129129
}
130130

131+
function _isDownloadComplete(status) {
132+
return status.stage === 'COMPLETED';
133+
}
134+
131135
function _isDownloadOngoing(status) {
132136
return status.stage !== 'COMPLETED' && status.stage !== 'NOT_STARTED';
133137
}
@@ -145,29 +149,25 @@ export function decideWelcome(store) {
145149

146150
return Promise.all([getDownloadStatus(), getShouldResume()]).then(
147151
([status, { shouldResume, grade, name }]) => {
148-
if (_isDownloadOngoing(status) || shouldResume) {
152+
if (_isDownloadComplete(status)) {
153+
store.commit('CORE_SET_PAGE_LOADING', false);
154+
store.commit('CORE_SET_ERROR', null);
155+
console.debug('Welcome: Download complete, redirecting to Explore page...');
156+
router.replace({ name: PageNames.TOPICS_ROOT });
157+
} else if (_isDownloadOngoing(status) || shouldResume) {
149158
console.debug('Welcome: Redirecting to Download page...');
150159
// The catch here is needed for ignoring redundant navigation errors.
151160
router.replace({ name: PageNames.DOWNLOAD, params: { grade, name } }).catch(() => {});
152161
store.commit('SET_PAGE_NAME', PageNames.DOWNLOAD);
153162
store.commit('CORE_SET_PAGE_LOADING', false);
154163
store.commit('CORE_SET_ERROR', null);
155164
} else {
156-
return store.dispatch('setAndCheckChannels').then(channels => {
157-
if (!channels.length) {
158-
console.debug('Welcome: Redirecting to Welcome page...');
159-
// The catch here is needed for ignoring redundant navigation errors.
160-
router.replace({ name: PageNames.WELCOME_ROOT }).catch(() => {});
161-
store.commit('SET_PAGE_NAME', PageNames.WELCOME_ROOT);
162-
store.commit('CORE_SET_PAGE_LOADING', false);
163-
store.commit('CORE_SET_ERROR', null);
164-
} else {
165-
store.commit('CORE_SET_PAGE_LOADING', false);
166-
store.commit('CORE_SET_ERROR', null);
167-
console.debug('Welcome: Redirecting to Explore page...');
168-
router.replace({ name: PageNames.TOPICS_ROOT });
169-
}
170-
});
165+
console.debug('Welcome: Redirecting to Welcome page...');
166+
// The catch here is needed for ignoring redundant navigation errors.
167+
router.replace({ name: PageNames.WELCOME_ROOT }).catch(() => {});
168+
store.commit('SET_PAGE_NAME', PageNames.WELCOME_ROOT);
169+
store.commit('CORE_SET_PAGE_LOADING', false);
170+
store.commit('CORE_SET_ERROR', null);
171171
}
172172
}
173173
);
@@ -192,7 +192,12 @@ export function decideDownload(store, grade, name) {
192192

193193
return Promise.all([getDownloadStatus(), getShouldResume()]).then(
194194
([status, { shouldResume }]) => {
195-
if (_isDownloadOngoing(status)) {
195+
if (_isDownloadComplete(status)) {
196+
console.debug('Already downloaded, redirecting to Explore page...');
197+
store.commit('CORE_SET_PAGE_LOADING', false);
198+
store.commit('CORE_SET_ERROR', null);
199+
router.replace({ name: PageNames.TOPICS_ROOT });
200+
} else if (_isDownloadOngoing(status)) {
196201
console.debug('A collections download is ongoing...');
197202
store.commit('SET_PAGE_NAME', PageNames.DOWNLOAD);
198203
store.commit('CORE_SET_PAGE_LOADING', false);
@@ -205,20 +210,11 @@ export function decideDownload(store, grade, name) {
205210
store.commit('CORE_SET_ERROR', null);
206211
});
207212
} else {
208-
return store.dispatch('setAndCheckChannels').then(channels => {
209-
if (!channels.length) {
210-
console.debug('Downloading starter pack...');
211-
return startDownload(grade, name).then(() => {
212-
store.commit('SET_PAGE_NAME', PageNames.DOWNLOAD);
213-
store.commit('CORE_SET_PAGE_LOADING', false);
214-
store.commit('CORE_SET_ERROR', null);
215-
});
216-
} else {
217-
console.debug('Conditions not met to download, assuming as completed.');
218-
store.commit('CORE_SET_PAGE_LOADING', false);
219-
store.commit('CORE_SET_ERROR', null);
220-
router.replace({ name: PageNames.TOPICS_ROOT });
221-
}
213+
console.debug('Downloading starter pack...');
214+
return startDownload(grade, name).then(() => {
215+
store.commit('SET_PAGE_NAME', PageNames.DOWNLOAD);
216+
store.commit('CORE_SET_PAGE_LOADING', false);
217+
store.commit('CORE_SET_ERROR', null);
222218
});
223219
}
224220
}

0 commit comments

Comments
 (0)