Created
August 24, 2022 03:49
-
-
Save touhidrahman/ede43a2efe7d54beb2f58e9769baeb9c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<main> | |
<app-movie-card | |
*ngFor="let movie of movies$ | async" | |
[movie]="movie] | |
></app-movie-card> | |
</main> | |
<app-pagination | |
[currentPage]="page$ | async" | |
[totalPages]="totalPages$ | async" | |
[size]="size$ | async" | |
[routerLinkBase]="['/movies']" | |
></app-pagination> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export class MovieListPageComponent { | |
page$: Observable<number> = this.activatedRoute.queryParams.pipe(map(({page}) => page ? +page : 1)) | |
size$: Observable<number> = this.activatedRoute.queryParams.pipe(map(({size}) => size ? +size : 24)) | |
movies$: Observable<Movie[]> | |
totalPages$: Observable<number> | |
constructor( | |
private movieService: MovieService, | |
private activatedRoute: ActivatedRoute | |
) { | |
this.movies$ = combineLatest({ | |
page: this.page$, | |
size: this.size$, | |
}).pipe( | |
debounceTime(200), | |
switchMap(({ page, size }) => { | |
return this.movieService.find({ page, size}) | |
}) | |
) | |
this.totalPages$ = combineLatest({ | |
total: this.movieService.count(), | |
size: this.size$, | |
}).pipe( | |
switchMap(({ total, size }) => { | |
return Math.ceil(total / size) | |
}) | |
) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment