7
7
BookRequiredProps
8
8
} from "src/app/shared/models/book.model" ;
9
9
import { BooksService } from "src/app/shared/services/book.service" ;
10
- import { BooksPageActions } from "../../actions" ;
10
+ import { BooksPageActions , BooksApiActions } from "../../actions" ;
11
11
12
12
@Component ( {
13
13
selector : "app-books" ,
@@ -35,6 +35,8 @@ export class BooksPageComponent implements OnInit {
35
35
this . booksService . all ( ) . subscribe ( books => {
36
36
this . books = books ;
37
37
this . updateTotals ( books ) ;
38
+
39
+ this . store . dispatch ( BooksApiActions . booksLoaded ( { books } ) ) ;
38
40
} ) ;
39
41
}
40
42
@@ -69,9 +71,11 @@ export class BooksPageComponent implements OnInit {
69
71
saveBook ( bookProps : BookRequiredProps ) {
70
72
this . store . dispatch ( BooksPageActions . createBook ( { book : bookProps } ) ) ;
71
73
72
- this . booksService . create ( bookProps ) . subscribe ( ( ) => {
74
+ this . booksService . create ( bookProps ) . subscribe ( book => {
73
75
this . getBooks ( ) ;
74
76
this . removeSelectedBook ( ) ;
77
+
78
+ this . store . dispatch ( BooksApiActions . bookCreated ( { book } ) ) ;
75
79
} ) ;
76
80
}
77
81
@@ -80,9 +84,11 @@ export class BooksPageComponent implements OnInit {
80
84
BooksPageActions . updateBook ( { bookId : book . id , changes : book } )
81
85
) ;
82
86
83
- this . booksService . update ( book . id , book ) . subscribe ( ( ) => {
87
+ this . booksService . update ( book . id , book ) . subscribe ( book => {
84
88
this . getBooks ( ) ;
85
89
this . removeSelectedBook ( ) ;
90
+
91
+ this . store . dispatch ( BooksApiActions . bookUpdated ( { book } ) ) ;
86
92
} ) ;
87
93
}
88
94
@@ -92,6 +98,8 @@ export class BooksPageComponent implements OnInit {
92
98
this . booksService . delete ( book . id ) . subscribe ( ( ) => {
93
99
this . getBooks ( ) ;
94
100
this . removeSelectedBook ( ) ;
101
+
102
+ this . store . dispatch ( BooksApiActions . bookDeleted ( { bookId : book . id } ) ) ;
95
103
} ) ;
96
104
}
97
105
}
0 commit comments