diff --git a/src/app/books/components/books-page/books-page.component.html b/src/app/books/components/books-page/books-page.component.html index 096bcf3..6f7a9c0 100755 --- a/src/app/books/components/books-page/books-page.component.html +++ b/src/app/books/components/books-page/books-page.component.html @@ -5,7 +5,7 @@ diff --git a/src/app/books/components/books-page/books-page.component.ts b/src/app/books/components/books-page/books-page.component.ts index 634ef32..051f1a6 100755 --- a/src/app/books/components/books-page/books-page.component.ts +++ b/src/app/books/components/books-page/books-page.component.ts @@ -3,17 +3,31 @@ import { Component, OnInit } from '@angular/core'; import { Book } from 'src/app/shared/models/book.model'; import { BooksService } from 'src/app/shared/services/book.service'; +import { Observable } from 'rxjs'; +import { Store, select } from '@ngrx/store'; +import * as fromRoot from 'src/app/shared/state'; +import { map } from 'rxjs/operators'; + @Component({ selector: 'app-books', templateUrl: './books-page.component.html', styleUrls: ['./books-page.component.css'] }) export class BooksPageComponent implements OnInit { + books$: Observable; books: Book[]; currentBook: Book; total: number; - constructor(private booksService: BooksService) {} + constructor( + private booksService: BooksService, + private store: Store + ) { + this.books$ = this.store.pipe( + select(state => state.books), + map(booksState => booksState.books) + ); + } ngOnInit() { this.getBooks(); diff --git a/src/app/shared/state/books.reducer.ts b/src/app/shared/state/books.reducer.ts index 7d85022..669f9ef 100644 --- a/src/app/shared/state/books.reducer.ts +++ b/src/app/shared/state/books.reducer.ts @@ -27,3 +27,21 @@ const updateBook = (books: Book[], book: Book) => books.map(w => { return w.id === book.id ? Object.assign({}, book) : w; }); const deleteBook = (books: Book[], book: Book) => books.filter(w => book.id !== w.id); + +export interface State { + activeBookId: string | null; + books: Book[]; +} + +export const initialState = { + activeBookId: null, + books: initialBooks +}; + +export function reducer(state = initialState, action: any): State { + switch(action.type) { + + default: + return state; + } +} \ No newline at end of file diff --git a/src/app/shared/state/index.ts b/src/app/shared/state/index.ts index 5229521..fc55204 100644 --- a/src/app/shared/state/index.ts +++ b/src/app/shared/state/index.ts @@ -1,12 +1,15 @@ import { ActionReducerMap, createSelector, MetaReducer } from "@ngrx/store"; import * as fromMovies from "./movie.reducer"; +import * as fromBooks from "./books.reducer"; export interface State { movies: fromMovies.State; + books: fromBooks.State; } export const reducers: ActionReducerMap = { - movies: fromMovies.reducer + movies: fromMovies.reducer, + books: fromBooks.reducer }; export const metaReducers: MetaReducer[] = [];