Skip to content

Commit 9caf72e

Browse files
committed
Update firebase in content service
1 parent a052bf5 commit 9caf72e

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

apps/codelab/src/app/admin/content/presentation-editor/content.module.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ import {
1313
NAVIGATION_BASE_URL,
1414
NavigationService,
1515
} from './services/navigation.service';
16+
import { getFirestore, provideFirestore } from "@angular/fire/firestore";
17+
import { initializeApp, provideFirebaseApp } from "@angular/fire/app";
18+
import { environment } from "../../../../environments/environment";
1619

1720
@NgModule({
1821
declarations: [ContentComponent],
@@ -23,6 +26,8 @@ import {
2326
{ provide: NAVIGATION_BASE_URL, useValue: 'admin/content' },
2427
],
2528
imports: [
29+
provideFirebaseApp(() => initializeApp(environment.firebaseConfig)),
30+
provideFirestore(()=>getFirestore()),
2631
CommonModule,
2732
SlideEditorModule,
2833
AngularFirestoreModule,

apps/codelab/src/app/admin/content/presentation-editor/services/content.service.ts

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
1-
import { Injectable, OnDestroy } from '@angular/core';
2-
import { AngularFirestore } from '@angular/fire/compat/firestore';
1+
import { inject, Injectable, OnDestroy } from '@angular/core';
32
import { merge, Subject } from 'rxjs';
43
import { auditTime, distinctUntilChanged, map, scan, shareReplay, take, takeUntil, } from 'rxjs/operators';
54
import { nanoid } from 'nanoid';
65
import { ContentBlock, ContentPresentation } from '../types';
76
import { reducer } from '../reducer';
87
import { serverTimestamp } from '@angular/fire/database';
98
import { NavigationService } from "./navigation.service";
9+
import { collection, doc, docData, Firestore, setDoc } from "@angular/fire/firestore";
1010

1111
const DOC_KEY = 'presentations';
1212

1313
@Injectable({providedIn: 'root'})
1414
export 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

Comments
 (0)