1- import { Injectable , OnDestroy } from '@angular/core' ;
2- import { AngularFirestore } from '@angular/fire/compat/firestore' ;
1+ import { inject , Injectable , OnDestroy } from '@angular/core' ;
32import { merge , Subject } from 'rxjs' ;
43import { auditTime , distinctUntilChanged , map , scan , shareReplay , take , takeUntil , } from 'rxjs/operators' ;
54import { nanoid } from 'nanoid' ;
65import { ContentBlock , ContentPresentation } from '../types' ;
76import { reducer } from '../reducer' ;
87import { serverTimestamp } from '@angular/fire/database' ;
98import { NavigationService } from "./navigation.service" ;
9+ import { collection , doc , docData , Firestore , setDoc } from "@angular/fire/firestore" ;
1010
1111const DOC_KEY = 'presentations' ;
1212
1313@Injectable ( { providedIn : 'root' } )
1414export class ContentService implements OnDestroy {
15+ private firestore : Firestore = inject ( Firestore ) ;
1516 public readonly currentSlideIndex$ = this . navigationService . currentSlideIndex$ ;
1617
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 ) )
2120 . pipe (
2221 distinctUntilChanged ( ( a , b ) => {
22+ debugger ;
2323 return JSON . stringify ( a ) === JSON . stringify ( b ) ;
2424 } ) ,
2525 map ( ( doc : any ) => {
@@ -29,8 +29,6 @@ export class ContentService implements OnDestroy {
2929
3030 private readonly localActions$ = new Subject ( ) ;
3131
32- readonly appliedActions = new Set ( ) ;
33-
3432 readonly allActions$ = merge (
3533 this . presentations$ . pipe (
3634 // TODO(kirjs): actually make it work
@@ -53,15 +51,14 @@ export class ContentService implements OnDestroy {
5351 ) ;
5452
5553 constructor (
56- private readonly firestore : AngularFirestore ,
5754 private readonly navigationService : NavigationService
5855 ) {
5956 // TODO: There should be a better way
6057
6158 this . state$
6259 . pipe ( auditTime ( 2000 ) , takeUntil ( this . onDestroy$ ) )
6360 . subscribe ( ( presentations ) => {
64- this . presentations . doc ( 'presentations' ) . set ( { presentations} ) ;
61+ setDoc ( doc ( this . presentations , DOC_KEY ) , { presentations} ) ;
6562 } ) ;
6663 }
6764
0 commit comments