MOBILE-3320 forum: Fix offline discussions
parent
18ac86d793
commit
fe1a24dd70
|
@ -11,12 +11,12 @@
|
|||
[priority]="750" content="{{'addon.blog.blog' | translate}}" [iconAction]="'far-newspaper'" (action)="gotoBlog()">
|
||||
</core-context-menu-item>
|
||||
<core-context-menu-item
|
||||
*ngIf="discussions.onlineLoaded && discussions.loaded && !(hasOffline || hasOfflineRatings) && isOnline"
|
||||
*ngIf="discussions.loaded && !(hasOffline || hasOfflineRatings) && isOnline"
|
||||
[priority]="700" [content]="'addon.mod_forum.refreshdiscussions' | translate" [iconAction]="refreshIcon" [closeOnClick]="false"
|
||||
(action)="doRefresh(null, $event)">
|
||||
</core-context-menu-item>
|
||||
<core-context-menu-item
|
||||
*ngIf="discussions.onlineLoaded && discussions.loaded && (hasOffline || hasOfflineRatings) && isOnline"
|
||||
*ngIf="discussions.loaded && (hasOffline || hasOfflineRatings) && isOnline"
|
||||
[priority]="600" [content]="'core.settings.synchronizenow' | translate" [iconAction]="syncIcon" [closeOnClick]="false"
|
||||
(action)="doRefresh(null, $event, true)">
|
||||
</core-context-menu-item>
|
||||
|
@ -39,11 +39,11 @@
|
|||
|
||||
<!-- Content. -->
|
||||
<core-split-view>
|
||||
<ion-refresher slot="fixed" [disabled]="!discussions.onlineLoaded || !discussions.loaded" (ionRefresh)="doRefresh($event.target)">
|
||||
<ion-refresher slot="fixed" [disabled]="!discussions.loaded" (ionRefresh)="doRefresh($event.target)">
|
||||
<ion-refresher-content pullingText="{{ 'core.pulltorefresh' | translate }}"></ion-refresher-content>
|
||||
</ion-refresher>
|
||||
|
||||
<core-loading [hideUntil]="discussions.onlineLoaded && discussions.loaded">
|
||||
<core-loading [hideUntil]="discussions.loaded">
|
||||
<!-- Activity info. -->
|
||||
<core-course-module-info *ngIf="showCompletion" [module]="module" [showManualCompletion]="true"
|
||||
(completionChanged)="onCompletionChange()">
|
||||
|
@ -158,7 +158,7 @@
|
|||
</ion-item>
|
||||
|
||||
<core-infinite-loading
|
||||
[enabled]="discussions.onlineLoaded && !discussions.completed" [error]="fetchMoreDiscussionsFailed"
|
||||
[enabled]="discussions.onlineLoaded && !discussions.completed" [error]="discussions.fetchFailed"
|
||||
(action)="fetchMoreDiscussions($event)">
|
||||
</core-infinite-loading>
|
||||
</ng-container>
|
||||
|
|
|
@ -73,7 +73,6 @@ export class AddonModForumIndexComponent extends CoreCourseModuleMainActivityCom
|
|||
moduleName = 'forum';
|
||||
descriptionNote?: string;
|
||||
forum?: AddonModForumData;
|
||||
fetchMoreDiscussionsFailed = false;
|
||||
discussions: AddonModForumDiscussionsManager;
|
||||
canAddDiscussion = false;
|
||||
addDiscussionText!: string;
|
||||
|
@ -237,7 +236,7 @@ export class AddonModForumIndexComponent extends CoreCourseModuleMainActivityCom
|
|||
* @param showErrors Wether to show errors to the user or hide them.
|
||||
*/
|
||||
protected async fetchContent(refresh: boolean = false, sync: boolean = false, showErrors: boolean = false): Promise<void> {
|
||||
this.fetchMoreDiscussionsFailed = false;
|
||||
this.discussions.fetchFailed = false;
|
||||
|
||||
const promises: Promise<void>[] = [];
|
||||
|
||||
|
@ -259,7 +258,7 @@ export class AddonModForumIndexComponent extends CoreCourseModuleMainActivityCom
|
|||
if (refresh) {
|
||||
CoreDomUtils.showErrorModalDefault(error, 'addon.mod_forum.errorgetforum', true);
|
||||
|
||||
this.fetchMoreDiscussionsFailed = true; // Set to prevent infinite calls with infinite-loading.
|
||||
this.discussions.fetchFailed = true; // Set to prevent infinite calls with infinite-loading.
|
||||
} else {
|
||||
// Get forum failed, retry without using cache since it might be a new activity.
|
||||
await this.refreshContent(sync);
|
||||
|
@ -422,7 +421,7 @@ export class AddonModForumIndexComponent extends CoreCourseModuleMainActivityCom
|
|||
*/
|
||||
protected async fetchDiscussions(refresh: boolean): Promise<void> {
|
||||
const forum = this.forum!;
|
||||
this.fetchMoreDiscussionsFailed = false;
|
||||
this.discussions.fetchFailed = false;
|
||||
|
||||
if (refresh) {
|
||||
this.page = 0;
|
||||
|
@ -497,7 +496,7 @@ export class AddonModForumIndexComponent extends CoreCourseModuleMainActivityCom
|
|||
} catch (error) {
|
||||
CoreDomUtils.showErrorModalDefault(error, 'addon.mod_forum.errorgetforum', true);
|
||||
|
||||
this.fetchMoreDiscussionsFailed = true;
|
||||
this.discussions.fetchFailed = true;
|
||||
} finally {
|
||||
complete();
|
||||
}
|
||||
|
@ -715,6 +714,7 @@ type DiscussionItem = AddonModForumDiscussion | AddonModForumOfflineDiscussion |
|
|||
class AddonModForumDiscussionsManager extends CorePageItemsListManager<DiscussionItem> {
|
||||
|
||||
onlineLoaded = false;
|
||||
fetchFailed = false;
|
||||
|
||||
private discussionsPathPrefix: string;
|
||||
private component: AddonModForumIndexComponent;
|
||||
|
@ -726,6 +726,10 @@ class AddonModForumDiscussionsManager extends CorePageItemsListManager<Discussio
|
|||
this.discussionsPathPrefix = discussionsPathPrefix;
|
||||
}
|
||||
|
||||
get loaded(): boolean {
|
||||
return super.loaded && (this.onlineLoaded || this.fetchFailed);
|
||||
}
|
||||
|
||||
get onlineDiscussions(): AddonModForumDiscussion[] {
|
||||
return this.items.filter(discussion => this.isOnlineDiscussion(discussion)) as AddonModForumDiscussion[];
|
||||
}
|
||||
|
@ -782,6 +786,7 @@ class AddonModForumDiscussionsManager extends CorePageItemsListManager<Discussio
|
|||
const otherDiscussions = this.items.filter(discussion => !this.isOnlineDiscussion(discussion));
|
||||
|
||||
this.setItems(otherDiscussions.concat(onlineDiscussions), hasMoreItems);
|
||||
this.onlineLoaded = true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -795,15 +800,6 @@ class AddonModForumDiscussionsManager extends CorePageItemsListManager<Discussio
|
|||
this.setItems((offlineDiscussions as DiscussionItem[]).concat(otherDiscussions), this.hasMoreItems);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
setItems(discussions: DiscussionItem[], hasMoreItems: boolean = false): void {
|
||||
super.setItems(discussions, hasMoreItems);
|
||||
|
||||
this.onlineLoaded = this.onlineLoaded || discussions.some(discussion => this.isOnlineDiscussion(discussion));
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue