11import { Component , Input , OnChanges , SimpleChanges } from '@angular/core' ;
22import { FeedMenuEnum } from "../../../common/models/view/feed.view-model" ;
33import { ArticleService } from "../../../common/services/api/article.service" ;
4- import { Article , ArticlesResponse } from "../../../common/models/api/article.model" ;
4+ import { Article , ArticlesResponse , QueryArticlesParams } from "../../../common/models/api/article.model" ;
55import { Observable } from "rxjs" ;
6- import { DEFAULT_PROFILE_IMAGE , QUERY_PAGE_SIZE } from "../../../common/constants/default.constant" ;
6+ import { QUERY_PAGE_SIZE } from "../../../common/constants/default.constant" ;
77
88@Component ( {
99 selector : 'app-feed' ,
1010 templateUrl : './feed.component.html' ,
1111 styleUrl : './feed.component.scss'
1212} )
1313export class FeedComponent implements OnChanges {
14- public readonly DEFAULT_PROFILE_IMAGE = DEFAULT_PROFILE_IMAGE ;
1514 @Input ( ) feedMenuId ?: FeedMenuEnum ;
15+ @Input ( ) queryParams ?: Partial < QueryArticlesParams > = { } ;
1616
1717 public articles : Article [ ] = [ ] ;
1818 public activePageIndex = 0 ;
@@ -27,10 +27,13 @@ export class FeedComponent implements OnChanges {
2727 if ( changes [ 'feedMenuId' ] ?. currentValue ) {
2828 this . _queryFeed ( ) ;
2929 }
30+
31+ if ( changes [ 'queryParams' ] ?. currentValue ) {
32+ this . _queryFeed ( ) ;
33+ }
3034 }
3135
32- private _queryFeed ( pageIndex = 0 ) : void {
33- console . log ( pageIndex )
36+ private _queryFeed ( ) : void {
3437 this . _constructQueryRequest ( ) . subscribe ( ( response :ArticlesResponse ) => {
3538 this . articles = response . articles ;
3639 this . totalPages = Math . ceil ( response . articlesCount / QUERY_PAGE_SIZE ) ;
@@ -39,6 +42,7 @@ export class FeedComponent implements OnChanges {
3942
4043 private _constructQueryRequest ( ) : Observable < ArticlesResponse > {
4144 const queryParams = {
45+ ...this . queryParams ,
4246 limit : QUERY_PAGE_SIZE ,
4347 offset : this . activePageIndex * QUERY_PAGE_SIZE
4448 } ;
@@ -56,6 +60,6 @@ export class FeedComponent implements OnChanges {
5660 }
5761
5862 this . activePageIndex = pageIndex ;
59- this . _queryFeed ( this . activePageIndex ) ;
63+ this . _queryFeed ( ) ;
6064 }
6165}
0 commit comments