11import { Component ,
2- ChangeDetectorRef ,
32 OnInit } from '@angular/core' ;
43
54import {
@@ -21,16 +20,13 @@ import { SnackbarComponent } from './components/snackbar.component';
2120import { NewBookDialog } from './components/new-book-dialog.component' ;
2221
2322import {
24- IFilterItem ,
25- IFilter ,
2623 IProgressMessage ,
27- IFilterAction ,
24+ IAddBookDialogResData ,
25+ IFilter ,
26+ TAvatarIds ,
27+ TBookSortBy ,
2828} from '../vendor' ;
2929
30- import { IAddBookDialogResData } from './vendor' ;
31-
32- import { TAvatarIds } from './vendor' ;
33-
3430@Component ( {
3531 selector : 'app-home' ,
3632 templateUrl : './home.page.html' ,
@@ -42,23 +38,18 @@ export class HomePage implements OnInit {
4238
4339 downloadingList : Array < number > = [ ] ;
4440
45- private _filter : IFilter = {
46- displayRecycled : false ,
47- isOpened : false ,
48- filterList : [ ]
49- } ;
50-
51- get filter ( ) {
52- return this . _filter ;
53- }
54-
41+ sortBy : TBookSortBy = 'openCount' ;
42+ displayRecycled : boolean = false ;
43+ beenOpened : boolean = true ;
44+
5545 constructor (
5646 private crud : CrudService ,
5747 private snackbar : MatSnackBar ,
5848 private dialog : MatDialog ,
5949 private book : BookService ,
6050 ) { }
6151
52+
6253 private changeFabButton = ( button : TAvatarIds ) => {
6354 const buttonList = [ 'currently-reading' , 'on-shelf' , 'recycled' ] ;
6455 document . getElementById ( `avatar-${ button } ` )
@@ -73,6 +64,29 @@ export class HomePage implements OnInit {
7364 } ) ;
7465 }
7566
67+ get currentlyReadingNumber ( ) {
68+ const currentlyReadingFilter : IFilter = {
69+ displayRecycled : false ,
70+ isOpened : true ,
71+ }
72+ return this . book . getList ( currentlyReadingFilter ) . length
73+ }
74+
75+ get onShelfNumber ( ) {
76+ const onShelfFilter : IFilter = {
77+ displayRecycled : false ,
78+ isOpened : true ,
79+ }
80+ return this . book . getList ( onShelfFilter ) . length
81+ }
82+
83+ get recycledNumber ( ) {
84+ const recycledFilter : IFilter = {
85+ displayRecycled : true ,
86+ }
87+ return this . book . getList ( recycledFilter ) . length ;
88+ }
89+
7690 ngOnInit ( ) {
7791 this . crud . ipcRenderer . on ( 'error-occured' , ( ev , book : Book ) => {
7892 this . book . bookUpdated ( book ) ;
@@ -109,29 +123,30 @@ export class HomePage implements OnInit {
109123 } ) ;
110124 }
111125
112- changeFilter = ( filterAction : IFilterAction ) => {
113- let index : number ;
114- switch ( filterAction . action ) {
115- case 'add' :
116- index = this . filter . filterList . findIndex ( ( filterItem : IFilterItem ) => {
117- const key = Object . keys ( filterItem ) [ 0 ] ;
118- const _key = Object . keys ( filterAction . filterItem ) [ 0 ] ;
119- return key === _key && filterItem [ key ] . id === filterAction [ key ] . id ;
120- } ) ;
126+ displayBookListCurrentlyReading = ( ) => {
127+ this . displayRecycled = false ;
128+ this . beenOpened = true ;
121129
122- if ( index < 0 ) this . filter . filterList . push ( filterAction . filterItem ) ;
123- break ;
124- case 'remove' :
125- index = this . filter . filterList . findIndex ( ( filterItem : IFilterItem ) => {
126- const key = Object . keys ( filterItem ) [ 0 ] ;
127- const _key = Object . keys ( filterAction . filterItem ) [ 0 ] ;
128- return key === _key && filterItem [ key ] . id === filterAction [ key ] . id ;
129- } ) ;
130+ this . sortBy = 'openCount' ;
130131
131- if ( index >= 0 ) this . filter . filterList . splice ( index , 1 ) ;
132- break ;
133- }
132+ this . changeFabButton ( 'currently-reading' ) ;
133+ }
134+
135+ displayBookListOnShelf = ( ) => {
136+ this . displayRecycled = false ;
137+ this . beenOpened = false ;
138+
139+ this . sortBy = 'dateCreated' ;
140+
141+ this . changeFabButton ( 'on-shelf' ) ;
142+ }
143+
144+ displayBookListRecycled = ( ) => {
145+ this . displayRecycled = true ;
146+
147+ this . sortBy = 'dateUpdated' ;
134148
149+ this . changeFabButton ( 'recycled' ) ;
135150 }
136151
137152 openAddBookDialog = ( ) => {
0 commit comments