@tech4good/angular-schematics 17.0.4 → 18.0.1

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 (223) hide show
  1. package/README.md +8 -0
  2. package/package.json +4 -4
  3. package/src/collection.json +0 -16
  4. package/src/component/files/__name@dasherize__/__name@dasherize__.component.ts.template +22 -8
  5. package/src/component/index.js +2 -45
  6. package/src/component/index.js.map +1 -1
  7. package/src/component/schema.json +0 -5
  8. package/src/entity/files/__name@dasherize__/__name@dasherize__.mock.ts.template +12 -0
  9. package/src/entity/files/__name@dasherize__/__name@dasherize__.model.ts.template +1 -0
  10. package/src/entity/files/__name@dasherize__/__name@dasherize__.store.ts.template +41 -0
  11. package/src/entity/index.js +29 -50
  12. package/src/entity/index.js.map +1 -1
  13. package/src/init/files/.eslintrc.json.template +1 -1
  14. package/src/init/files/.firebaserc.template +8 -0
  15. package/src/init/files/.github/workflows/angular-github-ci.yml.template +1 -1
  16. package/src/init/files/README.md.template +13 -10
  17. package/src/init/files/angular.json.template +18 -11
  18. package/src/init/files/package.json.template +29 -30
  19. package/src/init/files/src/app/admin/{waitlist/waitlist.animations.ts.template → admin-panel/admin-panel.animations.ts.template} +1 -1
  20. package/src/init/files/src/app/admin/{waitlist/waitlist.component.html.template → admin-panel/admin-panel.component.html.template} +3 -3
  21. package/src/init/files/src/app/admin/{waitlist/waitlist.component.scss.template → admin-panel/admin-panel.component.scss.template} +1 -1
  22. package/src/init/files/src/app/admin/admin-panel/admin-panel.component.spec.ts.template +25 -0
  23. package/src/init/files/src/app/admin/admin-panel/admin-panel.component.ts.template +99 -0
  24. package/src/init/files/src/app/app.component.ts.template +12 -8
  25. package/src/init/files/src/app/app.config.ts.template +65 -0
  26. package/src/init/files/src/app/app.routes.ts.template +32 -0
  27. package/src/init/files/src/app/core/analytics/log.service.ts.template +122 -89
  28. package/src/init/files/src/app/core/analytics/time-analytics.service.ts.template +9 -17
  29. package/src/init/files/src/app/core/auth/auth.guard.ts.template +26 -23
  30. package/src/init/files/src/app/core/firebase/cached-listeners.service.ts.template +291 -0
  31. package/src/init/files/src/app/core/firebase/database.service.ts.template +56 -0
  32. package/src/init/files/src/app/core/firebase/firebase.mock.service.ts.template +276 -0
  33. package/src/init/files/src/app/core/firebase/firebase.service.ts.template +265 -215
  34. package/src/init/files/src/app/core/local-storage/session.service.ts.template +3 -4
  35. package/src/init/files/src/app/core/store/app.model.ts.template +19 -0
  36. package/src/init/files/src/app/core/store/app.store.ts.template +1074 -0
  37. package/src/init/files/src/app/core/store/auth/auth.mock.ts.template +20 -0
  38. package/src/init/files/src/app/core/store/auth/auth.store.ts.template +136 -0
  39. package/src/init/files/src/app/core/store/batch-write.firebase.service.ts.template +58 -0
  40. package/src/init/files/src/app/core/store/batch-write.mock.service.ts.template +105 -0
  41. package/src/init/files/src/app/core/store/batch-write.service.ts.template +126 -0
  42. package/src/init/files/src/app/core/store/user/user.mock.ts.template +24 -0
  43. package/src/init/files/src/app/core/store/user/user.model.ts.template +3 -6
  44. package/src/init/files/src/app/core/store/user/user.store.ts.template +41 -0
  45. package/src/init/files/src/app/core/store/user-context/user-context.mock.ts.template +24 -0
  46. package/src/init/files/src/app/core/store/user-context/user-context.model.ts.template +1 -0
  47. package/src/init/files/src/app/core/store/user-context/user-context.store.ts.template +41 -0
  48. package/src/init/files/src/app/core/utils/rand.utils.ts.template +13 -0
  49. package/src/init/files/src/app/{onboarding → first-time}/consent/consent.component.html.template +10 -14
  50. package/src/init/files/src/app/{onboarding → first-time}/consent/consent.component.scss.template +2 -2
  51. package/src/init/files/src/app/first-time/consent/consent.component.ts.template +95 -0
  52. package/src/init/files/src/app/first-time/early-access/early-access.animations.ts.template +4 -0
  53. package/src/init/files/src/app/first-time/early-access/early-access.component.html.template +65 -0
  54. package/src/init/files/src/app/{onboarding/waiting/waiting.component.scss.template → first-time/early-access/early-access.component.scss.template} +10 -3
  55. package/src/init/files/src/app/first-time/early-access/early-access.component.spec.ts.template +25 -0
  56. package/src/init/files/src/app/first-time/early-access/early-access.component.ts.template +254 -0
  57. package/src/init/files/src/app/first-time/early-access/early-access.model.ts.template +7 -0
  58. package/src/init/files/src/app/{general → first-time}/landing/landing.component.html.template +1 -1
  59. package/src/init/files/src/app/first-time/landing/landing.component.ts.template +44 -0
  60. package/src/init/files/src/app/first-time/login/login.component.html.template +10 -0
  61. package/src/init/files/src/app/first-time/login/login.component.ts.template +45 -0
  62. package/src/init/files/src/app/first-time/onboarding/onboarding.animations.ts.template +4 -0
  63. package/src/init/files/src/app/first-time/onboarding/onboarding.component.html.template +2 -0
  64. package/src/init/files/src/app/first-time/onboarding/onboarding.component.scss.template +5 -0
  65. package/src/init/files/src/app/{admin/waitlist/waitlist.component.spec.ts.template → first-time/onboarding/onboarding.component.spec.ts.template} +6 -6
  66. package/src/init/files/src/app/first-time/onboarding/onboarding.component.ts.template +41 -0
  67. package/src/init/files/src/app/main/home/home.component.html.template +6 -0
  68. package/src/init/files/src/app/{general → main}/home/home.component.scss.template +1 -0
  69. package/src/init/files/src/app/main/home/home.component.ts.template +55 -0
  70. package/src/init/files/src/app/shared/navbar/navbar.component.html.template +15 -0
  71. package/src/init/files/src/app/shared/navbar/navbar.component.scss.template +41 -0
  72. package/src/init/files/src/app/shared/navbar/navbar.component.spec.ts.template +25 -0
  73. package/src/init/files/src/app/shared/navbar/navbar.component.ts.template +40 -0
  74. package/src/init/files/src/app/shared/redeployment-warning/redeployment-warning.component.html.template +9 -0
  75. package/src/init/files/src/app/shared/{components/redeployment-warning → redeployment-warning}/redeployment-warning.component.ts.template +17 -6
  76. package/src/init/files/src/app/shared/{components/redeployment-warning → redeployment-warning}/redeployment-warning.service.ts.template +2 -2
  77. package/src/init/files/src/assets/images/close-x.svg +3 -0
  78. package/src/init/files/src/environments/environment.prod.ts.template +6 -2
  79. package/src/init/files/src/environments/environment.ts.template +4 -2
  80. package/src/init/files/src/index.html.template +1 -1
  81. package/src/init/files/src/styles.scss.template +4 -0
  82. package/src/init/files/tsconfig.json.template +0 -1
  83. package/src/container/files/__name@dasherize__/+state/__name@dasherize__.actions.ts.template +0 -26
  84. package/src/container/files/__name@dasherize__/+state/__name@dasherize__.effects.ts.template +0 -48
  85. package/src/container/files/__name@dasherize__/+state/__name@dasherize__.model.ts.template +0 -0
  86. package/src/container/files/__name@dasherize__/+state/__name@dasherize__.selectors.ts.template +0 -20
  87. package/src/container/files/__name@dasherize__/+state/__name@dasherize__.state.ts.template +0 -13
  88. package/src/container/files/__name@dasherize__/__name@dasherize__.animations.ts.template +0 -4
  89. package/src/container/files/__name@dasherize__/__name@dasherize__.component.html.template +0 -3
  90. package/src/container/files/__name@dasherize__/__name@dasherize__.component.scss.template +0 -5
  91. package/src/container/files/__name@dasherize__/__name@dasherize__.component.spec.ts.template +0 -25
  92. package/src/container/files/__name@dasherize__/__name@dasherize__.component.ts.template +0 -90
  93. package/src/container/index.d.ts +0 -2
  94. package/src/container/index.js +0 -127
  95. package/src/container/index.js.map +0 -1
  96. package/src/container/index_spec.d.ts +0 -1
  97. package/src/container/index_spec.js +0 -23
  98. package/src/container/index_spec.js.map +0 -1
  99. package/src/container/schema.json +0 -50
  100. package/src/entity/files/__name@dasherize__/__name@dasherize__.actions.ts.template +0 -249
  101. package/src/entity/files/__name@dasherize__/__name@dasherize__.effects.ts.template +0 -131
  102. package/src/entity/files/__name@dasherize__/__name@dasherize__.reducer.spec.ts.template +0 -13
  103. package/src/entity/files/__name@dasherize__/__name@dasherize__.reducer.ts.template +0 -51
  104. package/src/entity/files/__name@dasherize__/__name@dasherize__.service.ts.template +0 -50
  105. package/src/entity-in-example/files/__name@dasherize__/__name@dasherize__.actions.ts.template +0 -270
  106. package/src/entity-in-example/files/__name@dasherize__/__name@dasherize__.effects.ts.template +0 -131
  107. package/src/entity-in-example/files/__name@dasherize__/__name@dasherize__.model.ts.template +0 -3
  108. package/src/entity-in-example/files/__name@dasherize__/__name@dasherize__.reducer.spec.ts.template +0 -13
  109. package/src/entity-in-example/files/__name@dasherize__/__name@dasherize__.reducer.ts.template +0 -51
  110. package/src/entity-in-example/files/__name@dasherize__/__name@dasherize__.service.ts.template +0 -50
  111. package/src/entity-in-example/index.d.ts +0 -2
  112. package/src/entity-in-example/index.js +0 -141
  113. package/src/entity-in-example/index.js.map +0 -1
  114. package/src/entity-in-example/index_spec.d.ts +0 -1
  115. package/src/entity-in-example/index_spec.js +0 -23
  116. package/src/entity-in-example/index_spec.js.map +0 -1
  117. package/src/entity-in-example/schema.json +0 -45
  118. package/src/init/files/CHANGELOG.md.template +0 -10
  119. package/src/init/files/src/app/admin/admin-routing.module.ts.template +0 -17
  120. package/src/init/files/src/app/admin/admin.module.spec.ts.template +0 -13
  121. package/src/init/files/src/app/admin/admin.module.ts.template +0 -28
  122. package/src/init/files/src/app/admin/waitlist/+state/waitlist.actions.ts.template +0 -23
  123. package/src/init/files/src/app/admin/waitlist/+state/waitlist.effects.ts.template +0 -50
  124. package/src/init/files/src/app/admin/waitlist/+state/waitlist.model.ts.template +0 -0
  125. package/src/init/files/src/app/admin/waitlist/+state/waitlist.selectors.ts.template +0 -39
  126. package/src/init/files/src/app/admin/waitlist/+state/waitlist.state.ts.template +0 -13
  127. package/src/init/files/src/app/admin/waitlist/waitlist.component.ts.template +0 -141
  128. package/src/init/files/src/app/app-routing.module.ts.template +0 -26
  129. package/src/init/files/src/app/app.module.ts.template +0 -34
  130. package/src/init/files/src/app/core/core.module.ts.template +0 -75
  131. package/src/init/files/src/app/core/setup/firebase-setup.ts.template +0 -25
  132. package/src/init/files/src/app/core/setup/module-import-guard.ts.template +0 -5
  133. package/src/init/files/src/app/core/snackbar/snackbar.actions.ts.template +0 -24
  134. package/src/init/files/src/app/core/snackbar/snackbar.effects.ts.template +0 -41
  135. package/src/init/files/src/app/core/store/app-state/app-state.actions.ts.template +0 -249
  136. package/src/init/files/src/app/core/store/app-state/app-state.effects.ts.template +0 -131
  137. package/src/init/files/src/app/core/store/app-state/app-state.model.ts.template +0 -8
  138. package/src/init/files/src/app/core/store/app-state/app-state.reducer.spec.ts.template +0 -13
  139. package/src/init/files/src/app/core/store/app-state/app-state.reducer.ts.template +0 -51
  140. package/src/init/files/src/app/core/store/app-state/app-state.service.ts.template +0 -50
  141. package/src/init/files/src/app/core/store/app.actions.ts.template +0 -92
  142. package/src/init/files/src/app/core/store/app.effects.ts.template +0 -175
  143. package/src/init/files/src/app/core/store/app.reducer.ts.template +0 -36
  144. package/src/init/files/src/app/core/store/app.selectors.ts.template +0 -42
  145. package/src/init/files/src/app/core/store/auth/auth.actions.ts.template +0 -77
  146. package/src/init/files/src/app/core/store/auth/auth.effects.ts.template +0 -163
  147. package/src/init/files/src/app/core/store/auth/auth.reducer.spec.ts.template +0 -13
  148. package/src/init/files/src/app/core/store/auth/auth.reducer.ts.template +0 -26
  149. package/src/init/files/src/app/core/store/auth/auth.selectors.ts.template +0 -25
  150. package/src/init/files/src/app/core/store/cached-load-connections.service.ts.template +0 -405
  151. package/src/init/files/src/app/core/store/cached-selectors.service.ts.template +0 -376
  152. package/src/init/files/src/app/core/store/effects.helpers.ts.template +0 -66
  153. package/src/init/files/src/app/core/store/user/user.actions.ts.template +0 -248
  154. package/src/init/files/src/app/core/store/user/user.effects.ts.template +0 -148
  155. package/src/init/files/src/app/core/store/user/user.reducer.spec.ts.template +0 -13
  156. package/src/init/files/src/app/core/store/user/user.reducer.ts.template +0 -50
  157. package/src/init/files/src/app/core/store/user/user.service.ts.template +0 -50
  158. package/src/init/files/src/app/core/store/user-context/user-context.actions.ts.template +0 -248
  159. package/src/init/files/src/app/core/store/user-context/user-context.effects.ts.template +0 -131
  160. package/src/init/files/src/app/core/store/user-context/user-context.reducer.spec.ts.template +0 -13
  161. package/src/init/files/src/app/core/store/user-context/user-context.reducer.ts.template +0 -51
  162. package/src/init/files/src/app/core/store/user-context/user-context.service.ts.template +0 -50
  163. package/src/init/files/src/app/core/utils/string-case.utils.ts.template +0 -96
  164. package/src/init/files/src/app/general/general-routing.module.ts.template +0 -25
  165. package/src/init/files/src/app/general/general.module.spec.ts.template +0 -13
  166. package/src/init/files/src/app/general/general.module.ts.template +0 -36
  167. package/src/init/files/src/app/general/home/+state/home.actions.ts.template +0 -26
  168. package/src/init/files/src/app/general/home/+state/home.effects.ts.template +0 -48
  169. package/src/init/files/src/app/general/home/+state/home.model.ts.template +0 -0
  170. package/src/init/files/src/app/general/home/+state/home.selectors.ts.template +0 -20
  171. package/src/init/files/src/app/general/home/+state/home.state.ts.template +0 -13
  172. package/src/init/files/src/app/general/home/home.component.html.template +0 -5
  173. package/src/init/files/src/app/general/home/home.component.ts.template +0 -88
  174. package/src/init/files/src/app/general/landing/+state/landing.actions.ts.template +0 -26
  175. package/src/init/files/src/app/general/landing/+state/landing.effects.ts.template +0 -48
  176. package/src/init/files/src/app/general/landing/+state/landing.model.ts.template +0 -0
  177. package/src/init/files/src/app/general/landing/+state/landing.selectors.ts.template +0 -20
  178. package/src/init/files/src/app/general/landing/+state/landing.state.ts.template +0 -13
  179. package/src/init/files/src/app/general/landing/landing.component.ts.template +0 -98
  180. package/src/init/files/src/app/general/login/login.component.html.template +0 -11
  181. package/src/init/files/src/app/general/login/login.component.ts.template +0 -80
  182. package/src/init/files/src/app/onboarding/consent/+state/consent.actions.ts.template +0 -23
  183. package/src/init/files/src/app/onboarding/consent/+state/consent.effects.ts.template +0 -47
  184. package/src/init/files/src/app/onboarding/consent/+state/consent.model.ts.template +0 -0
  185. package/src/init/files/src/app/onboarding/consent/+state/consent.selectors.ts.template +0 -20
  186. package/src/init/files/src/app/onboarding/consent/+state/consent.state.ts.template +0 -13
  187. package/src/init/files/src/app/onboarding/consent/consent.component.ts.template +0 -151
  188. package/src/init/files/src/app/onboarding/onboarding-routing.module.ts.template +0 -19
  189. package/src/init/files/src/app/onboarding/onboarding.module.spec.ts.template +0 -13
  190. package/src/init/files/src/app/onboarding/onboarding.module.ts.template +0 -32
  191. package/src/init/files/src/app/onboarding/waiting/+state/waiting.actions.ts.template +0 -26
  192. package/src/init/files/src/app/onboarding/waiting/+state/waiting.effects.ts.template +0 -52
  193. package/src/init/files/src/app/onboarding/waiting/+state/waiting.model.ts.template +0 -9
  194. package/src/init/files/src/app/onboarding/waiting/+state/waiting.selectors.ts.template +0 -42
  195. package/src/init/files/src/app/onboarding/waiting/+state/waiting.state.ts.template +0 -13
  196. package/src/init/files/src/app/onboarding/waiting/waiting.animations.ts.template +0 -4
  197. package/src/init/files/src/app/onboarding/waiting/waiting.component.html.template +0 -57
  198. package/src/init/files/src/app/onboarding/waiting/waiting.component.spec.ts.template +0 -25
  199. package/src/init/files/src/app/onboarding/waiting/waiting.component.ts.template +0 -281
  200. package/src/init/files/src/app/shared/components/redeployment-warning/redeployment-warning.component.html.template +0 -10
  201. package/src/init/files/src/app/shared/shared.module.ts.template +0 -87
  202. package/src/init/files/src/main.ts.template +0 -12
  203. package/src/module/files/__name@dasherize__/__name@dasherize__-routing.module.ts.template +0 -15
  204. package/src/module/files/__name@dasherize__/__name@dasherize__.module.spec.ts.template +0 -13
  205. package/src/module/files/__name@dasherize__/__name@dasherize__.module.ts.template +0 -24
  206. package/src/module/index.d.ts +0 -2
  207. package/src/module/index.js +0 -97
  208. package/src/module/index.js.map +0 -1
  209. package/src/module/index_spec.d.ts +0 -1
  210. package/src/module/index_spec.js +0 -23
  211. package/src/module/index_spec.js.map +0 -1
  212. package/src/module/schema.json +0 -38
  213. /package/src/init/files/src/app/{onboarding → first-time}/consent/consent.animations.ts.template +0 -0
  214. /package/src/init/files/src/app/{onboarding → first-time}/consent/consent.component.spec.ts.template +0 -0
  215. /package/src/init/files/src/app/{general → first-time}/landing/landing.animations.ts.template +0 -0
  216. /package/src/init/files/src/app/{general → first-time}/landing/landing.component.scss.template +0 -0
  217. /package/src/init/files/src/app/{general → first-time}/landing/landing.component.spec.ts.template +0 -0
  218. /package/src/init/files/src/app/{general → first-time}/login/login.component.scss.template +0 -0
  219. /package/src/init/files/src/app/{general → first-time}/login/login.component.spec.ts.template +0 -0
  220. /package/src/init/files/src/app/{general → main}/home/home.animations.ts.template +0 -0
  221. /package/src/init/files/src/app/{general → main}/home/home.component.spec.ts.template +0 -0
  222. /package/src/init/files/src/app/shared/{components/redeployment-warning → redeployment-warning}/redeployment-warning.component.scss.template +0 -0
  223. /package/src/init/files/src/app/shared/{components/redeployment-warning → redeployment-warning}/redeployment-warning.component.spec.ts.template +0 -0
@@ -0,0 +1,20 @@
1
+ import { signalStore, patchState, withState, withMethods, signalStoreFeature } from '@ngrx/signals';
2
+ import { USER_DB } from '../user/user.mock';
3
+
4
+ export const AuthMockDB = signalStore(
5
+ { providedIn: 'root' },
6
+ withState({ user: null }),
7
+ withMethods((store) => ({
8
+ login() {
9
+ patchState(store, { user: {
10
+ uid: USER_DB[0].__id,
11
+ email: USER_DB[0].email,
12
+ displayName: USER_DB[0].name,
13
+ photoURL: USER_DB[0].photoURL,
14
+ } });
15
+ },
16
+ logout() {
17
+ patchState(store, { user: null });
18
+ },
19
+ })),
20
+ );
@@ -0,0 +1,136 @@
1
+ import { Inject, inject, effect } from '@angular/core';
2
+ import { signalStore, patchState, withState, withMethods } from '@ngrx/signals';
3
+ import { rxMethod } from '@ngrx/signals/rxjs-interop';
4
+ import { User, AccessState } from '../user/user.model';
5
+ import { DATABASE_SERVICE, DatabaseService } from '../../firebase/database.service';
6
+ import { firstValueFrom, EMPTY, of, pipe } from 'rxjs';
7
+ import { tap, catchError, switchMap, map } from 'rxjs/operators';
8
+ import { Router } from '@angular/router';
9
+
10
+ type State = {
11
+ user: User;
12
+ isLoadingLogin: boolean;
13
+ }
14
+
15
+ const initialState: State = {
16
+ user: null,
17
+ isLoadingLogin: false,
18
+ };
19
+
20
+ export const AuthStore = signalStore(
21
+ { providedIn: 'root' },
22
+ withState(initialState),
23
+ withMethods((store, db = inject(DATABASE_SERVICE), router = inject(Router)) => ({
24
+ loadAuth: rxMethod<void>(
25
+ pipe(
26
+ // Every time firebase or db user changes, we want to update auth store
27
+ switchMap(() => db.afUser().pipe(
28
+ catchError((e) => {
29
+ console.error(e);
30
+ return EMPTY;
31
+ }),
32
+ )),
33
+ switchMap((afUser) => {
34
+ if (afUser) {
35
+ return db.streamEntity('users', afUser.uid).pipe(
36
+ map((dbUser) => ({ afUser, dbUser })),
37
+ catchError((e) => {
38
+ console.error(e);
39
+ return EMPTY;
40
+ }),
41
+ );
42
+ } else {
43
+ return of({ afUser, dbUser: null });
44
+ }
45
+ }),
46
+ tap(async ({ afUser, dbUser }) => {
47
+ if (!afUser) {
48
+ patchState(store, { user: undefined });
49
+ } else if (afUser && dbUser) {
50
+ patchState(store, { user: dbUser });
51
+ }
52
+ }),
53
+ ),
54
+ ),
55
+ async login(provider: string, params: {
56
+ scope?: string,
57
+ doNotRoute: boolean
58
+ } = { doNotRoute: false }): Promise<void> {
59
+ patchState(store, { isLoadingLogin: true });
60
+
61
+ try {
62
+ const loginResult = await db.login(provider, params.scope);
63
+ const afUser = loginResult.user;
64
+ // could this be problematic if it hits a cached value?
65
+ const dbUser: User = await db.getEntity('users', afUser.uid);
66
+
67
+ const navLocation = ['/home'];
68
+ // update the token if there is already a dbUser
69
+ if (dbUser) {
70
+ const tokenHash = {};
71
+ tokenHash[provider] = afUser.accessToken;
72
+ const changes = {
73
+ email: afUser.email,
74
+ name: afUser.displayName || afUser.email,
75
+ photoURL: afUser.photoURL,
76
+ tokens: Object.assign({}, dbUser.tokens || {}, tokenHash),
77
+ };
78
+ try {
79
+ patchState(store, { user: dbUser });
80
+ await db.updateEntity('users', dbUser.__id, changes);
81
+
82
+ if (!params || !params.doNotRoute) {
83
+ router.navigate(navLocation, { queryParamsHandling: 'preserve' });
84
+ }
85
+ } catch (e) {
86
+ console.error(e);
87
+ throw e;
88
+ }
89
+ } else {
90
+ const tokenHash = {};
91
+ tokenHash[provider] = afUser.accessToken;
92
+ const newUser = {
93
+ __id: afUser.uid,
94
+ email: afUser.email,
95
+ name: afUser.displayName || afUser.email,
96
+ photoURL: afUser.photoURL,
97
+ tokens: tokenHash,
98
+ isAdmin: false,
99
+ consented: false,
100
+ accessState: AccessState.CONSENT,
101
+ };
102
+ try {
103
+ await db.addEntity('users', newUser);
104
+ patchState(store, { user: newUser });
105
+
106
+ if (!params || !params.doNotRoute) {
107
+ router.navigate(navLocation, { queryParamsHandling: 'preserve' });
108
+ }
109
+ } catch (e) {
110
+ console.error(e);
111
+ throw e;
112
+ }
113
+ }
114
+ } catch (e) {
115
+ switch (e.code) {
116
+ case 'auth/account-exists-with-different-credential': {
117
+ db.loginLink(e);
118
+ }
119
+ }
120
+ throw e;
121
+ }
122
+ patchState(store, { isLoadingLogin: false });
123
+ },
124
+ async logout(params?: { doNotRoute: boolean }): Promise<void> {
125
+ try {
126
+ await db.logout();
127
+ if (!params || !params.doNotRoute) {
128
+ router.navigate(['/landing']);
129
+ }
130
+ } catch (e) {
131
+ console.error(e);
132
+ throw e;
133
+ }
134
+ },
135
+ })),
136
+ );
@@ -0,0 +1,58 @@
1
+ import { InjectionToken, Injectable, WritableSignal, inject } from '@angular/core';
2
+ import { Firestore, WriteBatch, writeBatch } from '@angular/fire/firestore';
3
+ import { MatSnackBar, MatSnackBarConfig } from '@angular/material/snack-bar';
4
+ import { FirebaseMockService } from '../firebase/firebase.mock.service';
5
+ import { processBatchWrite, BatchWriteService } from './batch-write.service';
6
+
7
+ @Injectable({
8
+ providedIn: 'root',
9
+ })
10
+ export class BatchWriteDBService implements BatchWriteService {
11
+ private firestore = inject(Firestore);
12
+ private snackBar = inject(MatSnackBar);
13
+
14
+ constructor(
15
+ ) { }
16
+
17
+ /**
18
+ * @param batchFn function that contains any number of add, update,
19
+ * or remove calls and writes them all as a batch write. It takes a
20
+ * batchConfig as an input, which contains the batch and revertBatch objects
21
+ * as the patchFns or revertFns arrays for collecting the functions
22
+ * that need to be run to either add things to the store after success or
23
+ * revert things from the store on failure in an optimistic write setting.
24
+ * It also stores whether these will be optimistic writes or not.
25
+ * @param options support for optimistic writes, a loading icon, and
26
+ * a snackbar that has an undo option.
27
+ */
28
+ async batchWrite(
29
+ batchFn: (batchConfig: {
30
+ batch: WriteBatch,
31
+ revertBatch: WriteBatch,
32
+ patchFns: Array<() => void>,
33
+ revertFns: Array<() => void>,
34
+ dbRevertFns: Array<() => void>,
35
+ optimistic?: boolean,
36
+ }) => void,
37
+ options?: {
38
+ optimistic?: boolean,
39
+ loading?: WritableSignal<boolean>,
40
+ snackBarConfig?: {
41
+ successMessage: string,
42
+ failureMessage: string,
43
+ undoOnAction?: boolean,
44
+ config?: MatSnackBarConfig<any>,
45
+ }
46
+ },
47
+ ) {
48
+ const batch = writeBatch(this.firestore);
49
+ const revertBatch = writeBatch(this.firestore);
50
+
51
+ try {
52
+ await processBatchWrite(batchFn, options, batch, revertBatch, this.snackBar);
53
+ } catch (e) {
54
+ console.log(e);
55
+ throw e;
56
+ }
57
+ }
58
+ }
@@ -0,0 +1,105 @@
1
+ import { InjectionToken, Injectable, WritableSignal, inject } from '@angular/core';
2
+ import { Firestore, WriteBatch, writeBatch } from '@angular/fire/firestore';
3
+ import { MatSnackBar, MatSnackBarConfig } from '@angular/material/snack-bar';
4
+ import { FirebaseMockService } from '../firebase/firebase.mock.service';
5
+ import { WriteBatchI, BatchWriteService, processBatchWrite } from './batch-write.service';
6
+
7
+ // after doing a bunch of update/sets, then we need to actually do that when we commit
8
+ export class WriteBatchMock {
9
+ saveFns;
10
+ db;
11
+
12
+ // Constant for simulating delay (e.g. to see loading icon in action)
13
+ PUT_LATENCY_SIMULATION_DELAY = 300;
14
+
15
+ constructor(
16
+ db: FirebaseMockService,
17
+ ) {
18
+ this.saveFns = [];
19
+ this.db = db;
20
+ }
21
+
22
+ async update(docRef, changes) {
23
+ const [collectionName, id] = docRef.path.split('/').slice(0, 2);
24
+ this.saveFns.push(async () => {
25
+ try {
26
+ await this.db.updateEntity(collectionName, id, changes);
27
+ } catch (e) {
28
+ console.error(e);
29
+ throw e;
30
+ }
31
+ });
32
+ }
33
+
34
+ async set(docRef, entity) {
35
+ const [collectionName] = docRef.path.split('/').slice(0, 1);
36
+ this.saveFns.push(async () => {
37
+ try {
38
+ await this.db.addEntity(collectionName, entity);
39
+ } catch (e) {
40
+ console.error(e);
41
+ throw e;
42
+ }
43
+ });
44
+ }
45
+
46
+ async delete(docRef) {
47
+ const [collectionName, id] = docRef.path.split('/').slice(0, 2);
48
+ this.saveFns.push(async () => {
49
+ try {
50
+ await this.db.removeEntity(collectionName, id);
51
+ } catch (e) {
52
+ console.error(e);
53
+ throw e;
54
+ }
55
+ });
56
+ }
57
+
58
+ async commit() {
59
+ await new Promise((resolve) => setTimeout(resolve, this.PUT_LATENCY_SIMULATION_DELAY));
60
+ return Promise.all(this.saveFns.map((saveFn) => saveFn()));
61
+ }
62
+ }
63
+
64
+ @Injectable({
65
+ providedIn: 'root',
66
+ })
67
+ export class BatchWriteMockService implements BatchWriteService {
68
+ private snackBar = inject(MatSnackBar);
69
+
70
+ constructor(
71
+ private db: FirebaseMockService,
72
+ ) {
73
+ }
74
+
75
+ async batchWrite(
76
+ batchFn: (batchConfig: {
77
+ batch: WriteBatchMock,
78
+ revertBatch: WriteBatchMock,
79
+ patchFns: Array<() => void>,
80
+ revertFns: Array<() => void>,
81
+ dbRevertFns: Array<() => void>,
82
+ optimistic?: boolean,
83
+ }) => void,
84
+ options?: {
85
+ optimistic?: boolean,
86
+ loading?: WritableSignal<boolean>,
87
+ snackBarConfig?: {
88
+ successMessage: string,
89
+ failureMessage: string,
90
+ undoOnAction?: boolean,
91
+ config?: MatSnackBarConfig<any>,
92
+ }
93
+ },
94
+ ): Promise<void> {
95
+ const batch = new WriteBatchMock(this.db);
96
+ const revertBatch = new WriteBatchMock(this.db);
97
+
98
+ try {
99
+ await processBatchWrite(batchFn, options, batch, revertBatch, this.snackBar);
100
+ } catch (e) {
101
+ console.log(e);
102
+ throw e;
103
+ }
104
+ }
105
+ }
@@ -0,0 +1,126 @@
1
+ import { openSnackBarWithUndoOption } from './app.store';
2
+ import { MatSnackBar, MatSnackBarConfig } from '@angular/material/snack-bar';
3
+ import { InjectionToken, Injectable, WritableSignal, inject } from '@angular/core';
4
+ import { WriteBatchMock } from './batch-write.mock.service';
5
+ import { WriteBatch } from '@angular/fire/firestore';
6
+
7
+ export interface WriteBatchI {
8
+ update(docRef, changes);
9
+ set(docRef, entity);
10
+ delete(docRef);
11
+ commit();
12
+ }
13
+
14
+ export interface BatchWriteService {
15
+ batchWrite(
16
+ batchFn: (batchConfig: {
17
+ batch: WriteBatch | WriteBatchMock,
18
+ revertBatch: WriteBatch | WriteBatchMock,
19
+ patchFns: Array<() => void>,
20
+ revertFns: Array<() => void>,
21
+ dbRevertFns: Array<() => void>,
22
+ optimistic?: boolean,
23
+ }) => void,
24
+ options?: {
25
+ optimistic?: boolean,
26
+ loading?: WritableSignal<boolean>,
27
+ snackBarConfig?: {
28
+ successMessage: string,
29
+ failureMessage: string,
30
+ undoOnAction?: boolean,
31
+ config?: MatSnackBarConfig<any>,
32
+ }
33
+ },
34
+ ): Promise<void>;
35
+ }
36
+
37
+ export const BATCH_WRITE_SERVICE = new InjectionToken<BatchWriteService>('BatchWriteService');
38
+
39
+ export async function processBatchWrite(
40
+ batchFn: (batchConfig: {
41
+ batch: WriteBatchI,
42
+ revertBatch: WriteBatchI,
43
+ patchFns: Array<() => void>,
44
+ revertFns: Array<() => void>,
45
+ dbRevertFns: Array<() => void>,
46
+ optimistic?: boolean,
47
+ }) => void,
48
+ options: {
49
+ optimistic?: boolean,
50
+ loading?: WritableSignal<boolean>,
51
+ snackBarConfig?: {
52
+ successMessage: string,
53
+ failureMessage: string,
54
+ undoOnAction?: boolean,
55
+ config?: MatSnackBarConfig<any>,
56
+ }
57
+ },
58
+ batch: WriteBatchI,
59
+ revertBatch: WriteBatchI,
60
+ snackBar: MatSnackBar,
61
+ ) {
62
+ const patchFns = [];
63
+ const revertFns = [];
64
+ const dbRevertFns = [];
65
+
66
+ if (options?.optimistic) {
67
+ // this includes optimistically patching locally assuming
68
+ // they are using the add, update, remove functions from
69
+ // the ngrx signal stores
70
+ await batchFn({ batch, revertBatch, patchFns, revertFns, dbRevertFns, optimistic: options.optimistic });
71
+ try {
72
+ await batch.commit();
73
+ if (options?.snackBarConfig) {
74
+ openSnackBarWithUndoOption(
75
+ snackBar,
76
+ options.snackBarConfig,
77
+ revertFns,
78
+ dbRevertFns,
79
+ revertBatch,
80
+ );
81
+ }
82
+ } catch (e) {
83
+ revertFns.forEach((revertFn) => revertFn());
84
+ console.error(e);
85
+ if (options?.snackBarConfig) {
86
+ snackBar.open(
87
+ options.snackBarConfig.failureMessage,
88
+ '',
89
+ options.snackBarConfig.config,
90
+ );
91
+ }
92
+ throw e;
93
+ }
94
+ } else {
95
+ // start loading icon
96
+ options?.loading?.set(true);
97
+ try {
98
+ await batchFn({ batch, revertBatch, patchFns, revertFns, dbRevertFns });
99
+ await batch.commit();
100
+ patchFns.forEach((patchFn) => patchFn());
101
+
102
+ if (options?.snackBarConfig) {
103
+ openSnackBarWithUndoOption(
104
+ snackBar,
105
+ options.snackBarConfig,
106
+ revertFns,
107
+ dbRevertFns,
108
+ revertBatch,
109
+ );
110
+ }
111
+ } catch (e) {
112
+ console.error(e);
113
+ if (options?.snackBarConfig) {
114
+ snackBar.open(
115
+ options.snackBarConfig.failureMessage,
116
+ '',
117
+ options.snackBarConfig.config,
118
+ );
119
+ }
120
+ throw e;
121
+ } finally {
122
+ // stop loading icon
123
+ options?.loading?.set(false);
124
+ }
125
+ }
126
+ }
@@ -0,0 +1,24 @@
1
+ import { Timestamp } from '@angular/fire/firestore';
2
+ import { withEntitiesForMockDB } from '../app.store';
3
+ import { signalStore } from '@ngrx/signals';
4
+ import { User, AccessState } from './user.model';
5
+
6
+ export const UserMockDB = signalStore(
7
+ { providedIn: 'root' },
8
+ withEntitiesForMockDB<User>(),
9
+ );
10
+
11
+ export const USER_DB: User[] = [
12
+ {
13
+ __id: '1',
14
+ email: 'a@sample.com',
15
+ name: 'User A',
16
+ photoURL: 'http://loremflickr.com/100/100',
17
+ isAdmin: false,
18
+ consented: true,
19
+ accessState: AccessState.DONE,
20
+ _createdAt: Timestamp.now(),
21
+ _updatedAt: Timestamp.now(),
22
+ _deleted: false,
23
+ },
24
+ ];
@@ -5,6 +5,7 @@ export interface User {
5
5
  __id: string;
6
6
  _createdAt?: Timestamp;
7
7
  _updatedAt?: Timestamp;
8
+ _deleted?: boolean;
8
9
  name: string;
9
10
  email: string;
10
11
  photoURL?: string;
@@ -15,16 +16,12 @@ export interface User {
15
16
  isAdmin: boolean;
16
17
  accessState: AccessState;
17
18
  consented: boolean;
18
- positionNumber?: number;
19
19
  joinedWaitlistAt?: Timestamp;
20
20
  }
21
21
 
22
22
  export enum AccessState {
23
23
  CONSENT = '01 - consent', // on consent form
24
- SUBMIT_INTEREST = '02 - submit interest', // short form on login with basic interest
25
- SUBMIT_DETAILED = '03 - submit detailed', // longer form on richer context
26
- WAITING = '04 - waiting', // on waitlist for early access
27
- // PLACEHOLDER: uncomment below for app-specific walkthrough page
28
- // WALKTHROUGH = '05 - walkthrough', // on app specific walkthrough page
24
+ SUBMIT_INTEREST = '02 - submit interest', // on basic interest form
25
+ WAITING = '03 - waiting', // on waitlist for early access
29
26
  DONE = 'done', // finished with the entire flow
30
27
  }
@@ -0,0 +1,41 @@
1
+ import { inject, effect, WritableSignal } from '@angular/core';
2
+ import { signalStore, patchState, withState, withMethods } from '@ngrx/signals';
3
+ import { withEntities, removeEntity, updateEntity, setEntity, removeEntities, setEntities } from '@ngrx/signals/entities';
4
+ import { EntityLoadQuery, EntityStreamQuery, selectEntities, processLoadQueries, withEntitiesAndDBMethods } from '../app.store';
5
+ import { QueryParams, QueryOptions, AnyEntity } from '../app.model';
6
+ import { User } from '../user/user.model';
7
+
8
+ export class LoadUser extends EntityLoadQuery<User> {
9
+ constructor(
10
+ store,
11
+ queryParams: QueryParams,
12
+ queryOptions: QueryOptions,
13
+ loadQueries?: (entity: User) => EntityLoadQuery<AnyEntity>[],
14
+ ) {
15
+ super('users', store, queryParams, queryOptions, loadQueries);
16
+ }
17
+
18
+ static create(store, queryParams: QueryParams, queryOptions: QueryOptions, loadQueries?: (entity: User) => EntityLoadQuery<AnyEntity>[]): LoadUser {
19
+ return new LoadUser(store, queryParams, queryOptions, loadQueries);
20
+ }
21
+ }
22
+
23
+ export class StreamUser extends EntityStreamQuery<User> {
24
+ constructor(
25
+ store,
26
+ queryParams: QueryParams,
27
+ queryOptions: QueryOptions,
28
+ streamQueries?: (entity: User) => EntityStreamQuery<AnyEntity>[],
29
+ ) {
30
+ super('users', store, queryParams, queryOptions, streamQueries);
31
+ }
32
+
33
+ static create(store, queryParams: QueryParams, queryOptions: QueryOptions, streamQueries?: (entity: User) => EntityStreamQuery<AnyEntity>[]): StreamUser {
34
+ return new StreamUser(store, queryParams, queryOptions, streamQueries);
35
+ }
36
+ }
37
+
38
+ export const UserStore = signalStore(
39
+ { providedIn: 'root' },
40
+ withEntitiesAndDBMethods<User>('users'),
41
+ );
@@ -0,0 +1,24 @@
1
+ import { Timestamp } from '@angular/fire/firestore';
2
+ import { UserContext } from './user-context.model';
3
+ import { withEntitiesForMockDB } from '../app.store';
4
+ import { signalStore } from '@ngrx/signals';
5
+ import { USER_DB } from '../user/user.mock';
6
+
7
+ export const UserContextMockDB = signalStore(
8
+ { providedIn: 'root' },
9
+ withEntitiesForMockDB<UserContext>(),
10
+ );
11
+
12
+ export const USERCONTEXT_DB = [
13
+ {
14
+ __id: 'uc1',
15
+ __userId: USER_DB[0].__id,
16
+ background: {
17
+ selections: ['option1'],
18
+ },
19
+ desiredValue: 'test',
20
+ _createdAt: Timestamp.now(),
21
+ _updatedAt: Timestamp.now(),
22
+ _deleted: false,
23
+ },
24
+ ];
@@ -10,4 +10,5 @@ export interface UserContext {
10
10
  desiredValue: string;
11
11
  _createdAt?: Timestamp;
12
12
  _updatedAt?: Timestamp;
13
+ _deleted?: boolean;
13
14
  }
@@ -0,0 +1,41 @@
1
+ import { inject, effect, WritableSignal } from '@angular/core';
2
+ import { signalStore, patchState, withState, withMethods } from '@ngrx/signals';
3
+ import { withEntities, removeEntity, updateEntity, setEntity, removeEntities, setEntities } from '@ngrx/signals/entities';
4
+ import { EntityLoadQuery, EntityStreamQuery, selectEntities, processLoadQueries, withEntitiesAndDBMethods } from '../app.store';
5
+ import { QueryParams, QueryOptions, AnyEntity } from '../app.model';
6
+ import { UserContext } from './user-context.model';
7
+
8
+ export class LoadUserContext extends EntityLoadQuery<UserContext> {
9
+ constructor(
10
+ store,
11
+ queryParams: QueryParams,
12
+ queryOptions: QueryOptions,
13
+ loadQueries?: (entity: UserContext) => EntityLoadQuery<AnyEntity>[],
14
+ ) {
15
+ super('userContexts', store, queryParams, queryOptions, loadQueries);
16
+ }
17
+
18
+ static create(store, queryParams: QueryParams, queryOptions: QueryOptions, loadQueries?: (entity: UserContext) => EntityLoadQuery<AnyEntity>[]): LoadUserContext {
19
+ return new LoadUserContext(store, queryParams, queryOptions, loadQueries);
20
+ }
21
+ }
22
+
23
+ export class StreamUserContext extends EntityStreamQuery<UserContext> {
24
+ constructor(
25
+ store,
26
+ queryParams: QueryParams,
27
+ queryOptions: QueryOptions,
28
+ streamQueries?: (entity: UserContext) => EntityStreamQuery<AnyEntity>[],
29
+ ) {
30
+ super('userContexts', store, queryParams, queryOptions, streamQueries);
31
+ }
32
+
33
+ static create(store, queryParams: QueryParams, queryOptions: QueryOptions, streamQueries?: (entity: UserContext) => EntityStreamQuery<AnyEntity>[]): StreamUserContext {
34
+ return new StreamUserContext(store, queryParams, queryOptions, streamQueries);
35
+ }
36
+ }
37
+
38
+ export const UserContextStore = signalStore(
39
+ { providedIn: 'root' },
40
+ withEntitiesAndDBMethods<UserContext>('userContexts'),
41
+ );
@@ -0,0 +1,13 @@
1
+ /** Generate a random string, e.g. for use in a containerId. */
2
+ export function createId(): string {
3
+ // see https://stackoverflow.com/questions/56574593/access-firestore-id-generator-on-the-front-end?noredirect=1&lq=1
4
+ // see https://github.com/firebase/firebase-js-sdk/blob/73a586c92afe3f39a844b2be86086fddb6877bb7/packages/firestore/src/util/misc.ts#L36
5
+ // Alphanumeric characters
6
+ const chars =
7
+ 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
8
+ let autoId = '';
9
+ for (let i = 0; i < 20; i++) {
10
+ autoId += chars.charAt(Math.floor(Math.random() * chars.length));
11
+ }
12
+ return autoId;
13
+ }
@@ -1,4 +1,5 @@
1
- <main class="guide">
1
+ <app-navbar></app-navbar>
2
+ <main class="consent-container">
2
3
  <h1>Research Consent and Privacy Policy</h1>
3
4
  <div class="separator"></div>
4
5
 
@@ -44,18 +45,13 @@
44
45
 
45
46
  <p>We may revise this Privacy Policy from time to time. The most current version of the policy will govern our use of your information and will be at <a routerLink="/consent">{{ consentUrl }}</a>. If we make a change to this policy that, in our sole discretion, is material, we will notify you via an email to the email address associated with your account. By continuing to access or use the Services after those changes become effective, you agree to be bound by the revised Privacy Policy.</p>
46
47
 
47
- <ng-container *ngIf="{ loading: loading$ | async } as state">
48
- <form #checkForm="ngForm" (ngSubmit)="submit$.next()" *ngIf="!state.loading">
49
- <div class="agree-container">
50
- <mat-checkbox [color]="'primary'" [(ngModel)]="checked" name="checked" required><span style="white-space:normal;" class="permission-text">I have read and understood the above, agree to the terms of use, and consent to participate in the research study.</span></mat-checkbox>
51
- </div>
52
- <button type="submit" class="btn continue-btn" [disabled]="!checkForm.form.valid">
53
- Accept and Continue
54
- <img src="https://icongr.am/feather/arrow-right.svg?size=20&color=B2B6C7">
55
- </button>
56
- </form>
57
- <div class="loading-container" *ngIf="state.loading">
58
- Submitting... <mat-spinner [diameter]="20" [strokeWidth]="2"></mat-spinner>
48
+ <form [formGroup]="checkForm" (ngSubmit)="submit()">
49
+ <div class="agree-container">
50
+ <mat-checkbox [color]="'primary'" formControlName="checked" name="checked" required><span style="white-space:normal;" class="permission-text">I have read and understood the above, agree to the terms of use, and consent to participate in the research study.</span></mat-checkbox>
59
51
  </div>
60
- </ng-container>
52
+ <button type="submit" class="btn continue-btn" [disabled]="checkForm.invalid">
53
+ Accept and Continue
54
+ <img src="https://icongr.am/feather/arrow-right.svg?size=20&color=B2B6C7">
55
+ </button>
56
+ </form>
61
57
  </main>
@@ -1,7 +1,7 @@
1
- .guide {
1
+ .consent-container {
2
2
  align-items: stretch;
3
3
  width: 100%;
4
- height: 100%;
4
+ height: calc(100% - 70px);
5
5
  padding: 50px 100px;
6
6
  overflow-y: auto;
7
7
  color: #303030;