Skip to content

Commit

Permalink
chore: getting resources #7
Browse files Browse the repository at this point in the history
  • Loading branch information
svendjanis committed Oct 3, 2020
1 parent a03f6f9 commit 302edf7
Showing 1 changed file with 13 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import {ChangeDetectionStrategy, Component, OnInit} from '@angular/core';
import {BehaviorSubject, Observable} from 'rxjs';
import {finalize, map} from 'rxjs/operators';
import {JasperoApiService} from '../../shared/services/jaspero-api/jaspero-api.service';
import {FirestoreCollection} from '../../shared/enums/firestore-collection.enum';
import {AngularFirestore} from '@angular/fire/firestore';

interface StrippedResource {
name: string;
Expand All @@ -15,21 +16,22 @@ interface StrippedResource {
changeDetection: ChangeDetectionStrategy.OnPush
})
export class ResourcesComponent implements OnInit {
constructor(private _jasperoApi: JasperoApiService) {}
constructor(private afs: AngularFirestore) {}

loading$ = new BehaviorSubject(true);
resources$: Observable<StrippedResource[]>;

ngOnInit() {
this.resources$ = this._jasperoApi
.get<StrippedResource>('resources', {
projection: {
name: 1,
url: 1
}
})
ngOnInit(): void {
this.resources$ = this.afs
.collection(FirestoreCollection.Resources)
.snapshotChanges()
.pipe(
map(res => res.data),
map(actions =>
actions.map(action => ({
id: action.payload.doc.id,
...(action.payload.doc.data() as any)
}))
),
finalize(() => {
this.loading$.next(false);
})
Expand Down

0 comments on commit 302edf7

Please sign in to comment.