[frontend] Add spinner when loading

This commit is contained in:
Cathy Hu 2020-09-11 15:38:46 +02:00
parent d6fc38504a
commit bc4b57aaef
17 changed files with 475 additions and 348 deletions

View file

@ -10,9 +10,10 @@
<mat-icon>add</mat-icon> <mat-icon>add</mat-icon>
</button> </button>
</form> </form>
<ng-container *ngIf="badwords$ | async as badwords"> <ng-container *ngIf="badwords$ | loading | async as badwords">
<mat-list *ngIf="badwords.length !== 0; else empty"> <ng-template [ngIf]="badwords.value">
<mat-list-item *ngFor="let badword of badwords"> <mat-list *ngIf="badwords.value.length !== 0; else empty">
<mat-list-item *ngFor="let badword of badwords.value">
<div class="entry"> <div class="entry">
<div class="regex"> <div class="regex">
{{ badword.pattern }} {{ badword.pattern }}
@ -39,11 +40,16 @@
<mat-divider></mat-divider> <mat-divider></mat-divider>
</mat-list-item> </mat-list-item>
</mat-list> </mat-list>
</ng-container>
<ng-template #empty> <ng-template #empty>
<div class="error-msg"> <div class="error-msg">No badwords configured yet.</div>
No badwords configured yet.
</div>
</ng-template> </ng-template>
</ng-template>
<ng-template [ngIf]="badwords.error"
><mat-icon class="warning">warning</mat-icon></ng-template
>
<ng-template [ngIf]="badwords.loading">
<mat-spinner [diameter]="45" class="spinner"></mat-spinner>
</ng-template>
</ng-container>
</mat-card-content> </mat-card-content>
</mat-card> </mat-card>

View file

@ -10,9 +10,10 @@
<mat-icon>add</mat-icon> <mat-icon>add</mat-icon>
</button> </button>
</form> </form>
<ng-container *ngIf="triggers$ | async as triggers"> <ng-container *ngIf="triggers$ | loading | async as triggers">
<mat-list *ngIf="triggers.length !== 0; else empty"> <ng-template [ngIf]="triggers.value">
<mat-list-item *ngFor="let trigger of triggers"> <mat-list *ngIf="triggers.value.length !== 0; else empty">
<mat-list-item *ngFor="let trigger of triggers.value">
<div class="entry"> <div class="entry">
<div class="regex"> <div class="regex">
{{ trigger.pattern }} {{ trigger.pattern }}
@ -39,11 +40,16 @@
<mat-divider></mat-divider> <mat-divider></mat-divider>
</mat-list-item> </mat-list-item>
</mat-list> </mat-list>
</ng-container>
<ng-template #empty> <ng-template #empty>
<div class="error-msg"> <div class="error-msg">No triggers configured yet.</div>
No triggers configured yet.
</div>
</ng-template> </ng-template>
</ng-template>
<ng-template [ngIf]="triggers.error"
><mat-icon class="warning">warning</mat-icon></ng-template
>
<ng-template [ngIf]="triggers.loading">
<mat-spinner [diameter]="45" class="spinner"></mat-spinner>
</ng-template>
</ng-container>
</mat-card-content> </mat-card-content>
</mat-card> </mat-card>

View file

@ -7,11 +7,13 @@
technology for your community to florish! technology for your community to florish!
</p> </p>
<div class="hoods-container"> <div class="hoods-container">
<ng-container *ngIf="hoods$ | loading | async as hoods">
<ng-template [ngIf]="hoods.value">
<mat-selection-list [multiple]="false"> <mat-selection-list [multiple]="false">
<div mat-subheader>Configure your hoods</div> <div mat-subheader>Configure your hoods</div>
<mat-divider></mat-divider> <mat-divider></mat-divider>
<a <a
*ngFor="let hood of hoods$ | async" *ngFor="let hood of hoods.value"
[routerLink]="['/dashboard/hoods', hood.id]" [routerLink]="['/dashboard/hoods', hood.id]"
matTooltip="Edit settings of {{ hood.name }}" matTooltip="Edit settings of {{ hood.name }}"
> >
@ -28,7 +30,7 @@
</mat-selection-list> </mat-selection-list>
<mat-list> <mat-list>
<div mat-subheader></div> <div mat-subheader></div>
<mat-list-item *ngFor="let hood of hoods$ | async"> <mat-list-item *ngFor="let hood of hoods.value">
<a <a
[routerLink]="['/hoods', hood.id]" [routerLink]="['/hoods', hood.id]"
target="_blank" target="_blank"
@ -38,6 +40,14 @@
</a> </a>
</mat-list-item> </mat-list-item>
</mat-list> </mat-list>
</ng-template>
<ng-template [ngIf]="hoods.error"
><mat-icon class="warning">warning</mat-icon></ng-template
>
<ng-template [ngIf]="hoods.loading">
<mat-spinner [diameter]="45" class="spinner"></mat-spinner>
</ng-template>
</ng-container>
</div> </div>
<button <button

View file

@ -1,5 +1,6 @@
<div *ngIf="emails$ | async as emails"> <div *ngIf="emails$ | loading | async as emails">
<mat-card *ngIf="emails.length !== 0"> <ng-template [ngIf]="emails.value">
<mat-card>
<mat-card-header> <mat-card-header>
<div mat-card-avatar class="email"></div> <div mat-card-avatar class="email"></div>
<mat-card-title class="platform-title"> <mat-card-title class="platform-title">
@ -14,14 +15,19 @@
</button> </button>
</mat-card-title> </mat-card-title>
</mat-card-header> </mat-card-header>
<mat-card-content> <mat-card-content *ngIf="emails.value.length !== 0; else noEmail">
<h3>Subscribe to E-Mail list:</h3> <h3>Subscribe to E-Mail list:</h3>
<form class="input" [formGroup]="form" (ngSubmit)="onSubmit()"> <form class="input" [formGroup]="form" (ngSubmit)="onSubmit()">
<mat-form-field> <mat-form-field>
<mat-label>Your E-Mail</mat-label> <mat-label>Your E-Mail</mat-label>
<input formControlName="email" matInput /> <input formControlName="email" matInput />
</mat-form-field> </mat-form-field>
<button mat-icon-button color="primary" aria-label="Add" class="button"> <button
mat-icon-button
color="primary"
aria-label="Add"
class="button"
>
<mat-icon>person_add</mat-icon> <mat-icon>person_add</mat-icon>
</button> </button>
</form> </form>
@ -29,7 +35,7 @@
<h3>Send e-mail to hood:</h3> <h3>Send e-mail to hood:</h3>
<mat-selection-list [multiple]="false" class="list"> <mat-selection-list [multiple]="false" class="list">
<a <a
*ngFor="let email of emails" *ngFor="let email of emails.value"
href="mailto:{{ email.name }}@{{ emailDomain }}" href="mailto:{{ email.name }}@{{ emailDomain }}"
> >
<mat-list-option> <mat-list-option>
@ -40,4 +46,16 @@
</mat-selection-list> </mat-selection-list>
</mat-card-content> </mat-card-content>
</mat-card> </mat-card>
<ng-template #noEmail>
<mat-card-content>
Unfortunately your hood admin has not configured E-Mail as platform yet.
</mat-card-content>
</ng-template>
</ng-template>
<ng-template [ngIf]="emails.error"
><mat-icon class="warning">warning</mat-icon></ng-template
>
<ng-template [ngIf]="emails.loading">
<mat-spinner [diameter]="45" class="spinner"></mat-spinner>
</ng-template>
</div> </div>

View file

@ -14,8 +14,9 @@
</mat-card-title> </mat-card-title>
</mat-card-header> </mat-card-header>
<mat-card-content> <mat-card-content>
<mat-list *ngIf="emails$ | async as emails"> <mat-list *ngIf="emails$ | loading | async as emails">
<mat-list-item *ngIf="emails.length === 0; else startButton"> <ng-template [ngIf]="emails.value">
<mat-list-item *ngIf="emails.value.length === 0; else startButton">
<button mat-menu-item (click)="onCreate()"> <button mat-menu-item (click)="onCreate()">
<mat-icon>add</mat-icon> <mat-icon>add</mat-icon>
<span> Add a platform connection!</span> <span> Add a platform connection!</span>
@ -35,7 +36,7 @@
<mat-divider></mat-divider> <mat-divider></mat-divider>
</mat-list-item> </mat-list-item>
</ng-template> </ng-template>
<mat-list-item *ngFor="let email of emails"> <mat-list-item *ngFor="let email of emails.value">
<div class="entry"> <div class="entry">
{{ email.name }}@{{ domain }} {{ email.name }}@{{ domain }}
<button <button
@ -58,6 +59,13 @@
</button> </button>
</mat-menu> </mat-menu>
</mat-list-item> </mat-list-item>
</ng-template>
<ng-template [ngIf]="emails.error"
><mat-icon class="warning">warning</mat-icon></ng-template
>
<ng-template [ngIf]="emails.loading">
<mat-spinner [diameter]="45" class="spinner"></mat-spinner>
</ng-template>
</mat-list> </mat-list>
</mat-card-content> </mat-card-content>
</mat-card> </mat-card>

View file

@ -1,5 +1,6 @@
<div *ngIf="telegrams$ | async as telegrams"> <div *ngIf="telegrams$ | loading | async as telegrams">
<mat-card *ngIf="telegrams.length !== 0"> <ng-template [ngIf]="telegrams.value">
<mat-card>
<mat-card-header> <mat-card-header>
<div mat-card-avatar class="telegram"></div> <div mat-card-avatar class="telegram"></div>
<mat-card-title class="platform-title"> <mat-card-title class="platform-title">
@ -14,10 +15,10 @@
</button> </button>
</mat-card-title> </mat-card-title>
</mat-card-header> </mat-card-header>
<mat-card-content> <mat-card-content *ngIf="telegrams.value.length !== 0; else noTelegram">
<mat-selection-list [multiple]="false" class="list"> <mat-selection-list [multiple]="false" class="list">
<a <a
*ngFor="let telegram of telegrams" *ngFor="let telegram of telegrams.value"
href="https://t.me/{{ telegram.username }}" href="https://t.me/{{ telegram.username }}"
routerLinkActive="router-link-active" routerLinkActive="router-link-active"
> >
@ -29,4 +30,17 @@
</mat-selection-list> </mat-selection-list>
</mat-card-content> </mat-card-content>
</mat-card> </mat-card>
<ng-template #noTelegram>
<mat-card-content>
Unfortunately your hood admin has not configured Telegram as platform
yet.
</mat-card-content>
</ng-template>
</ng-template>
<ng-template [ngIf]="telegrams.error"
><mat-icon class="warning">warning</mat-icon></ng-template
>
<ng-template [ngIf]="telegrams.loading">
<mat-spinner [diameter]="45" class="spinner"></mat-spinner>
</ng-template>
</div> </div>

View file

@ -14,15 +14,16 @@
</mat-card-title> </mat-card-title>
</mat-card-header> </mat-card-header>
<mat-card-content> <mat-card-content>
<mat-list *ngIf="telegrams$ | async as telegrams"> <mat-list *ngIf="telegrams$ | loading | async as telegrams">
<mat-list-item *ngIf="telegrams.length === 0"> <ng-template [ngIf]="telegrams.value">
<mat-list-item *ngIf="telegrams.value.length === 0">
<button mat-menu-item (click)="onCreate()"> <button mat-menu-item (click)="onCreate()">
<mat-icon>add</mat-icon> <mat-icon>add</mat-icon>
<span> Add a platform connection!</span> <span> Add a platform connection!</span>
</button> </button>
<mat-divider></mat-divider> <mat-divider></mat-divider>
</mat-list-item> </mat-list-item>
<mat-list-item *ngFor="let telegram of telegrams"> <mat-list-item *ngFor="let telegram of telegrams.value">
<div class="entry"> <div class="entry">
@{{ telegram.username }} @{{ telegram.username }}
<mat-slide-toggle <mat-slide-toggle
@ -53,6 +54,13 @@
</button> </button>
</mat-menu> </mat-menu>
</mat-list-item> </mat-list-item>
</ng-template>
<ng-template [ngIf]="telegrams.error"
><mat-icon class="warning">warning</mat-icon></ng-template
>
<ng-template [ngIf]="telegrams.loading">
<mat-spinner [diameter]="45" class="spinner"></mat-spinner>
</ng-template>
</mat-list> </mat-list>
</mat-card-content> </mat-card-content>
</mat-card> </mat-card>

View file

@ -1,5 +1,6 @@
<div *ngIf="twitters$ | async as twitters"> <div *ngIf="twitters$ | loading | async as twitters">
<mat-card *ngIf="twitters.length !== 0"> <ng-template [ngIf]="twitters.value">
<mat-card>
<mat-card-header> <mat-card-header>
<div mat-card-avatar class="twitter"></div> <div mat-card-avatar class="twitter"></div>
<mat-card-title class="platform-title"> <mat-card-title class="platform-title">
@ -14,10 +15,10 @@
</button> </button>
</mat-card-title> </mat-card-title>
</mat-card-header> </mat-card-header>
<mat-card-content> <mat-card-content *ngIf="twitters.value.length !== 0; else noTwitter">
<mat-selection-list [multiple]="false" class="list"> <mat-selection-list [multiple]="false" class="list">
<a <a
*ngFor="let twitter of twitters" *ngFor="let twitter of twitters.value"
href="https://twitter.com/{{ twitter.username }}" href="https://twitter.com/{{ twitter.username }}"
routerLinkActive="router-link-active" routerLinkActive="router-link-active"
> >
@ -29,4 +30,17 @@
</mat-selection-list> </mat-selection-list>
</mat-card-content> </mat-card-content>
</mat-card> </mat-card>
<ng-template #noTwitter>
<mat-card-content>
Unfortunately your hood admin has not configured Twitter as platform
yet.
</mat-card-content>
</ng-template>
</ng-template>
<ng-template [ngIf]="twitters.error"
><mat-icon class="warning">warning</mat-icon></ng-template
>
<ng-template [ngIf]="twitters.loading">
<mat-spinner [diameter]="45" class="spinner"></mat-spinner>
</ng-template>
</div> </div>

View file

@ -14,15 +14,16 @@
</mat-card-title> </mat-card-title>
</mat-card-header> </mat-card-header>
<mat-card-content> <mat-card-content>
<mat-list *ngIf="twitters$ | async as twitters"> <mat-list *ngIf="twitters$ | loading | async as twitters">
<mat-list-item *ngIf="(twitters | twitterCorpses).length === 0"> <ng-template [ngIf]="twitters.value">
<mat-list-item *ngIf="(twitters.value | twitterCorpses).length === 0">
<button mat-menu-item (click)="onCreate()"> <button mat-menu-item (click)="onCreate()">
<mat-icon>add</mat-icon> <mat-icon>add</mat-icon>
<span> Add a platform connection!</span> <span> Add a platform connection!</span>
</button> </button>
<mat-divider></mat-divider> <mat-divider></mat-divider>
</mat-list-item> </mat-list-item>
<mat-list-item *ngFor="let twitter of twitters | twitterCorpses"> <mat-list-item *ngFor="let twitter of twitters.value | twitterCorpses">
<div class="entry"> <div class="entry">
@{{ twitter.username }} @{{ twitter.username }}
<mat-slide-toggle <mat-slide-toggle
@ -49,6 +50,13 @@
</button> </button>
</mat-menu> </mat-menu>
</mat-list-item> </mat-list-item>
</ng-template>
<ng-template [ngIf]="twitters.error"
><mat-icon class="warning">warning</mat-icon></ng-template
>
<ng-template [ngIf]="twitters.loading">
<mat-spinner [diameter]="45" class="spinner"></mat-spinner>
</ng-template>
</mat-list> </mat-list>
</mat-card-content> </mat-card-content>
</mat-card> </mat-card>

View file

@ -1,8 +1,9 @@
<app-heading-one [title]="hood.name"></app-heading-one> <ng-container *ngIf="hood$ | async as hood">
<div class="public-margin container"> <app-heading-one [title]="hood.name"></app-heading-one>
<div class="public-margin container">
<div class="markdown"> <div class="markdown">
<markdown [data]="hood.landingpage"></markdown> <markdown [data]="hood.landingpage"></markdown>
</div> </div>
<app-platforms-info-page [hoodId]="hoodId"></app-platforms-info-page> <app-platforms-info-page [hoodId]="hoodId"></app-platforms-info-page>
</div> </div>
</ng-container>

View file

@ -10,7 +10,7 @@ import { first } from 'rxjs/operators';
}) })
export class HoodpageComponent implements OnInit { export class HoodpageComponent implements OnInit {
hoodId; hoodId;
hood: BodyHood; hood$;
constructor( constructor(
private route: ActivatedRoute, private route: ActivatedRoute,
@ -21,12 +21,7 @@ export class HoodpageComponent implements OnInit {
ngOnInit(): void { ngOnInit(): void {
this.hoodId = this.route.snapshot.params.id; this.hoodId = this.route.snapshot.params.id;
if (this.hoodId) { if (this.hoodId) {
this.hoodsService this.hood$ = this.hoodsService.getHood(this.hoodId);
.getHood(this.hoodId)
.pipe(first())
.subscribe((data) => {
this.hood = data;
});
} }
} }
} }

View file

@ -13,19 +13,20 @@
</mat-form-field> </mat-form-field>
<mat-selection-list <mat-selection-list
[multiple]="false" [multiple]="false"
*ngIf="hoods$ | async; let hoods; else: noHoods" *ngIf="hoods$ | loading | async; let hoods"
class="list" class="list"
> >
<ng-template [ngIf]="hoods.value">
<a <a
[routerLink]="['/organizers']" [routerLink]="['/organizers']"
*ngIf="(hoods | filter: searchText).length === 0" *ngIf="(hoods.value | filter: searchText).length === 0"
> >
<mat-list-option> <mat-list-option>
<p>No matching hood found. Start by creating <u>a new hood!</u></p> <p>No matching hood found. Start by creating <u>a new hood!</u></p>
</mat-list-option> </mat-list-option>
</a> </a>
<a <a
*ngFor="let hood of hoods | filter: searchText" *ngFor="let hood of hoods.value | filter: searchText"
[routerLink]="['/hoods', hood.id]" [routerLink]="['/hoods', hood.id]"
> >
<mat-list-option> <mat-list-option>
@ -33,9 +34,12 @@
<mat-divider></mat-divider> <mat-divider></mat-divider>
</mat-list-option> </mat-list-option>
</a> </a>
</mat-selection-list>
<ng-template #noHoods>
No hoods available yet. Create
<a [routerLink]="['/dashboard']">a new hood! </a>
</ng-template> </ng-template>
<ng-template [ngIf]="hoods.error"
><mat-icon class="warning">warning</mat-icon></ng-template
>
<ng-template [ngIf]="hoods.loading">
<mat-spinner [diameter]="45" class="spinner"></mat-spinner>
</ng-template>
</mat-selection-list>
</div> </div>

View file

@ -0,0 +1,8 @@
import { LoadingPipe } from './loading.pipe';
describe('LoadingPipe', () => {
it('create an instance', () => {
const pipe = new LoadingPipe();
expect(pipe).toBeTruthy();
});
});

View file

@ -0,0 +1,18 @@
import { Pipe, PipeTransform } from '@angular/core';
import { map, startWith, catchError } from 'rxjs/operators';
import { of, isObservable } from 'rxjs';
@Pipe({
name: 'loading',
})
export class LoadingPipe implements PipeTransform {
transform(val) {
return isObservable(val)
? val.pipe(
map((value: any) => ({ loading: false, value })),
startWith({ loading: true }),
catchError((error) => of({ loading: false, error }))
)
: val;
}
}

View file

@ -2,10 +2,3 @@
margin: 10%; margin: 10%;
text-align: center; text-align: center;
} }
.spinner {
display: block;
margin-left: auto;
margin-right: auto;
width: 40%;
}

View file

@ -10,6 +10,7 @@ import { YesNoDialogComponent } from './yes-no-dialog/yes-no-dialog.component';
import { OverlayComponent } from './overlay/overlay.component'; import { OverlayComponent } from './overlay/overlay.component';
import { HeadingOneComponent } from './heading-one/heading-one.component'; import { HeadingOneComponent } from './heading-one/heading-one.component';
import { FooterComponent } from './footer/footer.component'; import { FooterComponent } from './footer/footer.component';
import { LoadingPipe } from './loading-pipe/loading.pipe';
@NgModule({ @NgModule({
declarations: [ declarations: [
@ -19,6 +20,7 @@ import { FooterComponent } from './footer/footer.component';
OverlayComponent, OverlayComponent,
HeadingOneComponent, HeadingOneComponent,
FooterComponent, FooterComponent,
LoadingPipe,
], ],
imports: [ imports: [
MaterialModule, MaterialModule,
@ -33,6 +35,7 @@ import { FooterComponent } from './footer/footer.component';
NotFoundComponent, NotFoundComponent,
HeadingOneComponent, HeadingOneComponent,
FooterComponent, FooterComponent,
LoadingPipe,
MaterialModule, MaterialModule,
ReactiveFormsModule, ReactiveFormsModule,
FormsModule, FormsModule,

View file

@ -74,3 +74,16 @@ a {
} }
/* public pages end */ /* public pages end */
.spinner {
display: block;
margin-left: auto;
margin-right: auto;
width: 40%;
}
.warning {
color: red;
text-align: center;
min-width: 100%;
}