88 selectBooksEarningsTotals
99} from "src/app/shared/state" ;
1010import { BookModel , BookRequiredProps } from "src/app/shared/models/book.model" ;
11- import { BooksService } from "src/app/shared/services/book.service" ;
12- import { BooksPageActions , BooksApiActions } from "../../actions" ;
11+ import { BooksPageActions } from "../../actions" ;
1312
1413@Component ( {
1514 selector : "app-books" ,
@@ -21,7 +20,7 @@ export class BooksPageComponent implements OnInit {
2120 currentBook$ : Observable < BookModel | null > ;
2221 total$ : Observable < number > ;
2322
24- constructor ( private booksService : BooksService , private store : Store < State > ) {
23+ constructor ( private store : Store < State > ) {
2524 this . books$ = store . select ( selectAllBooks ) ;
2625 this . currentBook$ = store . select ( selectActiveBook ) ;
2726 this . total$ = store . select ( selectBooksEarningsTotals ) ;
@@ -53,31 +52,15 @@ export class BooksPageComponent implements OnInit {
5352
5453 saveBook ( bookProps : BookRequiredProps ) {
5554 this . store . dispatch ( BooksPageActions . createBook ( { book : bookProps } ) ) ;
56-
57- this . booksService . create ( bookProps ) . subscribe ( book => {
58- this . removeSelectedBook ( ) ;
59-
60- this . store . dispatch ( BooksApiActions . bookCreated ( { book } ) ) ;
61- } ) ;
6255 }
6356
6457 updateBook ( book : BookModel ) {
6558 this . store . dispatch (
6659 BooksPageActions . updateBook ( { bookId : book . id , changes : book } )
6760 ) ;
68-
69- this . booksService . update ( book . id , book ) . subscribe ( book => {
70- this . store . dispatch ( BooksApiActions . bookUpdated ( { book } ) ) ;
71- } ) ;
7261 }
7362
7463 onDelete ( book : BookModel ) {
7564 this . store . dispatch ( BooksPageActions . deleteBook ( { bookId : book . id } ) ) ;
76-
77- this . booksService . delete ( book . id ) . subscribe ( ( ) => {
78- this . removeSelectedBook ( ) ;
79-
80- this . store . dispatch ( BooksApiActions . bookDeleted ( { bookId : book . id } ) ) ;
81- } ) ;
8265 }
8366}
0 commit comments