@@ -9,7 +9,7 @@ import { MatToolbarModule } from '@angular/material/toolbar'
99import { MatButtonToggleModule } from '@angular/material/button-toggle'
1010import { MatIconModule } from '@angular/material/icon'
1111import { RowSpacer } from '../../components/row-spacer/row-spacer'
12- import { Router } from '@angular/router'
12+ import { ActivatedRoute , Router } from '@angular/router'
1313import { Article } from '../../entities/article/article.types'
1414import { MatPaginatorModule } from '@angular/material/paginator'
1515import { TagService } from '../../services/tag-service'
@@ -44,6 +44,7 @@ import { SortOrder } from '../../entities/base/base.enums'
4444export class HomePage implements OnInit {
4545 feedService = inject ( FeedService )
4646 router = inject ( Router )
47+ route = inject ( ActivatedRoute )
4748 destroyRef = inject ( DestroyRef )
4849 tagService = inject ( TagService )
4950 titleService = inject ( TitleService )
@@ -54,6 +55,7 @@ export class HomePage implements OnInit {
5455
5556 $readFilter = new BehaviorSubject ( true )
5657 $favFilter = new BehaviorSubject ( false )
58+ $subscriptionFilter = new BehaviorSubject < string | null > ( null )
5759 $dateOrder = new BehaviorSubject ( SortOrder . Desc )
5860
5961 favTagId = signal < string > ( '' )
@@ -93,9 +95,10 @@ export class HomePage implements OnInit {
9395 this . pageService . $currentPage ,
9496 this . $favFilter ,
9597 this . $readFilter ,
98+ this . $subscriptionFilter ,
9699 this . $dateOrder ,
97100 ] ) . pipe (
98- switchMap ( ( [ perPage , pageNumber , fav , read , dateSort ] ) => {
101+ switchMap ( ( [ perPage , pageNumber , fav , read , subscription , dateSort ] ) => {
99102 const filters : Record < string , string | boolean > = { }
100103
101104 if ( read ) {
@@ -106,6 +109,10 @@ export class HomePage implements OnInit {
106109 filters [ 'tags' ] = favTag
107110 }
108111
112+ if ( subscription ) {
113+ filters [ 'subscription' ] = subscription
114+ }
115+
109116 return this . feedService . getAllArticles ( {
110117 pagination : {
111118 perPage,
@@ -124,9 +131,31 @@ export class HomePage implements OnInit {
124131 if ( result ) {
125132 this . articles . set ( result . result )
126133 this . pageService . setTotalResults ( result . total )
127- this . titleService . setTitle ( `News : ${ result . total } articles` )
134+ this . titleService . setTitle ( `Articles : ${ result . total } articles` )
128135 } else {
129- this . titleService . setTitle ( 'News' )
136+ this . titleService . setTitle ( 'Articles' )
137+ }
138+ } )
139+
140+ this . route . queryParams
141+ . pipe (
142+ takeUntilDestroyed ( this . destroyRef ) ,
143+ switchMap ( ( params ) => {
144+ const subscriptionId : string = params [ 'subscription' ]
145+ if ( ! subscriptionId ) {
146+ return of ( null )
147+ }
148+ return this . feedService . getOneSubscription ( { subscriptionId } )
149+ } ) ,
150+ catchError ( ( e ) => {
151+ console . error ( e )
152+ return of ( null )
153+ } ) ,
154+ )
155+ . subscribe ( ( feed ) => {
156+ if ( feed ) {
157+ this . titleService . setSubtitle ( feed . title )
158+ this . $subscriptionFilter . next ( feed . _id )
130159 }
131160 } )
132161 }
@@ -165,9 +194,9 @@ export class HomePage implements OnInit {
165194 if ( filter === 'read' ) {
166195 this . $readFilter . next ( ! this . $readFilter . value )
167196 } else {
168- this . pageService . setCurrentPage ( 1 )
197+ this . $favFilter . next ( ! this . $favFilter . value )
169198 }
170- this . $favFilter . next ( ! this . $favFilter . value )
199+ this . pageService . setCurrentPage ( 1 )
171200 }
172201
173202 orderHandler ( param : 'date' ) {
0 commit comments