From d356bf46fe9d24625567b345fdf049d56dcd7756 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pau=20Ferrer=20Oca=C3=B1a?= Date: Mon, 10 Oct 2022 16:44:13 +0200 Subject: [PATCH] MOBILE-4081 chore: Prevent default on scroll controls --- .../core-horizontal-scroll-controls.html | 4 ++-- .../horizontal-scroll-controls.ts | 6 +++++- .../course-list-item/course-list-item.ts | 4 ++-- src/core/features/user/services/user.ts | 16 ++++++++-------- 4 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/core/components/horizontal-scroll-controls/core-horizontal-scroll-controls.html b/src/core/components/horizontal-scroll-controls/core-horizontal-scroll-controls.html index b49f2c683..f23a2ee22 100644 --- a/src/core/components/horizontal-scroll-controls/core-horizontal-scroll-controls.html +++ b/src/core/components/horizontal-scroll-controls/core-horizontal-scroll-controls.html @@ -1,9 +1,9 @@ - - diff --git a/src/core/components/horizontal-scroll-controls/horizontal-scroll-controls.ts b/src/core/components/horizontal-scroll-controls/horizontal-scroll-controls.ts index 1842b0229..7541826af 100644 --- a/src/core/components/horizontal-scroll-controls/horizontal-scroll-controls.ts +++ b/src/core/components/horizontal-scroll-controls/horizontal-scroll-controls.ts @@ -44,13 +44,17 @@ export class CoreHorizontalScrollControlsComponent { /** * Scroll the target in the given direction. * + * @param ev Click event * @param direction Scroll direction. */ - scroll(direction: 'forward' | 'backward'): void { + scroll(ev: Event, direction: 'forward' | 'backward'): void { if (!this.target) { return; } + ev.stopPropagation(); + ev.preventDefault(); + const leftDelta = direction === 'forward' ? this.target.clientWidth : -this.target.clientWidth; const newScrollLeft = Math.max( Math.min( diff --git a/src/core/features/courses/components/course-list-item/course-list-item.ts b/src/core/features/courses/components/course-list-item/course-list-item.ts index c13587b47..56948e855 100644 --- a/src/core/features/courses/components/course-list-item/course-list-item.ts +++ b/src/core/features/courses/components/course-list-item/course-list-item.ts @@ -163,8 +163,6 @@ export class CoreCoursesCourseListItemComponent implements OnInit, OnDestroy, On /** * Open a course. - * - * @param course The course to open. */ openCourse(): void { if (this.isEnrolled) { @@ -179,6 +177,8 @@ export class CoreCoursesCourseListItemComponent implements OnInit, OnDestroy, On /** * Initialize prefetch course. + * + * @param forceInit Force initialization of prefetch course info. */ async initPrefetchCourse(forceInit = false): Promise { if (!this.isEnrolled || !this.showDownload || diff --git a/src/core/features/user/services/user.ts b/src/core/features/user/services/user.ts index 0be9e9a8a..e54cdb230 100644 --- a/src/core/features/user/services/user.ts +++ b/src/core/features/user/services/user.ts @@ -137,11 +137,11 @@ export class CoreUserProvider { const result = await site.write('core_user_update_picture', params); - if (!result.success) { + if (!result.success || !result.profileimageurl) { return Promise.reject(null); } - return result.profileimageurl!; + return result.profileimageurl; } /** @@ -452,7 +452,7 @@ export class CoreUserProvider { name, }; const preSets: CoreSiteWSPreSets = { - cacheKey: this.getUserPreferenceCacheKey(params.name!), + cacheKey: this.getUserPreferenceCacheKey(name), updateFrequency: CoreSite.FREQUENCY_SOMETIMES, }; @@ -613,7 +613,7 @@ export class CoreUserProvider { const treated: Record = {}; await Promise.all(userIds.map(async (userId) => { - if (userId === null) { + if (userId === null || !siteId) { return; } @@ -630,7 +630,7 @@ export class CoreUserProvider { const profile = await this.getProfile(userId, courseId, false, siteId); if (profile.profileimageurl) { - await CoreFilepool.addToQueueByUrl(siteId!, profile.profileimageurl); + await CoreFilepool.addToQueueByUrl(siteId, profile.profileimageurl); } } catch (error) { this.logger.warn(`Ignore error when prefetching user ${userId}`, error); @@ -658,7 +658,7 @@ export class CoreUserProvider { const promises = entries.map(async (entry) => { const imageUrl = entry[propertyName]; - if (!imageUrl || treated[imageUrl]) { + if (!imageUrl || treated[imageUrl] || !siteId) { // It doesn't have an image or it has already been treated. return; } @@ -666,7 +666,7 @@ export class CoreUserProvider { treated[imageUrl] = true; try { - await CoreFilepool.addToQueueByUrl(siteId!, imageUrl); + await CoreFilepool.addToQueueByUrl(siteId, imageUrl); } catch (ex) { this.logger.warn(`Ignore error when prefetching user avatar ${imageUrl}`, entry, ex); } @@ -682,7 +682,7 @@ export class CoreUserProvider { * @param search The string to search. * @param searchAnywhere Whether to find a match anywhere or only at the beginning. * @param page Page to get. - * @param limitNumber Number of participants to get. + * @param perPage Number of participants to get. * @param siteId Site Id. If not defined, use current site. * @return Promise resolved when the participants are retrieved. * @since 3.8