MOBILE-3973 course: Load fallback icon when image cannot be loaded

main
Pau Ferrer Ocaña 2023-06-08 15:56:16 +02:00
parent 2634d044cb
commit 597b4d5045
4 changed files with 27 additions and 3 deletions

View File

@ -18,7 +18,7 @@
</ion-refresher> </ion-refresher>
<core-loading [hideUntil]="dataLoaded"> <core-loading [hideUntil]="dataLoaded">
<div *ngIf="course" class="core-course-thumb" #courseThumb> <div *ngIf="course" class="core-course-thumb" #courseThumb>
<img *ngIf="course.courseimage" [src]="course.courseimage" core-external-content alt="" /> <img *ngIf="course.courseimage" [src]="course.courseimage" core-external-content alt="" (error)="loadFallbackCourseIcon()" />
<ion-icon *ngIf="!course.courseimage" name="fas-graduation-cap" class="course-icon" aria-hidden="true"> <ion-icon *ngIf="!course.courseimage" name="fas-graduation-cap" class="course-icon" aria-hidden="true">
</ion-icon> </ion-icon>
</div> </div>

View File

@ -466,6 +466,20 @@ export class CoreCourseSummaryPage implements OnInit, OnDestroy {
CoreNavigator.navigateToSitePath(item.data.page, { params }); CoreNavigator.navigateToSitePath(item.data.page, { params });
} }
/**
* Removes the course image set because it cannot be loaded and set the fallback icon color.
*/
loadFallbackCourseIcon(): void {
if (!this.course) {
return;
}
this.course.courseimage = undefined;
// Set the color because it won't be set at this point.
this.setCourseColor();
}
/** /**
* Set course color. * Set course color.
*/ */

View File

@ -3,7 +3,7 @@
button [attr.aria-label]="course.displayname || course.fullname"> button [attr.aria-label]="course.displayname || course.fullname">
<div *ngIf="layout == 'card' || layout == 'summarycard'" class="core-course-thumb" [class.core-course-color-img]="course.courseimage"> <div *ngIf="layout == 'card' || layout == 'summarycard'" class="core-course-thumb" [class.core-course-color-img]="course.courseimage">
<img *ngIf="course.courseimage" [src]="course.courseimage" core-external-content alt="" /> <img *ngIf="course.courseimage" [src]="course.courseimage" core-external-content alt="" (error)="loadFallbackCourseIcon()" />
<ion-icon *ngIf="!course.courseimage" name="fas-graduation-cap" class="course-icon" aria-hidden="true"> <ion-icon *ngIf="!course.courseimage" name="fas-graduation-cap" class="course-icon" aria-hidden="true">
</ion-icon> </ion-icon>
</div> </div>
@ -34,7 +34,7 @@
aria-hidden="true"> aria-hidden="true">
</ion-icon> </ion-icon>
<ion-avatar *ngIf="course.courseimage" slot="start" class="core-course-thumb"> <ion-avatar *ngIf="course.courseimage" slot="start" class="core-course-thumb">
<img [src]="course.courseimage" core-external-content alt="" /> <img [src]="course.courseimage" core-external-content alt="" (error)="loadFallbackCourseIcon()" />
</ion-avatar> </ion-avatar>
</ng-container> </ng-container>

View File

@ -128,6 +128,16 @@ export class CoreCoursesCourseListItemComponent implements OnInit, OnDestroy, On
} }
} }
/**
* Removes the course image set because it cannot be loaded and set the fallback icon color.
*/
loadFallbackCourseIcon(): void {
this.course.courseimage = undefined;
// Set the color because it won't be set at this point.
this.setCourseColor();
}
/** /**
* Set course color. * Set course color.
*/ */