Skip to content

Commit 5677b0d

Browse files
committed
♻️ refcatoring function and variables name
1 parent a9ba0f0 commit 5677b0d

File tree

1 file changed

+20
-29
lines changed

1 file changed

+20
-29
lines changed

src/app/core/components/network-status/network-status.component.ts

Lines changed: 20 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@ import { fromEvent, Observable, Subscription } from 'rxjs';
1616
<div class="p-4">
1717
<div class="flex items-start">
1818
<div class="flex-shrink-0">
19-
<!-- Heroicon name: outline/check-circle -->
2019
<svg
2120
class="h-6 w-6"
22-
[ngClass]="{'text-green-400': networkStatus === 'online', 'text-red-400': networkStatus === 'offline'}"
21+
[ngClass]="{
22+
'text-green-400': networkStatus === 'online',
23+
'text-red-400': networkStatus === 'offline'
24+
}"
2325
xmlns="http://www.w3.org/2000/svg"
2426
fill="none"
2527
viewBox="0 0 24 24"
@@ -38,15 +40,7 @@ import { fromEvent, Observable, Subscription } from 'rxjs';
3840
stroke-linejoin="round" />
3941
</svg>
4042
</div>
41-
<div *ngIf="networkStatus === 'online'" class="ml-3 w-0 flex-1 pt-0.5">
42-
<p class="text-sm font-medium text-slate-900 capitalize">
43-
{{ networkStatus }}
44-
</p>
45-
<p class="mt-1 text-sm text-slate-500">
46-
{{ networkStatusMessage }}
47-
</p>
48-
</div>
49-
<div *ngIf="networkStatus === 'offline'" class="ml-3 w-0 flex-1 pt-0.5">
43+
<div class="ml-3 w-0 flex-1 pt-0.5">
5044
<p class="text-sm font-medium text-slate-900 capitalize">
5145
{{ networkStatus }}
5246
</p>
@@ -63,53 +57,50 @@ import { fromEvent, Observable, Subscription } from 'rxjs';
6357
animations: [
6458
trigger('showHideNotification', [
6559
transition('void => *', [
66-
style({ transform: "translateX(0.5rem)", opacity: 0 }),
67-
animate(300, style({ transform: "translateX(0)", opacity: 1 }))
60+
style({ transform: 'translateX(0.5rem)', opacity: 0 }),
61+
animate(300, style({ transform: 'translateX(0)', opacity: 1 })),
6862
]),
69-
transition('* => void', [
70-
animate(100, style({ opacity: 0 }))
71-
])
63+
transition('* => void', [animate(100, style({ opacity: 0 }))]),
7264
]),
7365
],
7466
})
7567
export class NetworkStatusComponent implements OnInit {
7668
networkStatusMessage!: string;
7769
networkStatus!: string;
78-
79-
onlineEvent!: Observable<Event>;
80-
offlineEvent!: Observable<Event>;
8170
subscriptions: Subscription[] = [];
82-
8371
showNetworkStatus!: boolean;
8472

73+
onlineEvent$!: Observable<Event>;
74+
offlineEvent$!: Observable<Event>;
75+
8576
ngOnInit() {
8677
this.networkStatusChecker();
8778
}
8879

89-
showHideNetworkStatus() {
80+
toggleNetworkStatus(): void {
9081
this.showNetworkStatus = true;
9182
setTimeout(() => {
9283
this.showNetworkStatus = false;
93-
}, 3000);
84+
}, 5000);
9485
}
9586

9687
networkStatusChecker(): void {
97-
this.onlineEvent = fromEvent(window, 'online');
98-
this.offlineEvent = fromEvent(window, 'offline');
88+
this.onlineEvent$ = fromEvent(window, 'online');
89+
this.offlineEvent$ = fromEvent(window, 'offline');
9990

10091
this.subscriptions.push(
101-
this.onlineEvent.subscribe(() => {
92+
this.onlineEvent$.subscribe(() => {
10293
this.networkStatus = 'online';
10394
this.networkStatusMessage = $localize`Vous êtes de nouveau en ligne.`;
104-
this.showHideNetworkStatus();
95+
this.toggleNetworkStatus();
10596
})
10697
);
10798

10899
this.subscriptions.push(
109-
this.offlineEvent.subscribe(() => {
100+
this.offlineEvent$.subscribe(() => {
110101
this.networkStatus = 'offline';
111-
this.networkStatusMessage = $localize`Connexion perdue ! Vous n'êtes pas connecté à l'Internet`;
112-
this.showHideNetworkStatus();
102+
this.networkStatusMessage = $localize`Vous n'êtes pas connecté à l'Internet`;
103+
this.toggleNetworkStatus();
113104
})
114105
);
115106
}

0 commit comments

Comments
 (0)