MOBILE-3817 myoverview: Save setting when using custom filter

main
Dani Palou 2022-07-05 15:10:36 +02:00
parent fbe46ee895
commit c9a0b372a9
1 changed files with 21 additions and 5 deletions

View File

@ -252,7 +252,7 @@ export class AddonBlockMyOverviewComponent extends CoreBlockBaseComponent implem
this.loadSort(); this.loadSort();
this.loadLayouts(config?.layouts?.value.split(',')); this.loadLayouts(config?.layouts?.value.split(','));
this.loadFilters(config); await this.loadFilters(config);
this.isDirty = false; this.isDirty = false;
} }
@ -280,9 +280,9 @@ export class AddonBlockMyOverviewComponent extends CoreBlockBaseComponent implem
* *
* @param config Block configuration. * @param config Block configuration.
*/ */
protected loadFilters( protected async loadFilters(
config?: Record<string, { name: string; value: string; type: string }>, config?: Record<string, { name: string; value: string; type: string }>,
): void { ): Promise<void> {
if (!this.hasCourses) { if (!this.hasCourses) {
return; return;
} }
@ -320,7 +320,7 @@ export class AddonBlockMyOverviewComponent extends CoreBlockBaseComponent implem
this.saveFilters('all'); this.saveFilters('all');
} }
this.filterCourses(); await this.filterCourses();
} }
/** /**
@ -369,6 +369,8 @@ export class AddonBlockMyOverviewComponent extends CoreBlockBaseComponent implem
protected async refreshCourseList(data: CoreCoursesMyCoursesUpdatedEventData): Promise<void> { protected async refreshCourseList(data: CoreCoursesMyCoursesUpdatedEventData): Promise<void> {
if (data.action == CoreCoursesProvider.ACTION_ENROL) { if (data.action == CoreCoursesProvider.ACTION_ENROL) {
// Always update if user enrolled in a course. // Always update if user enrolled in a course.
this.loaded = false;
return this.refreshContent(); return this.refreshContent();
} }
@ -376,6 +378,8 @@ export class AddonBlockMyOverviewComponent extends CoreBlockBaseComponent implem
if (data.action == CoreCoursesProvider.ACTION_STATE_CHANGED) { if (data.action == CoreCoursesProvider.ACTION_STATE_CHANGED) {
if (!course) { if (!course) {
// Not found, use WS update. // Not found, use WS update.
this.loaded = false;
return this.refreshContent(); return this.refreshContent();
} }
@ -394,6 +398,8 @@ export class AddonBlockMyOverviewComponent extends CoreBlockBaseComponent implem
if (data.action == CoreCoursesProvider.ACTION_VIEW && data.courseId != CoreSites.getCurrentSiteHomeId()) { if (data.action == CoreCoursesProvider.ACTION_VIEW && data.courseId != CoreSites.getCurrentSiteHomeId()) {
if (!course) { if (!course) {
// Not found, use WS update. // Not found, use WS update.
this.loaded = false;
return this.refreshContent(); return this.refreshContent();
} }
@ -463,7 +469,9 @@ export class AddonBlockMyOverviewComponent extends CoreBlockBaseComponent implem
const customFilterValue = this.filters.customFilters[timeFilter.substring(7)]?.value; const customFilterValue = this.filters.customFilters[timeFilter.substring(7)]?.value;
if (customFilterName !== undefined && customFilterValue !== undefined) { if (customFilterName !== undefined && customFilterValue !== undefined) {
const alreadyLoading = this.loaded === false;
this.loaded = false; this.loaded = false;
try { try {
const courses = await CoreCourses.getEnrolledCoursesByCustomField(customFilterName, customFilterValue); const courses = await CoreCourses.getEnrolledCoursesByCustomField(customFilterName, customFilterValue);
@ -471,10 +479,18 @@ export class AddonBlockMyOverviewComponent extends CoreBlockBaseComponent implem
const courseIds = courses.map((course) => course.id); const courseIds = courses.map((course) => course.id);
this.filteredCourses = this.filteredCourses.filter((course) => courseIds.includes(course.id)); this.filteredCourses = this.filteredCourses.filter((course) => courseIds.includes(course.id));
this.saveFilters(timeFilter);
} catch (error) { } catch (error) {
if (alreadyLoading) {
throw error; // Pass the error to the caller so it's treated there.
}
CoreDomUtils.showErrorModalDefault(error, this.fetchContentDefaultError); CoreDomUtils.showErrorModalDefault(error, this.fetchContentDefaultError);
} finally { } finally {
this.loaded = true; if (!alreadyLoading) {
// Only set loaded to true if there was no other data being loaded.
this.loaded = true;
}
} }
} }
} else { } else {