@@ -9,7 +9,7 @@ import { searchFormHelper } from '@helpers';
99import { TranslateService } from '@ngx-translate/core' ;
1010import { UntilDestroy , untilDestroyed } from '@ngneat/until-destroy' ;
1111import { NgxMasonryComponent , NgxMasonryOptions } from 'ngx-masonry' ;
12- import { filter , forkJoin , Subject , Subscription } from 'rxjs' ;
12+ import { filter , forkJoin , Subscription } from 'rxjs' ;
1313import { PostDetailsModalComponent } from '../map' ;
1414import { MainViewComponent } from '@shared' ;
1515import { SessionService , BreakpointService , EventBusService , EventType } from '@services' ;
@@ -18,7 +18,6 @@ import { LanguageService } from '../core/services/language.service';
1818import {
1919 SavedsearchesService ,
2020 PostsService ,
21- GeoJsonFilter ,
2221 PostResult ,
2322 PostStatus ,
2423 postHelpers ,
@@ -43,10 +42,10 @@ export class FeedComponent extends MainViewComponent implements OnInit, OnDestro
4342 private _routerEvent = Subscription . EMPTY ;
4443 @ViewChild ( 'feed' ) public feed : ElementRef ;
4544 @ViewChild ( 'masonry' ) public masonry : NgxMasonryComponent ;
46- private readonly getPostsSubject = new Subject < {
47- params : GeoJsonFilter ;
48- add ?: boolean ;
49- } > ( ) ;
45+ // private readonly getPostsSubject = new Subject<{
46+ // params: GeoJsonFilter;
47+ // add?: boolean;
48+ // }>();
5049 public pagination = {
5150 page : 0 ,
5251 limit : 20 ,
@@ -104,6 +103,7 @@ export class FeedComponent extends MainViewComponent implements OnInit, OnDestro
104103 public initialLoad = true ;
105104 public urlFromRouteTrigger : string ;
106105 public urlAfterInteractionWithFilters : string ;
106+ private postRequests : Subscription [ ] = [ ] ;
107107
108108 constructor (
109109 protected override router : Router ,
@@ -428,17 +428,26 @@ export class FeedComponent extends MainViewComponent implements OnInit, OnDestro
428428 loadData ( ) : void { }
429429
430430 private getPosts ( { params, loadMore } : { params : any ; loadMore ?: boolean } ) : void {
431- /* --------------------------------------------
432- Work with Posts Service to get posts from API
433- ----------------------------------------------*/
434- this . postsService . getPosts ( '' , { ...params , ...this . activeSorting } ) . subscribe ( {
435- next : ( data ) => {
436- this . posts = loadMore ? [ ...this . posts , ...data . results ] : data . results ;
437- } ,
438- // complete: () => {
439- // // console.log('complete?');
440- // },
431+ // Call the posts service, keeping the subscription for later
432+ const postRequestSubscription = this . postsService
433+ . getPosts ( '' , { ...params , ...this . activeSorting } )
434+ . subscribe ( {
435+ next : ( data ) => {
436+ this . posts = loadMore ? [ ...this . posts , ...data . results ] : data . results ;
437+ } ,
438+ } ) ;
439+
440+ // Unsubscribe and destroy existing subscriptions....
441+ this . postRequests . forEach ( ( subscription ) => {
442+ subscription . unsubscribe ( ) ;
441443 } ) ;
444+
445+ // Reset everything so the user sees some loading indicators
446+ this . posts = [ ] ;
447+ this . isLoading = true ;
448+
449+ // Keep the subscription so we can end it later if its replaced with a new api call
450+ this . postRequests . push ( postRequestSubscription ) ;
442451 }
443452
444453 public updateMasonry ( ) : void {
0 commit comments