MOBILE-3833 comments: Don't display Sync option in offline

main
Dani Palou 2022-04-05 11:46:31 +02:00
parent ef834b34ea
commit 525218a4a0
2 changed files with 15 additions and 3 deletions

View File

@ -18,7 +18,7 @@
<core-context-menu-item [hidden]="!(commentsLoaded && !hasOffline)" [priority]="100" [content]="'core.refresh' | translate" <core-context-menu-item [hidden]="!(commentsLoaded && !hasOffline)" [priority]="100" [content]="'core.refresh' | translate"
(action)="refreshComments(false)" [iconAction]="refreshIcon" [closeOnClick]="true"> (action)="refreshComments(false)" [iconAction]="refreshIcon" [closeOnClick]="true">
</core-context-menu-item> </core-context-menu-item>
<core-context-menu-item [hidden]="!(commentsLoaded && hasOffline)" [priority]="100" <core-context-menu-item [hidden]="!(commentsLoaded && hasOffline && isOnline)" [priority]="100"
[content]="'core.settings.synchronizenow' | translate" (action)="refreshComments(true)" [iconAction]="syncIcon" [content]="'core.settings.synchronizenow' | translate" (action)="refreshComments(true)" [iconAction]="syncIcon"
[closeOnClick]="false"> [closeOnClick]="false">
</core-context-menu-item> </core-context-menu-item>
@ -31,7 +31,7 @@
<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]="commentsLoaded"> <core-loading [hideUntil]="commentsLoaded">
<core-empty-box *ngIf="!comments || !comments.length" icon="fas-comments" [message]="'core.comments.nocomments' | translate"> <core-empty-box *ngIf="!comments?.length && !offlineComment" icon="fas-comments" [message]="'core.comments.nocomments' | translate">
</core-empty-box> </core-empty-box>
<!-- Load previous messages. --> <!-- Load previous messages. -->

View File

@ -30,7 +30,7 @@ import {
import { IonContent, IonRefresher } from '@ionic/angular'; import { IonContent, IonRefresher } from '@ionic/angular';
import { ContextLevel, CoreConstants } from '@/core/constants'; import { ContextLevel, CoreConstants } from '@/core/constants';
import { CoreNavigator } from '@services/navigator'; import { CoreNavigator } from '@services/navigator';
import { Translate } from '@singletons'; import { Network, NgZone, Translate } from '@singletons';
import { CoreUtils } from '@services/utils/utils'; import { CoreUtils } from '@services/utils/utils';
import { CoreDomUtils } from '@services/utils/dom'; import { CoreDomUtils } from '@services/utils/dom';
import { CoreUser } from '@features/user/services/user'; import { CoreUser } from '@features/user/services/user';
@ -41,6 +41,7 @@ import { CoreCommentsDBRecord } from '@features/comments/services/database/comme
import { CoreTimeUtils } from '@services/utils/time'; import { CoreTimeUtils } from '@services/utils/time';
import { CoreApp } from '@services/app'; import { CoreApp } from '@services/app';
import moment from 'moment'; import moment from 'moment';
import { Subscription } from 'rxjs';
/** /**
* Page that displays comments. * Page that displays comments.
@ -77,9 +78,11 @@ export class CoreCommentsViewerPage implements OnInit, OnDestroy {
currentUserId: number; currentUserId: number;
sending = false; sending = false;
newComment = ''; newComment = '';
isOnline: boolean;
protected addDeleteCommentsAvailable = false; protected addDeleteCommentsAvailable = false;
protected syncObserver?: CoreEventObserver; protected syncObserver?: CoreEventObserver;
protected onlineObserver: Subscription;
protected viewDestroyed = false; protected viewDestroyed = false;
constructor( constructor(
@ -104,6 +107,14 @@ export class CoreCommentsViewerPage implements OnInit, OnDestroy {
this.fetchComments(false); this.fetchComments(false);
} }
}, CoreSites.getCurrentSiteId()); }, CoreSites.getCurrentSiteId());
this.isOnline = CoreApp.isOnline();
this.onlineObserver = Network.onChange().subscribe(() => {
// Execute the callback in the Angular zone, so change detection doesn't stop working.
NgZone.run(() => {
this.isOnline = CoreApp.isOnline();
});
});
} }
/** /**
@ -596,6 +607,7 @@ export class CoreCommentsViewerPage implements OnInit, OnDestroy {
*/ */
ngOnDestroy(): void { ngOnDestroy(): void {
this.syncObserver?.off(); this.syncObserver?.off();
this.onlineObserver.unsubscribe();
this.viewDestroyed = true; this.viewDestroyed = true;
} }