Skip to content

Commit 3f40626

Browse files
committed
Angular NgRx Course
1 parent d29a704 commit 3f40626

File tree

5 files changed

+39
-2
lines changed

5 files changed

+39
-2
lines changed

server/get-courses.route.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@ export function getAllCourses(req: Request, res: Response) {
99

1010
console.log("Retrieving courses data ...");
1111

12-
res.status(200).json({payload:Object.values(COURSES)});
12+
setTimeout(() => {
13+
14+
res.status(200).json({payload:Object.values(COURSES)});
15+
16+
}, 1000);
1317

1418
}
1519

src/app/app.component.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,8 @@ main {
1515
outline:none;
1616
}
1717

18+
19+
.spinner-container {
20+
width: 100%;
21+
margin-top: 100px;
22+
}

src/app/app.component.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@
2828
</button>
2929
</mat-toolbar>
3030

31+
<div class="spinner-container" *ngIf="loading">
32+
33+
<mat-spinner></mat-spinner>
34+
35+
</div>
36+
3137
<router-outlet></router-outlet>
3238

3339
</mat-sidenav-container>

src/app/app.component.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {select, Store} from "@ngrx/store";
33
import {Observable} from "rxjs";
44
import {map} from 'rxjs/operators';
55
import {isLoggedIn, isLoggedOut} from './auth/auth.selectors';
6-
import {Router} from '@angular/router';
6+
import {NavigationCancel, NavigationEnd, NavigationError, NavigationStart, Router} from '@angular/router';
77
import {logout} from './auth/auth.actions';
88
import {AppState} from './reducers/reducers';
99

@@ -18,13 +18,33 @@ export class AppComponent implements OnInit {
1818

1919
isLoggedOut$: Observable<boolean>;
2020

21+
loading = true;
2122

2223
constructor(private store: Store<AppState>, private router: Router) {
2324

2425
}
2526

2627
ngOnInit() {
2728

29+
this.router.events.subscribe(event => {
30+
switch (true) {
31+
case event instanceof NavigationStart: {
32+
this.loading = true;
33+
break;
34+
}
35+
36+
case event instanceof NavigationEnd:
37+
case event instanceof NavigationCancel:
38+
case event instanceof NavigationError: {
39+
this.loading = false;
40+
break;
41+
}
42+
default: {
43+
break;
44+
}
45+
}
46+
});
47+
2848
this.isLoggedIn$ = this.store
2949
.pipe(
3050
select(isLoggedIn)

src/app/app.module.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {EffectsModule} from '@ngrx/effects';
2222
import {AuthGuard} from './auth/auth.guard';
2323
import {EntityDataModule} from '@ngrx/data';
2424
import {reducers} from './reducers/reducers';
25+
import {MatProgressSpinnerModule} from '@angular/material';
2526

2627

2728
const routes: Routes = [
@@ -50,6 +51,7 @@ const routes: Routes = [
5051
MatMenuModule,
5152
MatIconModule,
5253
MatSidenavModule,
54+
MatProgressSpinnerModule,
5355
MatListModule,
5456
MatToolbarModule,
5557
AuthModule.forRoot(),

0 commit comments

Comments
 (0)