77 BookRequiredProps
88} from "src/app/shared/models/book.model" ;
99import { BooksService } from "src/app/shared/services/book.service" ;
10- import { BooksPageActions } from "../../actions" ;
10+ import { BooksPageActions , BooksApiActions } from "../../actions" ;
1111
1212@Component ( {
1313 selector : "app-books" ,
@@ -35,6 +35,8 @@ export class BooksPageComponent implements OnInit {
3535 this . booksService . all ( ) . subscribe ( books => {
3636 this . books = books ;
3737 this . updateTotals ( books ) ;
38+
39+ this . store . dispatch ( BooksApiActions . booksLoaded ( { books } ) ) ;
3840 } ) ;
3941 }
4042
@@ -69,9 +71,11 @@ export class BooksPageComponent implements OnInit {
6971 saveBook ( bookProps : BookRequiredProps ) {
7072 this . store . dispatch ( BooksPageActions . createBook ( { book : bookProps } ) ) ;
7173
72- this . booksService . create ( bookProps ) . subscribe ( ( ) => {
74+ this . booksService . create ( bookProps ) . subscribe ( book => {
7375 this . getBooks ( ) ;
7476 this . removeSelectedBook ( ) ;
77+
78+ this . store . dispatch ( BooksApiActions . bookCreated ( { book } ) ) ;
7579 } ) ;
7680 }
7781
@@ -80,9 +84,11 @@ export class BooksPageComponent implements OnInit {
8084 BooksPageActions . updateBook ( { bookId : book . id , changes : book } )
8185 ) ;
8286
83- this . booksService . update ( book . id , book ) . subscribe ( ( ) => {
87+ this . booksService . update ( book . id , book ) . subscribe ( book => {
8488 this . getBooks ( ) ;
8589 this . removeSelectedBook ( ) ;
90+
91+ this . store . dispatch ( BooksApiActions . bookUpdated ( { book } ) ) ;
8692 } ) ;
8793 }
8894
@@ -92,6 +98,8 @@ export class BooksPageComponent implements OnInit {
9298 this . booksService . delete ( book . id ) . subscribe ( ( ) => {
9399 this . getBooks ( ) ;
94100 this . removeSelectedBook ( ) ;
101+
102+ this . store . dispatch ( BooksApiActions . bookDeleted ( { bookId : book . id } ) ) ;
95103 } ) ;
96104 }
97105}
0 commit comments