Skip to content

Commit c2e6d8a

Browse files
authored
Show network status bar on PostCapture tab (#601)
1 parent f70fe75 commit c2e6d8a

File tree

5 files changed

+34
-26
lines changed

5 files changed

+34
-26
lines changed

src/app/app.component.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import { DiaBackendAssetUploadingService } from './shared/services/dia-backend/a
1414
import { DiaBackendAuthService } from './shared/services/dia-backend/auth/dia-backend-auth.service';
1515
import { DiaBackendNotificationService } from './shared/services/dia-backend/notification/dia-backend-notification.service';
1616
import { LanguageService } from './shared/services/language/language.service';
17-
import { NetworkService } from './shared/services/network/network.service';
1817
import { NotificationService } from './shared/services/notification/notification.service';
1918
import { PushNotificationService } from './shared/services/push-notification/push-notification.service';
2019

@@ -39,15 +38,13 @@ export class AppComponent {
3938
notificationService: NotificationService,
4039
pushNotificationService: PushNotificationService,
4140
langaugeService: LanguageService,
42-
networkService: NetworkService,
4341
diaBackendAuthService: DiaBackendAuthService,
4442
diaBackendNotificationService: DiaBackendNotificationService,
4543
uploadService: DiaBackendAssetUploadingService
4644
) {
4745
notificationService.requestPermission();
4846
pushNotificationService.register();
4947
langaugeService.initialize();
50-
networkService.initialize();
5148
diaBackendAuthService.initialize$().pipe(untilDestroyed(this)).subscribe();
5249
uploadService.initialize$().pipe(untilDestroyed(this)).subscribe();
5350
diaBackendNotificationService

src/app/features/home/post-capture-tab/post-capture-tab.component.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
<div class="segment-content" [ngSwitch]="categories">
1+
<p *ngIf="(networkConnected$ | async) === false" class="network-status">
2+
{{ 'message.networkNotConnected' | transloco }}
3+
</p>
4+
<div class="segments" [ngSwitch]="categories">
25
<ion-segment mode="ios" [(ngModel)]="categories">
36
<ion-segment-button value="Photo" checked>
47
<ion-icon src="/assets/icon/apps.svg" class="series-tab-icon"></ion-icon>

src/app/features/home/post-capture-tab/post-capture-tab.component.scss

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,31 @@
11
:host {
22
display: block;
3-
padding: 8px;
43
height: 100%;
54
}
65

7-
ion-segment {
8-
width: 80%;
9-
margin: 0 auto 16px;
10-
flex-shrink: 0;
6+
.network-status {
7+
margin: 0;
8+
padding: 8px;
9+
text-align: center;
10+
background-color: var(--ion-color-light);
11+
color: darkgray;
12+
font-weight: 500;
13+
font-size: 0.9em;
1114
}
1215

13-
.segment-content {
16+
.segments {
1417
display: flex;
18+
padding: 8px;
1519
flex-direction: column;
1620
height: 100%;
1721
}
1822

23+
ion-segment {
24+
width: 80%;
25+
margin: 0 auto 16px;
26+
flex-shrink: 0;
27+
}
28+
1929
.post-captures {
2030
overflow: auto;
2131
}

src/app/features/home/post-capture-tab/post-capture-tab.component.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ import { NetworkService } from '../../../shared/services/network/network.service
1717
export class PostCaptureTabComponent {
1818
categories = 'Photo';
1919

20-
readonly postCaptures$ = this.networkService.connected$.pipe(
20+
readonly networkConnected$ = this.networkService.connected$;
21+
22+
readonly postCaptures$ = this.networkConnected$.pipe(
2123
switchMap(isConnected =>
2224
iif(
2325
() => isConnected,
Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,27 @@
11
import { Inject, Injectable, NgZone } from '@angular/core';
22
import { NetworkPlugin, NetworkStatus } from '@capacitor/core';
3-
import { BehaviorSubject } from 'rxjs';
4-
import { distinctUntilChanged } from 'rxjs/operators';
3+
import { defer, merge, ReplaySubject } from 'rxjs';
4+
import { distinctUntilChanged, pluck } from 'rxjs/operators';
55
import { NETOWRK_PLUGIN } from '../../core/capacitor-plugins/capacitor-plugins.module';
66

77
@Injectable({
88
providedIn: 'root',
99
})
1010
export class NetworkService {
11-
private readonly _connected$ = new BehaviorSubject(true);
12-
readonly connected$ = this._connected$.pipe(distinctUntilChanged());
11+
private readonly status$ = new ReplaySubject<NetworkStatus>(1);
12+
13+
readonly connected$ = merge(
14+
defer(() => this.networkPlugin.getStatus()),
15+
this.status$
16+
).pipe(pluck('connected'), distinctUntilChanged());
1317

1418
constructor(
1519
@Inject(NETOWRK_PLUGIN)
1620
private readonly networkPlugin: NetworkPlugin,
17-
private readonly ngZone: NgZone
18-
) {}
19-
20-
async initialize() {
21-
const currentStatus = await this.networkPlugin.getStatus();
22-
this.updateNetworkStatus(currentStatus);
21+
private readonly zone: NgZone
22+
) {
2323
this.networkPlugin.addListener('networkStatusChange', status => {
24-
this.ngZone.run(() => this.updateNetworkStatus(status));
24+
this.zone.run(() => this.status$.next(status));
2525
});
2626
}
27-
28-
updateNetworkStatus(status: NetworkStatus) {
29-
this._connected$.next(status.connected);
30-
}
3127
}

0 commit comments

Comments
 (0)