From 6b0fbbeaa5b556292e13701a67bbd5209fcd61fa Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Wed, 14 Dec 2022 12:27:18 +0100 Subject: [PATCH] MOBILE-4081 forum: Display selectors if loading discussions fail --- scripts/langindex.json | 2 ++ .../forum/classes/forum-discussions-source.ts | 31 ++++++++++++++----- .../mod/forum/components/index/index.html | 15 ++++++--- .../mod/forum/components/index/index.ts | 4 +++ src/addons/mod/forum/lang.json | 2 ++ 5 files changed, 41 insertions(+), 13 deletions(-) diff --git a/scripts/langindex.json b/scripts/langindex.json index d319bd42f..7d2407912 100644 --- a/scripts/langindex.json +++ b/scripts/langindex.json @@ -639,6 +639,8 @@ "addon.mod_forum.erroremptysubject": "forum", "addon.mod_forum.errorgetforum": "local_moodlemobileapp", "addon.mod_forum.errorgetgroups": "local_moodlemobileapp", + "addon.mod_forum.errorloadingsortingorder": "local_moodlemobileapp", + "addon.mod_forum.errorloadingsortingorderdetails": "local_moodlemobileapp", "addon.mod_forum.errorposttoallgroups": "local_moodlemobileapp", "addon.mod_forum.favourites": "forum", "addon.mod_forum.favouriteupdated": "forum", diff --git a/src/addons/mod/forum/classes/forum-discussions-source.ts b/src/addons/mod/forum/classes/forum-discussions-source.ts index 4b35b9454..06a51ffdd 100644 --- a/src/addons/mod/forum/classes/forum-discussions-source.ts +++ b/src/addons/mod/forum/classes/forum-discussions-source.ts @@ -44,6 +44,7 @@ export class AddonModForumDiscussionsSource extends CoreRoutedItemsManagerSource groupInfo?: CoreGroupInfo; allPartsPermissions?: AddonModForumCanAddDiscussion; canAddDiscussionToGroup = true; + errorLoadingDiscussions = false; constructor(courseId: number, cmId: number, discussionsPathPrefix: string) { super(); @@ -222,13 +223,27 @@ export class AddonModForumDiscussionsSource extends CoreRoutedItemsManagerSource throw new Error('Can\'t load discussions without a forum or selected sort order'); } - const response = await AddonModForum.getDiscussions(this.forum.id, { - cmId: this.forum.cmid, - sortOrder: this.selectedSortOrder.value, - page, - groupId: this.groupId, - }); - let discussions = response.discussions; + let discussions: AddonModForumDiscussion[] = []; + let canLoadMore = false; + try { + const response = await AddonModForum.getDiscussions(this.forum.id, { + cmId: this.forum.cmid, + sortOrder: this.selectedSortOrder.value, + page, + groupId: this.groupId, + }); + + discussions = response.discussions; + canLoadMore = response.canLoadMore; + this.errorLoadingDiscussions = false; + } catch (error) { + if (page > 0 || CoreUtils.isWebServiceError(error)) { + throw error; + } + + // Error loading first discussions, use an empty list. + this.errorLoadingDiscussions = true; + } if (this.usesGroups) { discussions = await AddonModForum.formatDiscussionsGroups(this.forum.cmid, discussions); @@ -254,7 +269,7 @@ export class AddonModForumDiscussionsSource extends CoreRoutedItemsManagerSource } } - return { discussions, canLoadMore: response.canLoadMore }; + return { discussions, canLoadMore }; } /** diff --git a/src/addons/mod/forum/components/index/index.html b/src/addons/mod/forum/components/index/index.html index 4c6b1c123..e4d953a31 100644 --- a/src/addons/mod/forum/components/index/index.html +++ b/src/addons/mod/forum/components/index/index.html @@ -54,17 +54,22 @@ - - - -
+
+ + + + +

{{ 'addon.mod_forum.errorloadingsortingorderdetails' | translate }}

+
+ diff --git a/src/addons/mod/forum/components/index/index.ts b/src/addons/mod/forum/components/index/index.ts index 63d70a8d9..3dd733ad9 100644 --- a/src/addons/mod/forum/components/index/index.ts +++ b/src/addons/mod/forum/components/index/index.ts @@ -152,6 +152,10 @@ export class AddonModForumIndexComponent extends CoreCourseModuleMainActivityCom return !!(this.forum && this.canAddDiscussion && this.discussions?.getSource().canAddDiscussionToGroup); } + get errorLoadingDiscussions(): boolean { + return !!this.discussions?.getSource().errorLoadingDiscussions; + } + /** * Check whether a discussion is online. * diff --git a/src/addons/mod/forum/lang.json b/src/addons/mod/forum/lang.json index fc6d78c16..b3146a6a7 100644 --- a/src/addons/mod/forum/lang.json +++ b/src/addons/mod/forum/lang.json @@ -28,6 +28,8 @@ "erroremptysubject": "Post subject cannot be empty.", "errorgetforum": "Error getting forum data.", "errorgetgroups": "Error getting group settings.", + "errorloadingsortingorder": "Forum not available in this sorting order", + "errorloadingsortingorderdetails": "Try changing the sorting order or going online to view this forum.", "errorposttoallgroups": "Could not create new discussion in all groups.", "favourites": "Starred", "favouriteupdated": "Your star option has been updated.",