diff --git a/src/app/app.config.mock.ts b/src/app/app.config.mock.ts
index fde2d94..35c7453 100644
--- a/src/app/app.config.mock.ts
+++ b/src/app/app.config.mock.ts
@@ -3,13 +3,13 @@ import { ApplicationConfig, inject, provideBrowserGlobalErrorListeners, provideE
import { provideAnimationsAsync } from '@angular/platform-browser/animations/async';
import { provideRouter, TitleStrategy } from '@angular/router';
import Lara from '@primeuix/themes/lara';
+import { AppStateStore } from '@shared/appSate/app-state-store';
+import { PageTitleStrategy } from '@shared/page-title-strategy';
import { MessageService } from 'primeng/api';
import { providePrimeNG } from 'primeng/config';
import { routes } from './app.routes';
import { OpenLibraryBase } from './features/books/service/open-library-base';
import { OpenLibraryMock } from './features/books/service/open-library-mock';
-import { AppStateStore } from './shared/appSate/app-state-store';
-import { PageTitleStrategy } from './shared/page-title-strategy';
export const appConfig: ApplicationConfig = {
providers: [
diff --git a/src/app/app.config.ts b/src/app/app.config.ts
index 3173503..fb41295 100644
--- a/src/app/app.config.ts
+++ b/src/app/app.config.ts
@@ -3,14 +3,14 @@ import { ApplicationConfig, inject, provideBrowserGlobalErrorListeners, provideE
import { provideAnimationsAsync } from '@angular/platform-browser/animations/async';
import { provideRouter, TitleStrategy } from '@angular/router';
import Aura from '@primeuix/themes/Aura';
+import { AppStateStore } from '@shared/appSate/app-state-store';
+import { httpResponseErrorInterceptor } from '@shared/interceptor/http-response-error-interceptor';
+import { PageTitleStrategy } from '@shared/page-title-strategy';
import { MessageService } from 'primeng/api';
import { providePrimeNG } from 'primeng/config';
import { routes } from './app.routes';
import { OpenLibraryApi } from './features/books/service/open-library-api';
import { OpenLibraryBase } from './features/books/service/open-library-base';
-import { AppStateStore } from './shared/appSate/app-state-store';
-import { httpResponseErrorInterceptor } from './shared/interceptor/http-response-error-interceptor';
-import { PageTitleStrategy } from './shared/page-title-strategy';
export const appConfig: ApplicationConfig = {
providers: [
diff --git a/src/app/app.ts b/src/app/app.ts
index 4c9f5af..80e15cb 100644
--- a/src/app/app.ts
+++ b/src/app/app.ts
@@ -1,9 +1,9 @@
import { Component, inject } from '@angular/core';
import { RouterOutlet } from '@angular/router';
+import { AppStateStore } from '@shared/appSate/app-state-store';
+import { LayoutService } from '@shared/layout/layout.service';
import { Toast } from 'primeng/toast';
import { Sidebar } from './features/sidebar/sidebar';
-import { AppStateStore } from './shared/appSate/app-state-store';
-import { LayoutService } from './shared/layout/layout.service';
@Component({
selector: 'app-root',
diff --git a/src/app/features/books/books.html b/src/app/features/books/books.html
index 102e588..287320b 100644
--- a/src/app/features/books/books.html
+++ b/src/app/features/books/books.html
@@ -30,7 +30,7 @@
Bibliothèque
-
+
} @else {
diff --git a/src/app/features/books/books.ts b/src/app/features/books/books.ts
index 9dcf50a..6c02c3e 100644
--- a/src/app/features/books/books.ts
+++ b/src/app/features/books/books.ts
@@ -1,9 +1,8 @@
-import { Component, inject, Signal } from '@angular/core';
-import { deepComputed } from '@ngrx/signals';
-import { PaginatorComponent, PaginatorConfig } from '../../shared/component/paginator';
+import { Component, inject } from '@angular/core';
import { Book } from './book';
import { Search } from './search';
import { OpenLibraryStore } from './store/open-library.store';
+import { PaginatorComponent } from '@shared/component/paginator';
@Component({
selector: 'app-books',
@@ -13,10 +12,4 @@ import { OpenLibraryStore } from './store/open-library.store';
})
export default class Books {
protected store = inject(OpenLibraryStore);
-
- protected paginatorConfig: Signal = deepComputed(() => ({
- first: this.store.pager.firstRecord(),
- rows: this.store.pager.rows(),
- total: this.store.total()
- }));
}
diff --git a/src/app/features/books/store/open-library.store.ts b/src/app/features/books/store/open-library.store.ts
index 7878971..35e39e3 100644
--- a/src/app/features/books/store/open-library.store.ts
+++ b/src/app/features/books/store/open-library.store.ts
@@ -2,10 +2,9 @@ import { inject } from "@angular/core";
import { toObservable } from "@angular/core/rxjs-interop";
import { patchState, signalStore, withHooks, withMethods, withState } from "@ngrx/signals";
import { rxMethod } from "@ngrx/signals/rxjs-interop";
-import { PaginatorState } from "primeng/paginator";
+import { Pager, withPaginator } from "@shared/store/paginator-feature";
+import { setFulfilled, setPending, withRequestStatus } from "@shared/store/request-status-feature";
import { debounceTime, pipe, skip, switchMap, tap } from "rxjs";
-import { withPaginator } from "../../../shared/store/paginator-feature";
-import { setFulfilled, setPending, withRequestStatus } from "../../../shared/store/request-status-feature";
import { OpenLibraryApiResult, OpenLibraryRecord } from "../model/open-library.model";
import { OpenLibraryBase } from "../service/open-library-base";
@@ -21,16 +20,23 @@ const initialOpenLibraryState = {
documents: []
};
+const initialPagerConfig: Pager = {
+ page: 1,
+ first: 1,
+ rows: 9,
+ rowsPerPageOptions: [9, 18, 36]
+}
+
export const OpenLibraryStore = signalStore(
withState(initialOpenLibraryState),
withRequestStatus(),
- withPaginator(),
+ withPaginator(initialPagerConfig),
withMethods((store, api = inject(OpenLibraryBase)) => ({
search: rxMethod(
pipe(
debounceTime(500),
tap(() => patchState(store, setPending())),
- switchMap((query: string) => api.search(query, store.pager.currentPage(), store.pager.rows())),
+ switchMap((query: string) => api.search(query, store.pager.page(), store.pager.rows())),
tap((result?: OpenLibraryApiResult) => {
if (result) {
patchState(
@@ -45,9 +51,6 @@ export const OpenLibraryStore = signalStore(
reset(): void {
patchState(store, { total: 0, filter: '', documents: []});
},
- setPaginator(paginator: PaginatorState) {
- store.changePage(paginator);
- }
})),
withHooks((store) => ({
onInit: () => {
diff --git a/src/app/features/login/login.ts b/src/app/features/login/login.ts
index d2858bf..4729a91 100644
--- a/src/app/features/login/login.ts
+++ b/src/app/features/login/login.ts
@@ -1,10 +1,10 @@
import { Component, inject } from '@angular/core';
import { FormControl, FormGroup, ReactiveFormsModule, Validators } from '@angular/forms';
import { Router, RouterLink } from '@angular/router';
+import { AppStateApi } from '@shared/appSate/app-state-api';
+import { AppStateStore } from '@shared/appSate/app-state-store';
import { Button, ButtonDirective } from "primeng/button";
import { InputText } from 'primeng/inputtext';
-import { AppStateApi } from '../../shared/appSate/app-state-api';
-import { AppStateStore } from '../../shared/appSate/app-state-store';
@Component({
selector: 'app-login',
diff --git a/src/app/features/sidebar/sidebar.ts b/src/app/features/sidebar/sidebar.ts
index 7ddefef..55ddfa4 100644
--- a/src/app/features/sidebar/sidebar.ts
+++ b/src/app/features/sidebar/sidebar.ts
@@ -1,8 +1,8 @@
import { Component, computed, inject, signal } from '@angular/core';
import { Router, RouterLink, RouterLinkActive } from '@angular/router';
+import { AppStateStore } from '@shared/appSate/app-state-store';
+import { LayoutService } from '@shared/layout/layout.service';
import { Avatar } from 'primeng/avatar';
-import { AppStateStore } from '../../shared/appSate/app-state-store';
-import { LayoutService } from '../../shared/layout/layout.service';
@Component({
selector: 'app-sidebar',
diff --git a/src/app/shared/component/paginator.ts b/src/app/shared/component/paginator.ts
index b3becc6..f9307fe 100644
--- a/src/app/shared/component/paginator.ts
+++ b/src/app/shared/component/paginator.ts
@@ -1,11 +1,6 @@
import { Component, input, output } from '@angular/core';
import { Paginator, PaginatorState } from 'primeng/paginator';
-
-export type PaginatorConfig = {
- first: number;
- rows: number;
- total: number;
-}
+import { Pager } from '../store/paginator-feature';
@Component({
selector: 'shared-paginator',
@@ -13,16 +8,18 @@ export type PaginatorConfig = {
template: `
`
})
export class PaginatorComponent {
- paginatorState = input.required();
+ pager = input.required();
+
+ total = input.required();
pageChange = output();
}
diff --git a/src/app/shared/store/paginator-feature.ts b/src/app/shared/store/paginator-feature.ts
index 85ef064..32b9847 100644
--- a/src/app/shared/store/paginator-feature.ts
+++ b/src/app/shared/store/paginator-feature.ts
@@ -1,25 +1,22 @@
import { patchState, signalMethod, signalStoreFeature, withMethods, withState } from "@ngrx/signals";
import { PaginatorState } from "primeng/paginator";
+export type Pager = {
+ page: number;
+ first: number;
+ rows: number;
+ rowsPerPageOptions: number[];
+};
+
export type Paginator = {
- pager: {
- currentPage: number;
- firstRecord: number;
- rows: number;
- }
+ pager: Pager;
}
-const paginatorInitialState: Paginator = {
- pager: {
- currentPage: 1,
- firstRecord: 1,
- rows: 10
- }
-};
-
-export function withPaginator() {
+export function withPaginator(pager: Pager) {
return signalStoreFeature(
- withState(paginatorInitialState),
+ withState({
+ pager: pager
+ }),
withMethods((store) => ({
changePage: signalMethod(event => {
if (event.rows !== store.pager.rows()) {
@@ -28,9 +25,10 @@ export function withPaginator() {
}
patchState(store, {
pager: {
- currentPage: (event.page || 0) + 1,
- firstRecord: (event.page || 0) * (event.rows || 10) + 1,
- rows: (event.rows || 10)
+ page: (event.page || 0) + 1,
+ first: (event.page || 0) * (event.rows || pager.rows) + 1,
+ rows: (event.rows || pager.rows),
+ rowsPerPageOptions: store.pager().rowsPerPageOptions
}
});
}),
diff --git a/tsconfig.app.json b/tsconfig.app.json
index 5afa1a8..791ce73 100644
--- a/tsconfig.app.json
+++ b/tsconfig.app.json
@@ -8,6 +8,7 @@
"baseUrl": "src",
"paths": {
"@env/*": ["environments/*"],
+ "@shared/*": ["app/shared/*"]
}
},
"include": [