From f2798ec817da5fd99208aea77e557723b1f91bf4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pau=20Ferrer=20Oca=C3=B1a?= Date: Thu, 10 Mar 2022 12:28:39 +0100 Subject: [PATCH] MOBILE-3814 course: Add placeholder thumb on course page --- .../features/course/pages/index/index.html | 13 +++++-- .../features/course/pages/index/index.scss | 16 +++++++++ src/core/features/course/pages/index/index.ts | 36 +++++++++++++++---- 3 files changed, 56 insertions(+), 9 deletions(-) diff --git a/src/core/features/course/pages/index/index.html b/src/core/features/course/pages/index/index.html index b864139cd..a0e768d08 100644 --- a/src/core/features/course/pages/index/index.html +++ b/src/core/features/course/pages/index/index.html @@ -17,9 +17,16 @@ - - - + +
+ +
+ + + +
+

{{ title }}

diff --git a/src/core/features/course/pages/index/index.scss b/src/core/features/course/pages/index/index.scss index 63efe0c1f..6b75fd1e8 100644 --- a/src/core/features/course/pages/index/index.scss +++ b/src/core/features/course/pages/index/index.scss @@ -11,6 +11,22 @@ width: var(--core-courseimage-on-course-size); min-width: var(--core-courseimage-on-course-size); --border-radius: var(--core-courseimage-radius); + @include margin(8px, 16px, 8px, 0px); + + @for $i from 0 to length($core-course-image-background) { + &.course-color-#{$i} { + --course-color: var(--core-course-color-#{$i}); + --course-color-tint: var(--core-course-color-#{$i}-tint); + } + } + + ion-icon.course-icon { + padding: 12px; + font-size: calc(var(--core-courseimage-on-course-size) - 24px); + border-radius: var(--border-radius); + color: var(--course-color-tint); + background: var(--course-color, transparent); + } } @if ($core-hide-courseimage-on-course) { diff --git a/src/core/features/course/pages/index/index.ts b/src/core/features/course/pages/index/index.ts index bb2537e83..3a7679baf 100644 --- a/src/core/features/course/pages/index/index.ts +++ b/src/core/features/course/pages/index/index.ts @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -import { Component, ViewChild, OnDestroy, OnInit } from '@angular/core'; +import { Component, ViewChild, OnDestroy, OnInit, ElementRef } from '@angular/core'; import { ActivatedRoute, Params } from '@angular/router'; import { CoreTabsOutletTab, CoreTabsOutletComponent } from '@components/tabs-outlet/tabs-outlet'; @@ -28,6 +28,8 @@ import { CoreNavigationOptions, CoreNavigator } from '@services/navigator'; import { CONTENTS_PAGE_NAME } from '@features/course/course.module'; import { CoreDomUtils } from '@services/utils/dom'; import { CoreCourseSummaryPage } from '../course-summary/course-summary'; +import { CoreCoursesHelper, CoreCourseWithImageAndColor } from '@features/courses/services/courses-helper'; +import { CoreColors } from '@singletons/colors'; /** * Page that displays the list of courses the user is enrolled in. @@ -40,13 +42,13 @@ import { CoreCourseSummaryPage } from '../course-summary/course-summary'; export class CoreCourseIndexPage implements OnInit, OnDestroy { @ViewChild(CoreTabsOutletComponent) tabsComponent?: CoreTabsOutletComponent; + @ViewChild('courseThumb') courseThumb?: ElementRef; title = ''; category = ''; - course?: CoreCourseAnyCourseData; + course?: CoreCourseWithImageAndColor & CoreCourseAnyCourseData; tabs: CourseTab[] = []; loaded = false; - imageThumb?: string; progress?: number; protected currentPagePath = ''; @@ -235,9 +237,7 @@ export class CoreCourseIndexPage implements OnInit, OnDestroy { // Get the title to display initially. this.title = CoreCourseFormatDelegate.getCourseTitle(this.course); - if ('overviewfiles' in this.course) { - this.imageThumb = this.course.overviewfiles?.[0]?.fileurl; - } + await this.setCourseColor(); this.updateProgress(); @@ -313,6 +313,30 @@ export class CoreCourseIndexPage implements OnInit, OnDestroy { this.progress = this.course.progress; } + /** + * Set course color. + */ + protected async setCourseColor(): Promise { + if (!this.course) { + return; + } + + await CoreCoursesHelper.loadCourseColorAndImage(this.course); + + if (!this.courseThumb) { + return; + } + + if (this.course.color) { + this.courseThumb.nativeElement.style.setProperty('--course-color', this.course.color); + + const tint = CoreColors.lighter(this.course.color, 50); + this.courseThumb.nativeElement.style.setProperty('--course-color-tint', tint); + } else if(this.course.colorNumber !== undefined) { + this.courseThumb.nativeElement.classList.add('course-color-' + this.course.colorNumber); + } + } + } type CourseTab = CoreTabsOutletTab & {