Merge pull request #4268 from dpalou/MOBILE-4720
MOBILE-4720 myoverview: Load custom filter if all others are disabled
This commit is contained in:
		
						commit
						a2d4936194
					
				| @ -45,7 +45,7 @@ import { | |||||||
| } from '@features/courses/constants'; | } from '@features/courses/constants'; | ||||||
| 
 | 
 | ||||||
| const FILTER_PRIORITY: AddonBlockMyOverviewTimeFilters[] = | const FILTER_PRIORITY: AddonBlockMyOverviewTimeFilters[] = | ||||||
|     ['all', 'inprogress', 'future', 'past', 'favourite', 'allincludinghidden', 'hidden']; |     ['all', 'inprogress', 'future', 'past', 'favourite', 'allincludinghidden', 'hidden', 'custom']; | ||||||
| 
 | 
 | ||||||
| /** | /** | ||||||
|  * Component to render a my overview block. |  * Component to render a my overview block. | ||||||
| @ -529,6 +529,10 @@ export class AddonBlockMyOverviewComponent extends CoreBlockBaseComponent implem | |||||||
|      */ |      */ | ||||||
|     protected async filterCourses(loadWatcher?: PageLoadWatcher): Promise<void> { |     protected async filterCourses(loadWatcher?: PageLoadWatcher): Promise<void> { | ||||||
|         let timeFilter = this.filters.timeFilterSelected; |         let timeFilter = this.filters.timeFilterSelected; | ||||||
|  |         const filterIsActive = timeFilter.startsWith('custom-') ? this.filters.show.custom : this.filters.show[timeFilter]; | ||||||
|  |         if (!filterIsActive) { | ||||||
|  |             timeFilter = this.getFirstActiveFilter(); | ||||||
|  |         } | ||||||
| 
 | 
 | ||||||
|         this.filteredCourses = this.allCourses; |         this.filteredCourses = this.allCourses; | ||||||
| 
 | 
 | ||||||
| @ -571,10 +575,6 @@ export class AddonBlockMyOverviewComponent extends CoreBlockBaseComponent implem | |||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|         } else { |         } else { | ||||||
|             // Filter is not active, take the first active or all. Custom is never saved.
 |  | ||||||
|             if (!this.filters.show[timeFilter]) { |  | ||||||
|                 timeFilter = FILTER_PRIORITY.find((name) => this.filters.show[name]) || 'all'; |  | ||||||
|             } |  | ||||||
|             this.saveFilters(timeFilter); |             this.saveFilters(timeFilter); | ||||||
| 
 | 
 | ||||||
|             // Update today date.
 |             // Update today date.
 | ||||||
| @ -633,6 +633,21 @@ export class AddonBlockMyOverviewComponent extends CoreBlockBaseComponent implem | |||||||
|         this.initPrefetchCoursesIcons(); |         this.initPrefetchCoursesIcons(); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     /** | ||||||
|  |      * Get the first active filter, 'all' if no active filter. | ||||||
|  |      * | ||||||
|  |      * @returns First active filter. | ||||||
|  |      */ | ||||||
|  |     protected getFirstActiveFilter(): string { | ||||||
|  |         const activeFilter = FILTER_PRIORITY.find(name => this.filters.show[name]) || 'all'; | ||||||
|  |         if (activeFilter !== 'custom') { | ||||||
|  |             return activeFilter; | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         // Use first custom filter if there's any.
 | ||||||
|  |         return this.filters.customFilters.length ? 'custom-0' : 'all'; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     /** |     /** | ||||||
|      * Sort courses |      * Sort courses | ||||||
|      * |      * | ||||||
| @ -707,7 +722,7 @@ export class AddonBlockMyOverviewComponent extends CoreBlockBaseComponent implem | |||||||
|      * @param selected Option selected. |      * @param selected Option selected. | ||||||
|      * @returns Promise resolved when done. |      * @returns Promise resolved when done. | ||||||
|      */ |      */ | ||||||
|     async filterOptionsChanged(selected: AddonBlockMyOverviewTimeFilters): Promise<void> { |     async filterOptionsChanged(selected: string): Promise<void> { | ||||||
|         this.filters.timeFilterSelected = selected; |         this.filters.timeFilterSelected = selected; | ||||||
|         this.filterCourses(); |         this.filterCourses(); | ||||||
|     } |     } | ||||||
| @ -787,7 +802,7 @@ export class AddonBlockMyOverviewComponent extends CoreBlockBaseComponent implem | |||||||
| } | } | ||||||
| 
 | 
 | ||||||
| type AddonBlockMyOverviewLayouts = 'card'|'list'; | type AddonBlockMyOverviewLayouts = 'card'|'list'; | ||||||
| type AddonBlockMyOverviewTimeFilters = 'allincludinghidden'|'all'|'inprogress'|'future'|'past'|'favourite'|'hidden'; | type AddonBlockMyOverviewTimeFilters = 'allincludinghidden'|'all'|'inprogress'|'future'|'past'|'favourite'|'hidden'|'custom'; | ||||||
| 
 | 
 | ||||||
| export type AddonBlockMyOverviewFilterOptions = { | export type AddonBlockMyOverviewFilterOptions = { | ||||||
|     enabled: boolean; |     enabled: boolean; | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user