@@ -2,10 +2,9 @@ import { inject } from "@angular/core";
22import { toObservable } from "@angular/core/rxjs-interop" ;
33import { patchState , signalStore , withHooks , withMethods , withState } from "@ngrx/signals" ;
44import { rxMethod } from "@ngrx/signals/rxjs-interop" ;
5- import { PaginatorState } from "primeng/paginator" ;
5+ import { Pager , withPaginator } from "@shared/store/paginator-feature" ;
6+ import { setFulfilled , setPending , withRequestStatus } from "@shared/store/request-status-feature" ;
67import { debounceTime , pipe , skip , switchMap , tap } from "rxjs" ;
7- import { withPaginator } from "../../../shared/store/paginator-feature" ;
8- import { setFulfilled , setPending , withRequestStatus } from "../../../shared/store/request-status-feature" ;
98import { OpenLibraryApiResult , OpenLibraryRecord } from "../model/open-library.model" ;
109import { OpenLibraryBase } from "../service/open-library-base" ;
1110
@@ -21,16 +20,23 @@ const initialOpenLibraryState = {
2120 documents : [ ]
2221} ;
2322
23+ const initialPagerConfig : Pager = {
24+ page : 1 ,
25+ first : 1 ,
26+ rows : 9 ,
27+ rowsPerPageOptions : [ 9 , 18 , 36 ]
28+ }
29+
2430export const OpenLibraryStore = signalStore (
2531 withState < OpenLibraryState > ( initialOpenLibraryState ) ,
2632 withRequestStatus ( ) ,
27- withPaginator ( ) ,
33+ withPaginator ( initialPagerConfig ) ,
2834 withMethods ( ( store , api = inject ( OpenLibraryBase ) ) => ( {
2935 search : rxMethod < string > (
3036 pipe (
3137 debounceTime ( 500 ) ,
3238 tap ( ( ) => patchState ( store , setPending ( ) ) ) ,
33- switchMap ( ( query : string ) => api . search ( query , store . pager . currentPage ( ) , store . pager . rows ( ) ) ) ,
39+ switchMap ( ( query : string ) => api . search ( query , store . pager . page ( ) , store . pager . rows ( ) ) ) ,
3440 tap ( ( result ?: OpenLibraryApiResult ) => {
3541 if ( result ) {
3642 patchState (
@@ -45,9 +51,6 @@ export const OpenLibraryStore = signalStore(
4551 reset ( ) : void {
4652 patchState ( store , { total : 0 , filter : '' , documents : [ ] } ) ;
4753 } ,
48- setPaginator ( paginator : PaginatorState ) {
49- store . changePage ( paginator ) ;
50- }
5154 } ) ) ,
5255 withHooks ( ( store ) => ( {
5356 onInit : ( ) => {
0 commit comments