1
- import { Injectable , OnDestroy } from '@angular/core' ;
2
- import { AngularFirestore } from '@angular/fire/compat/firestore' ;
1
+ import { inject , Injectable , OnDestroy } from '@angular/core' ;
3
2
import { merge , Subject } from 'rxjs' ;
4
3
import { auditTime , distinctUntilChanged , map , scan , shareReplay , take , takeUntil , } from 'rxjs/operators' ;
5
4
import { nanoid } from 'nanoid' ;
6
5
import { ContentBlock , ContentPresentation } from '../types' ;
7
6
import { reducer } from '../reducer' ;
8
7
import { serverTimestamp } from '@angular/fire/database' ;
9
8
import { NavigationService } from "./navigation.service" ;
9
+ import { collection , doc , docData , Firestore , setDoc } from "@angular/fire/firestore" ;
10
10
11
11
const DOC_KEY = 'presentations' ;
12
12
13
13
@Injectable ( { providedIn : 'root' } )
14
14
export class ContentService implements OnDestroy {
15
+ private firestore : Firestore = inject ( Firestore ) ;
15
16
public readonly currentSlideIndex$ = this . navigationService . currentSlideIndex$ ;
16
17
17
- private readonly presentations = this . firestore . collection ( 'presentations' ) ;
18
- private readonly presentations$ = this . presentations
19
- . doc ( DOC_KEY )
20
- . valueChanges ( )
18
+ private readonly presentations = collection ( this . firestore , DOC_KEY ) ;
19
+ private readonly presentations$ = docData ( doc ( this . presentations , DOC_KEY ) )
21
20
. pipe (
22
21
distinctUntilChanged ( ( a , b ) => {
22
+ debugger ;
23
23
return JSON . stringify ( a ) === JSON . stringify ( b ) ;
24
24
} ) ,
25
25
map ( ( doc : any ) => {
@@ -29,8 +29,6 @@ export class ContentService implements OnDestroy {
29
29
30
30
private readonly localActions$ = new Subject ( ) ;
31
31
32
- readonly appliedActions = new Set ( ) ;
33
-
34
32
readonly allActions$ = merge (
35
33
this . presentations$ . pipe (
36
34
// TODO(kirjs): actually make it work
@@ -53,15 +51,14 @@ export class ContentService implements OnDestroy {
53
51
) ;
54
52
55
53
constructor (
56
- private readonly firestore : AngularFirestore ,
57
54
private readonly navigationService : NavigationService
58
55
) {
59
56
// TODO: There should be a better way
60
57
61
58
this . state$
62
59
. pipe ( auditTime ( 2000 ) , takeUntil ( this . onDestroy$ ) )
63
60
. subscribe ( ( presentations ) => {
64
- this . presentations . doc ( 'presentations' ) . set ( { presentations} ) ;
61
+ setDoc ( doc ( this . presentations , DOC_KEY ) , { presentations} ) ;
65
62
} ) ;
66
63
}
67
64
0 commit comments