Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved router handlers architecture in Coach - part 1 #11570

Merged
merged 5 commits into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions kolibri/plugins/coach/assets/src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { setChannelInfo } from 'kolibri.coreVue.vuex.actions';
import router from 'kolibri.coreVue.router';
import PageRoot from 'kolibri.coreVue.components.PageRoot';
import KolibriApp from 'kolibri_app';
import { PageNames } from './constants';
import routes from './routes';
import pluginModule from './modules/pluginModule';

Expand Down Expand Up @@ -38,18 +39,33 @@ class CoachToolsModule extends KolibriApp {
this.store.commit('SET_PAGE_NAME', to.name);
if (
to.name &&
!to.params.classId &&
!['CoachClassListPage', 'StatusTestPage', 'CoachPrompts', 'AllFacilitiesPage'].includes(
to.name
)
) {
if (to.params.classId)
promises.push(this.store.dispatch('initClassInfo', to.params.classId));
} else {
this.store.dispatch('coachNotifications/stopPolling');
}
// temporary condition as we're gradually moving all promises below this line to local page handlers and therefore need to skip those that we already refactored here https://github.com/learningequality/kolibri/issues/11219
if (to.name && to.name === PageNames.EXAMS) {
next();
ShivangRawat30 marked this conversation as resolved.
Show resolved Hide resolved
return;
}

if (
to.name &&
to.params.classId &&
!['CoachClassListPage', 'StatusTestPage', 'CoachPrompts', 'AllFacilitiesPage'].includes(
to.name
)
) {
promises.push(this.store.dispatch('initClassInfo', to.params.classId));
}

if (this.store.getters.isSuperuser && this.store.state.core.facilities.length === 0) {
promises.push(this.store.dispatch('getFacilities').catch(() => {}));
}

if (promises.length > 0) {
Promise.all(promises).then(next, error => {
this.store.dispatch('handleApiError', { error });
Expand Down
ShivangRawat30 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export function showExamsPage(store, classId) {
store.commit('SET_PAGE_NAME', PageNames.EXAMS);

const promises = [
store.dispatch('initClassInfo', classId),
ShivangRawat30 marked this conversation as resolved.
Show resolved Hide resolved
ExamResource.fetchCollection({
getParams: { collection: classId },
force: true,
Expand All @@ -16,6 +17,10 @@ export function showExamsPage(store, classId) {
store.dispatch('setClassList', store.state.classSummary.facility_id),
];

if (store.getters.isSuperuser && store.state.core.facilities.length === 0) {
promises.push(store.dispatch('getFacilities').catch(() => {}));
}

const shouldResolve = samePageCheckGenerator(store);

return Promise.all(promises).then(
Expand Down
Loading