@tech4good/angular-schematics 13.5.0 → 13.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (115) hide show
  1. package/package.json +1 -1
  2. package/src/component/files/__name@dasherize__/__name@dasherize__.component.ts.template +8 -8
  3. package/src/container/files/__name@dasherize__/+state/__name@dasherize__.actions.ts.template +3 -2
  4. package/src/container/files/__name@dasherize__/+state/__name@dasherize__.effects.ts.template +6 -5
  5. package/src/container/files/__name@dasherize__/+state/__name@dasherize__.selectors.ts.template +2 -2
  6. package/src/container/files/__name@dasherize__/__name@dasherize__.component.ts.template +25 -14
  7. package/src/container/index.js +13 -2
  8. package/src/container/index.js.map +1 -1
  9. package/src/entity/files/__name@dasherize__/__name@dasherize__.actions.ts.template +9 -30
  10. package/src/entity/files/__name@dasherize__/__name@dasherize__.effects.ts.template +23 -24
  11. package/src/init/files/.github/workflows/angular-github-ci.yml.template +1 -2
  12. package/src/init/files/package.json.template +3 -1
  13. package/src/init/files/src/app/admin/admin-routing.module.ts.template +17 -0
  14. package/src/init/files/src/app/admin/admin.module.spec.ts.template +13 -0
  15. package/src/init/files/src/app/admin/admin.module.ts.template +28 -0
  16. package/src/init/files/src/app/admin/waitlist/+state/waitlist.actions.ts.template +23 -0
  17. package/src/init/files/src/app/admin/waitlist/+state/waitlist.effects.ts.template +50 -0
  18. package/src/init/files/src/app/admin/waitlist/+state/waitlist.selectors.ts.template +39 -0
  19. package/src/init/files/src/app/admin/waitlist/+state/waitlist.state.ts.template +13 -0
  20. package/src/init/files/src/app/admin/waitlist/waitlist.animations.ts.template +4 -0
  21. package/src/init/files/src/app/admin/waitlist/waitlist.component.html.template +30 -0
  22. package/src/init/files/src/app/admin/waitlist/waitlist.component.scss.template +14 -0
  23. package/src/init/files/src/app/admin/waitlist/waitlist.component.spec.ts.template +25 -0
  24. package/src/init/files/src/app/admin/waitlist/waitlist.component.ts.template +136 -0
  25. package/src/init/files/src/app/app-routing.module.ts.template +13 -5
  26. package/src/init/files/src/app/app.component.html.template +1 -0
  27. package/src/init/files/src/app/app.component.scss.template +7 -0
  28. package/src/init/files/src/app/app.component.ts.template +5 -0
  29. package/src/init/files/src/app/core/analytics/log.service.ts.template +89 -4
  30. package/src/init/files/src/app/core/analytics/time-analytics.service.ts.template +204 -69
  31. package/src/init/files/src/app/core/auth/auth.guard.ts.template +85 -0
  32. package/src/init/files/src/app/core/core.module.ts.template +4 -0
  33. package/src/init/files/src/app/core/firebase/firebase.service.ts.template +4 -4
  34. package/src/init/files/src/app/core/local-storage/local-storage.service.ts.template +47 -0
  35. package/src/init/files/src/app/core/local-storage/session-local-storage.service.ts.template +67 -0
  36. package/src/init/files/src/app/core/local-storage/session.service.ts.template +48 -0
  37. package/src/init/files/src/app/core/store/app-state/app-state.actions.ts.template +270 -0
  38. package/src/init/files/src/app/core/store/app-state/app-state.effects.ts.template +131 -0
  39. package/src/init/files/src/app/core/store/app-state/app-state.model.ts.template +8 -0
  40. package/src/init/files/src/app/core/store/app-state/app-state.reducer.spec.ts.template +13 -0
  41. package/src/init/files/src/app/core/store/app-state/app-state.reducer.ts.template +51 -0
  42. package/src/init/files/src/app/core/store/app-state/app-state.service.ts.template +50 -0
  43. package/src/init/files/src/app/core/store/app.effects.ts.template +10 -2
  44. package/src/init/files/src/app/core/store/app.reducer.ts.template +6 -0
  45. package/src/init/files/src/app/core/store/app.selectors.ts.template +12 -0
  46. package/src/init/files/src/app/core/store/auth/auth.actions.ts.template +3 -1
  47. package/src/init/files/src/app/core/store/auth/auth.effects.ts.template +27 -31
  48. package/src/init/files/src/app/core/store/auth/auth.reducer.ts.template +1 -1
  49. package/src/init/files/src/app/core/store/auth/auth.selectors.ts.template +5 -1
  50. package/src/init/files/src/app/core/store/cached-load-connections.service.ts.template +9 -8
  51. package/src/init/files/src/app/core/store/user/user.model.ts.template +14 -0
  52. package/src/init/files/src/app/core/store/user-context/user-context.actions.ts.template +270 -0
  53. package/src/init/files/src/app/core/store/user-context/user-context.effects.ts.template +131 -0
  54. package/src/init/files/src/app/core/store/user-context/user-context.model.ts.template +13 -0
  55. package/src/init/files/src/app/core/store/user-context/user-context.reducer.spec.ts.template +13 -0
  56. package/src/init/files/src/app/core/store/user-context/user-context.reducer.ts.template +51 -0
  57. package/src/init/files/src/app/core/store/user-context/user-context.service.ts.template +50 -0
  58. package/src/init/files/src/app/general/general-routing.module.ts.template +6 -2
  59. package/src/init/files/src/app/general/general.module.ts.template +8 -2
  60. package/src/init/files/src/app/general/home/+state/home.actions.ts.template +26 -0
  61. package/src/init/files/src/app/general/home/+state/home.effects.ts.template +48 -0
  62. package/src/init/files/src/app/general/home/+state/home.model.ts.template +0 -0
  63. package/src/init/files/src/app/general/home/+state/home.selectors.ts.template +20 -0
  64. package/src/init/files/src/app/general/home/+state/home.state.ts.template +13 -0
  65. package/src/init/files/src/app/general/home/home.animations.ts.template +4 -0
  66. package/src/init/files/src/app/general/home/home.component.html.template +5 -0
  67. package/src/init/files/src/app/general/home/home.component.scss.template +5 -0
  68. package/src/init/files/src/app/general/{e404/e404.component.spec.ts.template → home/home.component.spec.ts.template} +6 -6
  69. package/src/init/files/src/app/general/home/home.component.ts.template +88 -0
  70. package/src/init/files/src/app/general/landing/+state/landing.actions.ts.template +26 -0
  71. package/src/init/files/src/app/general/landing/+state/landing.effects.ts.template +48 -0
  72. package/src/init/files/src/app/general/landing/+state/landing.model.ts.template +0 -0
  73. package/src/init/files/src/app/general/landing/+state/landing.selectors.ts.template +20 -0
  74. package/src/init/files/src/app/general/landing/+state/landing.state.ts.template +13 -0
  75. package/src/init/files/src/app/general/landing/landing.animations.ts.template +4 -0
  76. package/src/init/files/src/app/general/landing/landing.component.html.template +3 -0
  77. package/src/init/files/src/app/general/landing/landing.component.scss.template +13 -0
  78. package/src/init/files/src/app/general/landing/landing.component.spec.ts.template +25 -0
  79. package/src/init/files/src/app/general/landing/landing.component.ts.template +98 -0
  80. package/src/init/files/src/app/general/login/login.component.html.template +5 -5
  81. package/src/init/files/src/app/general/login/login.component.ts.template +12 -4
  82. package/src/init/files/src/app/onboarding/consent/+state/consent.actions.ts.template +23 -0
  83. package/src/init/files/src/app/onboarding/consent/+state/consent.effects.ts.template +47 -0
  84. package/src/init/files/src/app/onboarding/consent/+state/consent.model.ts.template +0 -0
  85. package/src/init/files/src/app/onboarding/consent/+state/consent.selectors.ts.template +20 -0
  86. package/src/init/files/src/app/onboarding/consent/+state/consent.state.ts.template +13 -0
  87. package/src/init/files/src/app/onboarding/consent/consent.animations.ts.template +4 -0
  88. package/src/init/files/src/app/onboarding/consent/consent.component.html.template +61 -0
  89. package/src/init/files/src/app/onboarding/consent/consent.component.scss.template +77 -0
  90. package/src/init/files/src/app/onboarding/consent/consent.component.spec.ts.template +25 -0
  91. package/src/init/files/src/app/onboarding/consent/consent.component.ts.template +152 -0
  92. package/src/init/files/src/app/onboarding/onboarding-routing.module.ts.template +19 -0
  93. package/src/init/files/src/app/onboarding/onboarding.module.spec.ts.template +13 -0
  94. package/src/init/files/src/app/onboarding/onboarding.module.ts.template +32 -0
  95. package/src/init/files/src/app/onboarding/waiting/+state/waiting.actions.ts.template +26 -0
  96. package/src/init/files/src/app/onboarding/waiting/+state/waiting.effects.ts.template +52 -0
  97. package/src/init/files/src/app/onboarding/waiting/+state/waiting.model.ts.template +9 -0
  98. package/src/init/files/src/app/onboarding/waiting/+state/waiting.selectors.ts.template +42 -0
  99. package/src/init/files/src/app/onboarding/waiting/+state/waiting.state.ts.template +13 -0
  100. package/src/init/files/src/app/onboarding/waiting/waiting.animations.ts.template +4 -0
  101. package/src/init/files/src/app/onboarding/waiting/waiting.component.html.template +57 -0
  102. package/src/init/files/src/app/onboarding/waiting/waiting.component.scss.template +99 -0
  103. package/src/init/files/src/app/onboarding/waiting/waiting.component.spec.ts.template +25 -0
  104. package/src/init/files/src/app/onboarding/waiting/waiting.component.ts.template +279 -0
  105. package/src/init/files/src/app/shared/components/redeployment-warning/redeployment-warning.component.html.template +10 -0
  106. package/src/init/files/src/app/shared/components/redeployment-warning/redeployment-warning.component.scss.template +46 -0
  107. package/src/init/files/src/app/shared/components/redeployment-warning/redeployment-warning.component.spec.ts.template +24 -0
  108. package/src/init/files/src/app/shared/components/redeployment-warning/redeployment-warning.component.ts.template +29 -0
  109. package/src/init/files/src/app/shared/components/redeployment-warning/redeployment-warning.service.ts.template +63 -0
  110. package/src/init/files/src/app/shared/shared.module.ts.template +6 -0
  111. package/src/init/files/src/index.html.template +0 -3
  112. package/src/module/files/__name@dasherize__/__name@dasherize__-routing.module.ts.template +2 -0
  113. package/src/init/files/src/app/general/e404/e404.component.html.template +0 -1
  114. package/src/init/files/src/app/general/e404/e404.component.ts.template +0 -28
  115. /package/src/init/files/src/app/{general/e404/e404.component.scss.template → admin/waitlist/+state/waitlist.model.ts.template} +0 -0
@@ -0,0 +1,50 @@
1
+ import { Injectable } from '@angular/core';
2
+ import { Observable } from 'rxjs';
3
+ import { CachedSelectorsService } from '../cached-selectors.service';
4
+ import { FirebaseService } from '../../firebase/firebase.service';
5
+ import { UserContext } from './user-context.model';
6
+
7
+ @Injectable({
8
+ providedIn: 'root',
9
+ })
10
+ export class UserContextService {
11
+ constructor(
12
+ private cs: CachedSelectorsService,
13
+ private db: FirebaseService,
14
+ ) { }
15
+
16
+ /** Select a userContext from the store. */
17
+ public selectUserContext = <T extends UserContext>(
18
+ id: string,
19
+ correlationId: string,
20
+ childrenFn?: (e: UserContext) => { [index: string]: Observable<any> },
21
+ ): Observable<T> => {
22
+ return this.cs.selectEntityObj<UserContext, T>('userContext', id, correlationId, childrenFn);
23
+ };
24
+
25
+ /** Select userContexts from the store. */
26
+ public selectUserContexts = <T extends UserContext>(
27
+ queryParams: [string, string, any][],
28
+ correlationId: string,
29
+ childrenFn?: (e: UserContext) => { [index: string]: Observable<any> },
30
+ ): Observable<Array<T>> => {
31
+ return this.cs.selectEntityList<UserContext, T>('userContext', queryParams, correlationId, childrenFn);
32
+ };
33
+
34
+ /** Get a userContext directly from the database. */
35
+ public getUserContext = <T extends UserContext>(
36
+ id: string,
37
+ childrenFn?: (e: UserContext) => { [index: string]: Observable<any> },
38
+ ): Observable<T> => {
39
+ return this.db.queryObjOnce<UserContext, T>('userContexts', id, childrenFn);
40
+ };
41
+
42
+ /** Get userContexts directly from the database. */
43
+ public getUserContexts = <T extends UserContext>(
44
+ queryParams: [string, string, any][],
45
+ queryOptions?: { [index: string]: any },
46
+ childrenFn?: (e: UserContext) => { [index: string]: Observable<any> },
47
+ ): Observable<Array<T>> => {
48
+ return this.db.queryListOnce<UserContext, T>('userContexts', queryParams, queryOptions, childrenFn);
49
+ };
50
+ }
@@ -1,12 +1,16 @@
1
1
  import { NgModule } from '@angular/core';
2
2
  import { Routes, RouterModule } from '@angular/router';
3
+ import { AuthGuard } from '../core/auth/auth.guard';
3
4
 
4
5
  // Containers
5
- import { E404Component } from './e404/e404.component';
6
+ import { HomeComponent } from './home/home.component';
7
+ import { LandingComponent } from './landing/landing.component';
6
8
  import { LoginComponent } from './login/login.component';
7
9
 
8
10
  const routes: Routes = [
9
- { path: '404', component: E404Component },
11
+ { path: 'home', component: HomeComponent, canActivate: [AuthGuard] },
12
+ { path: 'landing', component: LandingComponent, canActivate: [AuthGuard] },
13
+ // We intentionally do not add an AuthGuard here so you can always navigate there
10
14
  { path: 'login', component: LoginComponent },
11
15
  ];
12
16
 
@@ -5,7 +5,10 @@ import { SharedModule } from '../shared/shared.module';
5
5
  import { GeneralRoutingModule } from './general-routing.module';
6
6
 
7
7
  // Containers
8
- import { E404Component } from './e404/e404.component';
8
+ import { HomeComponent } from './home/home.component';
9
+ import { HomeEffects } from './home/+state/home.effects';
10
+ import { LandingComponent } from './landing/landing.component';
11
+ import { LandingEffects } from './landing/+state/landing.effects';
9
12
  import { LoginComponent } from './login/login.component';
10
13
 
11
14
  // Components
@@ -16,11 +19,14 @@ import { LoginComponent } from './login/login.component';
16
19
  SharedModule,
17
20
  GeneralRoutingModule,
18
21
  EffectsModule.forFeature([
22
+ HomeEffects,
23
+ LandingEffects,
19
24
  ]),
20
25
  ],
21
26
  declarations: [
22
27
  // Containers
23
- E404Component,
28
+ HomeComponent,
29
+ LandingComponent,
24
30
  LoginComponent,
25
31
  // Components
26
32
  ],
@@ -0,0 +1,26 @@
1
+ import { Action } from '@ngrx/store';
2
+ import { User } from '../../../core/store/user/user.model';
3
+
4
+ export enum HomeActionTypes {
5
+ LOAD_DATA = '[Home] load data',
6
+ CLEANUP = '[Home] cleanup',
7
+ }
8
+
9
+ /** Action for loading required DB data. */
10
+ export class LoadData implements Action {
11
+ readonly type = HomeActionTypes.LOAD_DATA;
12
+
13
+ constructor(public payload: {
14
+ currentUser: User,
15
+ }, public correlationId: string) { }
16
+ }
17
+
18
+ /** Action for cleaning up loading subscriptions. */
19
+ export class Cleanup implements Action {
20
+ readonly type = HomeActionTypes.CLEANUP;
21
+ constructor(public correlationId: string) { }
22
+ }
23
+
24
+ export type HomeActions =
25
+ LoadData |
26
+ Cleanup;
@@ -0,0 +1,48 @@
1
+ import { Injectable } from '@angular/core';
2
+ import { Action } from '@ngrx/store';
3
+ import { Actions, createEffect, ofType } from '@ngrx/effects';
4
+
5
+ import { of, Observable } from 'rxjs';
6
+ import { mergeMap, tap, map } from 'rxjs/operators';
7
+
8
+ import { select, Store } from '@ngrx/store';
9
+ import * as fromStore from '../../../core/store/app.reducer';
10
+ import { FirebaseService } from '../../../core/firebase/firebase.service';
11
+ import { EffectsHelpers } from '../../../core/store/effects.helpers';
12
+ import { HomeState } from './home.state';
13
+
14
+ import { ActionFlow, RouterNavigate, LoadAction, Unsubscribe } from '../../../core/store/app.actions';
15
+ import { HomeActionTypes, Cleanup, LoadData } from './home.actions';
16
+
17
+ @Injectable()
18
+ export class HomeEffects {
19
+ /** Load data from Firebase. */
20
+ loadData$: Observable<Action> = createEffect(
21
+ () => this.actions$.pipe(
22
+ ofType<LoadData>(HomeActionTypes.LOAD_DATA),
23
+ mergeMap((action: LoadData) => {
24
+ const loadId = action.correlationId;
25
+ const currentUser = action.payload.currentUser;
26
+
27
+ return [
28
+ ];
29
+ }),
30
+ ),
31
+ );
32
+
33
+ /** Unsubscribe connections from Firebase. */
34
+ cleanup$: Observable<Action> = createEffect(
35
+ () => this.actions$.pipe(
36
+ ofType<Cleanup>(HomeActionTypes.CLEANUP),
37
+ map((action: Cleanup) => new Unsubscribe(action.correlationId)),
38
+ ),
39
+ );
40
+
41
+ constructor(
42
+ private actions$: Actions,
43
+ private store: Store<fromStore.State>,
44
+ private state: HomeState,
45
+ private db: FirebaseService,
46
+ private eh: EffectsHelpers,
47
+ ) {}
48
+ }
@@ -0,0 +1,20 @@
1
+ import { Injectable } from '@angular/core';
2
+ import { Store, select } from '@ngrx/store';
3
+ import * as fromStore from '../../../core/store/app.reducer';
4
+ import { EntitySelectorService } from '../../../core/store/app.selectors';
5
+
6
+ import { Observable, of, combineLatest } from 'rxjs';
7
+ import { bufferTime, distinctUntilChanged, shareReplay, mergeMap, filter, switchMap, map } from 'rxjs/operators';
8
+
9
+ @Injectable({
10
+ providedIn: 'root',
11
+ })
12
+ export class HomeSelectors {
13
+ constructor(
14
+ private slRx: EntitySelectorService,
15
+ ) { }
16
+
17
+ cleanup(cId: string) {
18
+ this.slRx.release(cId);
19
+ }
20
+ }
@@ -0,0 +1,13 @@
1
+ import { Injectable } from '@angular/core';
2
+
3
+ import { BehaviorSubject } from 'rxjs';
4
+
5
+ @Injectable({
6
+ providedIn: 'root',
7
+ })
8
+ export class HomeState {
9
+ // --------------- LOCAL UI STATE ----------------------
10
+
11
+ constructor(
12
+ ) { }
13
+ }
@@ -0,0 +1,4 @@
1
+ import { trigger, group, query, animateChild, state, style, animate, transition } from '@angular/animations';
2
+
3
+ export const HomeAnimations = [
4
+ ];
@@ -0,0 +1,5 @@
1
+ <div class="home-container">
2
+ <ng-container *ngIf="currentUser$ | async as user">
3
+ {{ user.name }}
4
+ </ng-container>
5
+ </div>
@@ -0,0 +1,5 @@
1
+ :host {
2
+ display: block;
3
+ .home-container {
4
+ }
5
+ }
@@ -1,20 +1,20 @@
1
1
  import { waitForAsync, ComponentFixture, TestBed } from '@angular/core/testing';
2
2
 
3
- import { E404Component } from './e404.component';
3
+ import { HomeComponent } from './home.component';
4
4
 
5
- describe('E404Component', () => {
6
- let component: E404Component;
7
- let fixture: ComponentFixture<E404Component>;
5
+ describe('HomeComponent', () => {
6
+ let component: HomeComponent;
7
+ let fixture: ComponentFixture<HomeComponent>;
8
8
 
9
9
  beforeEach(waitForAsync(() => {
10
10
  TestBed.configureTestingModule({
11
- declarations: [E404Component],
11
+ declarations: [HomeComponent],
12
12
  })
13
13
  .compileComponents();
14
14
  }));
15
15
 
16
16
  beforeEach(() => {
17
- fixture = TestBed.createComponent(E404Component);
17
+ fixture = TestBed.createComponent(HomeComponent);
18
18
  component = fixture.componentInstance;
19
19
  fixture.detectChanges();
20
20
  });
@@ -0,0 +1,88 @@
1
+ import { Component, OnInit, OnDestroy, ChangeDetectionStrategy } from '@angular/core';
2
+ import { HomeAnimations } from './home.animations';
3
+ import { ParamMap, ActivatedRoute } from '@angular/router';
4
+ import { Store, select } from '@ngrx/store';
5
+ import * as fromStore from '../../core/store/app.reducer';
6
+ import * as fromAuth from '../../core/store/auth/auth.reducer';
7
+ import { FirebaseService } from '../../core/firebase/firebase.service';
8
+ import { Observable, Subject, BehaviorSubject, combineLatest } from 'rxjs';
9
+ import { withLatestFrom, filter, take, takeUntil } from 'rxjs/operators';
10
+
11
+ import { HomeState } from './+state/home.state';
12
+ import { HomeSelectors } from './+state/home.selectors';
13
+
14
+ import { LoadData, Cleanup } from './+state/home.actions';
15
+ import { RouterNavigate } from '../../core/store/app.actions';
16
+
17
+ import { User } from '../../core/store/user/user.model';
18
+
19
+ @Component({
20
+ selector: 'app-home',
21
+ templateUrl: './home.component.html',
22
+ styleUrls: ['./home.component.scss'],
23
+ changeDetection: ChangeDetectionStrategy.OnPush,
24
+ animations: HomeAnimations,
25
+ })
26
+ export class HomeComponent implements OnInit, OnDestroy {
27
+ // --------------- ROUTE PARAMS & CURRENT USER ---------
28
+
29
+ /** The currently signed in user. */
30
+ currentUser$: Observable<User> = this.store.pipe(
31
+ select(fromAuth.selectUser),
32
+ filter((user) => user !== null), // null indicates LoadAuth hasn't been processed
33
+ );
34
+
35
+ // --------------- LOCAL AND GLOBAL STATE --------------
36
+
37
+
38
+ // --------------- DB ENTITY DATA ----------------------
39
+
40
+ /** Container id for selectors and loading. */
41
+ containerId: string = this.db.createId();
42
+
43
+ // --------------- DATA BINDING ------------------------
44
+
45
+
46
+ // --------------- EVENT BINDING -----------------------
47
+
48
+
49
+ // --------------- HELPER FUNCTIONS AND OTHER ----------
50
+
51
+ /** Unsubscribe observable for subscriptions. */
52
+ unsubscribe$: Subject<void> = new Subject();
53
+
54
+ constructor(
55
+ private state: HomeState,
56
+ private route: ActivatedRoute,
57
+ private selectors: HomeSelectors,
58
+ private store: Store<fromStore.State>,
59
+ private db: FirebaseService,
60
+ ) {
61
+ }
62
+
63
+ ngOnInit() {
64
+ // --------------- EVENT HANDLING ----------------------
65
+
66
+
67
+ // --------------- LOAD DATA ---------------------------
68
+
69
+ // Once everything is set up, load the data for the role.
70
+ this.currentUser$.pipe(
71
+ takeUntil(this.unsubscribe$),
72
+ ).subscribe((currentUser) => {
73
+ this.store.dispatch( new LoadData({
74
+ currentUser,
75
+ }, this.containerId) );
76
+ });
77
+ }
78
+
79
+ ngOnDestroy() {
80
+ // Unsubscribe subscriptions.
81
+ this.unsubscribe$.next();
82
+ this.unsubscribe$.complete();
83
+
84
+ // Unsubscribe from firebase connection from load and free up memoized selector values.
85
+ this.store.dispatch( new Cleanup(this.containerId) );
86
+ this.selectors.cleanup(this.containerId);
87
+ }
88
+ }
@@ -0,0 +1,26 @@
1
+ import { Action } from '@ngrx/store';
2
+ import { User } from '../../../core/store/user/user.model';
3
+
4
+ export enum LandingActionTypes {
5
+ LOAD_DATA = '[Landing] load data',
6
+ CLEANUP = '[Landing] cleanup',
7
+ }
8
+
9
+ /** Action for loading required DB data. */
10
+ export class LoadData implements Action {
11
+ readonly type = LandingActionTypes.LOAD_DATA;
12
+
13
+ constructor(public payload: {
14
+ currentUser: User,
15
+ }, public correlationId: string) { }
16
+ }
17
+
18
+ /** Action for cleaning up loading subscriptions. */
19
+ export class Cleanup implements Action {
20
+ readonly type = LandingActionTypes.CLEANUP;
21
+ constructor(public correlationId: string) { }
22
+ }
23
+
24
+ export type LandingActions =
25
+ LoadData |
26
+ Cleanup;
@@ -0,0 +1,48 @@
1
+ import { Injectable } from '@angular/core';
2
+ import { Action } from '@ngrx/store';
3
+ import { Actions, createEffect, ofType } from '@ngrx/effects';
4
+
5
+ import { of, Observable } from 'rxjs';
6
+ import { mergeMap, tap, map } from 'rxjs/operators';
7
+
8
+ import { select, Store } from '@ngrx/store';
9
+ import * as fromStore from '../../../core/store/app.reducer';
10
+ import { FirebaseService } from '../../../core/firebase/firebase.service';
11
+ import { EffectsHelpers } from '../../../core/store/effects.helpers';
12
+ import { LandingState } from './landing.state';
13
+
14
+ import { ActionFlow, RouterNavigate, LoadAction, Unsubscribe } from '../../../core/store/app.actions';
15
+ import { LandingActionTypes, Cleanup, LoadData } from './landing.actions';
16
+
17
+ @Injectable()
18
+ export class LandingEffects {
19
+ /** Load data from Firebase. */
20
+ loadData$: Observable<Action> = createEffect(
21
+ () => this.actions$.pipe(
22
+ ofType<LoadData>(LandingActionTypes.LOAD_DATA),
23
+ mergeMap((action: LoadData) => {
24
+ const loadId = action.correlationId;
25
+ const currentUser = action.payload.currentUser;
26
+
27
+ return [
28
+ ];
29
+ }),
30
+ ),
31
+ );
32
+
33
+ /** Unsubscribe connections from Firebase. */
34
+ cleanup$: Observable<Action> = createEffect(
35
+ () => this.actions$.pipe(
36
+ ofType<Cleanup>(LandingActionTypes.CLEANUP),
37
+ map((action: Cleanup) => new Unsubscribe(action.correlationId)),
38
+ ),
39
+ );
40
+
41
+ constructor(
42
+ private actions$: Actions,
43
+ private store: Store<fromStore.State>,
44
+ private state: LandingState,
45
+ private db: FirebaseService,
46
+ private eh: EffectsHelpers,
47
+ ) {}
48
+ }
@@ -0,0 +1,20 @@
1
+ import { Injectable } from '@angular/core';
2
+ import { Store, select } from '@ngrx/store';
3
+ import * as fromStore from '../../../core/store/app.reducer';
4
+ import { EntitySelectorService } from '../../../core/store/app.selectors';
5
+
6
+ import { Observable, of, combineLatest } from 'rxjs';
7
+ import { bufferTime, distinctUntilChanged, shareReplay, mergeMap, filter, switchMap, map } from 'rxjs/operators';
8
+
9
+ @Injectable({
10
+ providedIn: 'root',
11
+ })
12
+ export class LandingSelectors {
13
+ constructor(
14
+ private slRx: EntitySelectorService,
15
+ ) { }
16
+
17
+ cleanup(cId: string) {
18
+ this.slRx.release(cId);
19
+ }
20
+ }
@@ -0,0 +1,13 @@
1
+ import { Injectable } from '@angular/core';
2
+
3
+ import { BehaviorSubject } from 'rxjs';
4
+
5
+ @Injectable({
6
+ providedIn: 'root',
7
+ })
8
+ export class LandingState {
9
+ // --------------- LOCAL UI STATE ----------------------
10
+
11
+ constructor(
12
+ ) { }
13
+ }
@@ -0,0 +1,4 @@
1
+ import { trigger, group, query, animateChild, state, style, animate, transition } from '@angular/animations';
2
+
3
+ export const LandingAnimations = [
4
+ ];
@@ -0,0 +1,3 @@
1
+ <div class="landing-container">
2
+ <input type="submit" value="Sign up for early access" (click)="login$.next()">
3
+ </div>
@@ -0,0 +1,13 @@
1
+ :host {
2
+ display: block;
3
+ .landing-container {
4
+ input {
5
+ margin-top: 30px;
6
+ height: 42px;
7
+ background: #FAFAFA;
8
+ border: 1px solid #E1E1E1;
9
+ box-sizing: border-box;
10
+ border-radius: 4px;
11
+ }
12
+ }
13
+ }
@@ -0,0 +1,25 @@
1
+ import { waitForAsync, ComponentFixture, TestBed } from '@angular/core/testing';
2
+
3
+ import { LandingComponent } from './landing.component';
4
+
5
+ describe('LandingComponent', () => {
6
+ let component: LandingComponent;
7
+ let fixture: ComponentFixture<LandingComponent>;
8
+
9
+ beforeEach(waitForAsync(() => {
10
+ TestBed.configureTestingModule({
11
+ declarations: [LandingComponent],
12
+ })
13
+ .compileComponents();
14
+ }));
15
+
16
+ beforeEach(() => {
17
+ fixture = TestBed.createComponent(LandingComponent);
18
+ component = fixture.componentInstance;
19
+ fixture.detectChanges();
20
+ });
21
+
22
+ it('should create', () => {
23
+ expect(component).toBeTruthy();
24
+ });
25
+ });
@@ -0,0 +1,98 @@
1
+ import { Component, OnInit, OnDestroy, ChangeDetectionStrategy } from '@angular/core';
2
+ import { LandingAnimations } from './landing.animations';
3
+ import { ParamMap, ActivatedRoute } from '@angular/router';
4
+ import { Store, select } from '@ngrx/store';
5
+ import * as fromStore from '../../core/store/app.reducer';
6
+ import * as fromAuth from '../../core/store/auth/auth.reducer';
7
+ import { FirebaseService } from '../../core/firebase/firebase.service';
8
+ import { Observable, Subject, BehaviorSubject, combineLatest } from 'rxjs';
9
+ import { withLatestFrom, filter, take, takeUntil } from 'rxjs/operators';
10
+
11
+ import { LandingState } from './+state/landing.state';
12
+ import { LandingSelectors } from './+state/landing.selectors';
13
+
14
+ import { LoadData, Cleanup } from './+state/landing.actions';
15
+ import { RouterNavigate } from '../../core/store/app.actions';
16
+
17
+ import { User } from '../../core/store/user/user.model';
18
+ import { Login } from '../../core/store/auth/auth.actions';
19
+
20
+ @Component({
21
+ selector: 'app-landing',
22
+ templateUrl: './landing.component.html',
23
+ styleUrls: ['./landing.component.scss'],
24
+ changeDetection: ChangeDetectionStrategy.OnPush,
25
+ animations: LandingAnimations,
26
+ })
27
+ export class LandingComponent implements OnInit, OnDestroy {
28
+ // --------------- ROUTE PARAMS & CURRENT USER ---------
29
+
30
+ /** The currently signed in user. */
31
+ currentUser$: Observable<User> = this.store.pipe(
32
+ select(fromAuth.selectUser),
33
+ filter((user) => user !== null), // null indicates LoadAuth hasn't been processed
34
+ );
35
+
36
+ // --------------- LOCAL AND GLOBAL STATE --------------
37
+
38
+
39
+ // --------------- DB ENTITY DATA ----------------------
40
+
41
+ /** Container id for selectors and loading. */
42
+ containerId: string = this.db.createId();
43
+
44
+ // --------------- DATA BINDING ------------------------
45
+
46
+
47
+ // --------------- EVENT BINDING -----------------------
48
+
49
+ /** Login click events. */
50
+ login$: Subject<void> = new Subject<void>();
51
+
52
+
53
+ // --------------- HELPER FUNCTIONS AND OTHER ----------
54
+
55
+ /** Unsubscribe observable for subscriptions. */
56
+ unsubscribe$: Subject<void> = new Subject();
57
+
58
+ constructor(
59
+ private state: LandingState,
60
+ private route: ActivatedRoute,
61
+ private selectors: LandingSelectors,
62
+ private store: Store<fromStore.State>,
63
+ private db: FirebaseService,
64
+ ) {
65
+ }
66
+
67
+ ngOnInit() {
68
+ // --------------- EVENT HANDLING ----------------------
69
+
70
+ /** Handle login events. */
71
+ this.login$.pipe(
72
+ takeUntil(this.unsubscribe$),
73
+ ).subscribe(() => {
74
+ this.store.dispatch(new Login({ provider: 'google.com' }));
75
+ });
76
+
77
+ // --------------- LOAD DATA ---------------------------
78
+
79
+ // Once everything is set up, load the data for the role.
80
+ this.currentUser$.pipe(
81
+ takeUntil(this.unsubscribe$),
82
+ ).subscribe((currentUser) => {
83
+ this.store.dispatch( new LoadData({
84
+ currentUser,
85
+ }, this.containerId) );
86
+ });
87
+ }
88
+
89
+ ngOnDestroy() {
90
+ // Unsubscribe subscriptions.
91
+ this.unsubscribe$.next();
92
+ this.unsubscribe$.complete();
93
+
94
+ // Unsubscribe from firebase connection from load and free up memoized selector values.
95
+ this.store.dispatch( new Cleanup(this.containerId) );
96
+ this.selectors.cleanup(this.containerId);
97
+ }
98
+ }
@@ -1,10 +1,10 @@
1
- <div class="login-container">
2
- <ng-container *ngIf="currentUser$ | async as user">
3
- <img class="profile" [src]="user.photoURL" />
4
- <h2>Hello {{user.name}}!</h2>
1
+ <div class="login-container" *ngIf="{ user: currentUser$ | async } as data">
2
+ <ng-container *ngIf="data.user">
3
+ <img class="profile" [src]="data.user.photoURL" referrerpolicy="no-referrer"/>
4
+ <h2>Hello {{data.user.name}}!</h2>
5
5
  <input type="submit" value="Logout" (click)="logout$.next()">
6
6
  </ng-container>
7
- <ng-container *ngIf="(currentUser$ | async) === null">
7
+ <ng-container *ngIf="!data.user">
8
8
  <h2>Hello!</h2>
9
9
  <input type="submit" value="Login" (click)="login$.next()">
10
10
  </ng-container>