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