Skip to content

Commit 6df2a12

Browse files
authored
Fix search pagination cache + stop subscriptions (#170)
* FIX search pagination cache * FIX pagination's cache on catalog search + close every subscription when components are destroyed
1 parent c27d9c5 commit 6df2a12

64 files changed

Lines changed: 910 additions & 197 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/app/offerings/gallery/gallery.component.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,25 @@
1-
import { Component, OnInit, ChangeDetectorRef } from '@angular/core';
1+
import { Component, OnInit, ChangeDetectorRef, OnDestroy } from '@angular/core';
22
import { CommonModule } from '@angular/common';
33
import {CardComponent} from "../../shared/card/card.component";
44
import {components} from "../../models/product-catalog";
55
type ProductOffering = components["schemas"]["ProductOffering"];
66
import { ApiServiceService } from 'src/app/services/product-service.service';
77
import {ThemeService} from "../../services/theme.service";
88
import {ThemeConfig} from "../../themes";
9-
import { Subscription } from 'rxjs';
9+
import { Subscription, Subject } from 'rxjs';
10+
import { takeUntil } from 'rxjs/operators';
1011

1112
@Component({
1213
selector: 'bae-off-gallery',
1314
templateUrl: './gallery.component.html',
1415
styleUrl: './gallery.component.css'
1516
})
16-
export class GalleryComponent implements OnInit {
17+
export class GalleryComponent implements OnInit, OnDestroy {
1718

1819
products: ProductOffering[]=[];
1920
private themeSubscription: Subscription = new Subscription();
2021
currentTheme: ThemeConfig | null = null;
22+
private destroy$ = new Subject<void>();
2123

2224
constructor(
2325
private api: ApiServiceService,
@@ -29,7 +31,9 @@ export class GalleryComponent implements OnInit {
2931
gallery_limit=4;
3032

3133
ngOnInit() {
32-
this.themeSubscription = this.themeService.currentTheme$.subscribe(theme => {
34+
this.themeSubscription = this.themeService.currentTheme$
35+
.pipe(takeUntil(this.destroy$))
36+
.subscribe(theme => {
3337
this.currentTheme = theme;
3438
});
3539
console.log('API RESPONSE:')
@@ -107,4 +111,9 @@ export class GalleryComponent implements OnInit {
107111
console.log(this.products)
108112
}
109113

114+
ngOnDestroy(){
115+
this.destroy$.next();
116+
this.destroy$.complete();
117+
}
118+
110119
}

src/app/pages/admin/admin.component.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, OnInit, ChangeDetectorRef } from '@angular/core';
1+
import { Component, OnInit, ChangeDetectorRef, OnDestroy } from '@angular/core';
22
import { Router } from '@angular/router';
33
import { FormControl } from '@angular/forms';
44
import {faIdCard, faSort, faSwatchbook} from "@fortawesome/pro-solid-svg-icons";
@@ -10,26 +10,31 @@ import {LocalStorageService} from "src/app/services/local-storage.service";
1010
import { LoginInfo } from 'src/app/models/interfaces';
1111
import { initFlowbite } from 'flowbite';
1212
import {EventMessageService} from "../../services/event-message.service";
13+
import { Subject } from 'rxjs';
14+
import { takeUntil } from 'rxjs/operators';
1315

1416
@Component({
1517
selector: 'app-admin',
1618
templateUrl: './admin.component.html',
1719
styleUrl: './admin.component.css'
1820
})
19-
export class AdminComponent implements OnInit {
21+
export class AdminComponent implements OnInit, OnDestroy {
2022
show_categories:boolean = true;
2123
show_create_categories:boolean = false;
2224
show_update_categories:boolean = false;
2325
show_verification:boolean = false;
2426
show_revenue:boolean = false;
27+
private destroy$ = new Subject<void>();
2528

2629
category_to_update:any;
2730
constructor(
2831
private localStorage: LocalStorageService,
2932
private cdr: ChangeDetectorRef,
3033
private eventMessage: EventMessageService
3134
) {
32-
this.eventMessage.messages$.subscribe(ev => {
35+
this.eventMessage.messages$
36+
.pipe(takeUntil(this.destroy$))
37+
.subscribe(ev => {
3338
if(ev.type === 'AdminCategories' && ev.value == true) {
3439
this.goToCategories();
3540
}
@@ -47,6 +52,11 @@ export class AdminComponent implements OnInit {
4752
console.log('init')
4853
}
4954

55+
ngOnDestroy(){
56+
this.destroy$.next();
57+
this.destroy$.complete();
58+
}
59+
5060
goToCategories(){
5161
this.selectCategories();
5262
this.show_categories = true;

src/app/pages/admin/categories/categories.component.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, OnInit, ChangeDetectorRef } from '@angular/core';
1+
import { Component, OnInit, ChangeDetectorRef, OnDestroy } from '@angular/core';
22
import { Router } from '@angular/router';
33
import { FormControl } from '@angular/forms';
44
import {faIdCard, faSort, faSwatchbook} from "@fortawesome/pro-solid-svg-icons";
@@ -10,13 +10,15 @@ import {LocalStorageService} from "src/app/services/local-storage.service";
1010
import { LoginInfo } from 'src/app/models/interfaces';
1111
import {EventMessageService} from "src/app/services/event-message.service";
1212
import { initFlowbite } from 'flowbite';
13+
import { Subject } from 'rxjs';
14+
import { takeUntil } from 'rxjs/operators';
1315

1416
@Component({
1517
selector: 'admin-categories',
1618
templateUrl: './categories.component.html',
1719
styleUrl: './categories.component.css'
1820
})
19-
export class CategoriesComponent {
21+
export class CategoriesComponent implements OnDestroy {
2022
protected readonly faIdCard = faIdCard;
2123
protected readonly faSort = faSort;
2224
protected readonly faSwatchbook = faSwatchbook;
@@ -29,6 +31,7 @@ export class CategoriesComponent {
2931
loading: boolean = false;
3032
partyId:any;
3133
status:any[]=['Active','Launched'];
34+
private destroy$ = new Subject<void>();
3235

3336
constructor(
3437
private router: Router,
@@ -37,7 +40,9 @@ export class CategoriesComponent {
3740
private localStorage: LocalStorageService,
3841
private eventMessage: EventMessageService,
3942
) {
40-
this.eventMessage.messages$.subscribe(ev => {
43+
this.eventMessage.messages$
44+
.pipe(takeUntil(this.destroy$))
45+
.subscribe(ev => {
4146
if(ev.type === 'ChangedSession') {
4247
this.initCatalogs();
4348
}
@@ -48,6 +53,11 @@ export class CategoriesComponent {
4853
this.initCatalogs();
4954
}
5055

56+
ngOnDestroy(){
57+
this.destroy$.next();
58+
this.destroy$.complete();
59+
}
60+
5161
initCatalogs(){
5262
this.loading=true;
5363
this.categories=[];

src/app/pages/admin/categories/create-category/create-category.component.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, OnInit, ChangeDetectorRef, HostListener, ElementRef, ViewChild } from '@angular/core';
1+
import { Component, OnInit, ChangeDetectorRef, HostListener, ElementRef, ViewChild, OnDestroy } from '@angular/core';
22
import { Router } from '@angular/router';
33
import { ApiServiceService } from 'src/app/services/product-service.service';
44
import {LocalStorageService} from "src/app/services/local-storage.service";
@@ -7,6 +7,8 @@ import { LoginInfo } from 'src/app/models/interfaces';
77
import { initFlowbite } from 'flowbite';
88
import { FormGroup, FormControl, Validators } from '@angular/forms';
99
import * as moment from 'moment';
10+
import { Subject } from 'rxjs';
11+
import { takeUntil } from 'rxjs/operators';
1012

1113
import {components} from "src/app/models/product-catalog";
1214
type Category_Create = components["schemas"]["Category_Create"];
@@ -16,7 +18,7 @@ type Category_Create = components["schemas"]["Category_Create"];
1618
templateUrl: './create-category.component.html',
1719
styleUrl: './create-category.component.css'
1820
})
19-
export class CreateCategoryComponent implements OnInit {
21+
export class CreateCategoryComponent implements OnInit, OnDestroy {
2022
partyId:any='';
2123
categoryToCreate:Category_Create | undefined;
2224

@@ -50,6 +52,7 @@ export class CreateCategoryComponent implements OnInit {
5052

5153
errorMessage:any='';
5254
showError:boolean=false;
55+
private destroy$ = new Subject<void>();
5356

5457
constructor(
5558
private router: Router,
@@ -59,7 +62,9 @@ export class CreateCategoryComponent implements OnInit {
5962
private elementRef: ElementRef,
6063
private api: ApiServiceService
6164
) {
62-
this.eventMessage.messages$.subscribe(ev => {
65+
this.eventMessage.messages$
66+
.pipe(takeUntil(this.destroy$))
67+
.subscribe(ev => {
6368
if(ev.type === 'ChangedSession') {
6469
this.initPartyInfo();
6570
}
@@ -81,6 +86,11 @@ export class CreateCategoryComponent implements OnInit {
8186
this.initPartyInfo();
8287
}
8388

89+
ngOnDestroy(){
90+
this.destroy$.next();
91+
this.destroy$.complete();
92+
}
93+
8494
initPartyInfo(){
8595
let aux = this.localStorage.getObject('login_items') as LoginInfo;
8696
if(JSON.stringify(aux) != '{}' && (((aux.expire - moment().unix())-4) > 0)) {

src/app/pages/admin/categories/update-category/update-category.component.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, OnInit, ChangeDetectorRef, HostListener, ElementRef, ViewChild, Input } from '@angular/core';
1+
import { Component, OnInit, ChangeDetectorRef, HostListener, ElementRef, ViewChild, Input, OnDestroy } from '@angular/core';
22
import { Router } from '@angular/router';
33
import { ApiServiceService } from 'src/app/services/product-service.service';
44
import {LocalStorageService} from "src/app/services/local-storage.service";
@@ -7,6 +7,8 @@ import { LoginInfo } from 'src/app/models/interfaces';
77
import { initFlowbite } from 'flowbite';
88
import { FormGroup, FormControl, Validators } from '@angular/forms';
99
import * as moment from 'moment';
10+
import { Subject } from 'rxjs';
11+
import { takeUntil } from 'rxjs/operators';
1012

1113
import {components} from "src/app/models/product-catalog";
1214
type Category_Update = components["schemas"]["Category_Update"];
@@ -16,7 +18,7 @@ type Category_Update = components["schemas"]["Category_Update"];
1618
templateUrl: './update-category.component.html',
1719
styleUrl: './update-category.component.css'
1820
})
19-
export class UpdateCategoryComponent implements OnInit {
21+
export class UpdateCategoryComponent implements OnInit, OnDestroy {
2022
@Input() category: any;
2123

2224
partyId:any='';
@@ -55,6 +57,7 @@ export class UpdateCategoryComponent implements OnInit {
5557

5658
errorMessage:any='';
5759
showError:boolean=false;
60+
private destroy$ = new Subject<void>();
5861

5962
constructor(
6063
private router: Router,
@@ -64,7 +67,9 @@ export class UpdateCategoryComponent implements OnInit {
6467
private elementRef: ElementRef,
6568
private api: ApiServiceService
6669
) {
67-
this.eventMessage.messages$.subscribe(ev => {
70+
this.eventMessage.messages$
71+
.pipe(takeUntil(this.destroy$))
72+
.subscribe(ev => {
6873
if(ev.type === 'ChangedSession') {
6974
this.initPartyInfo();
7075
}
@@ -86,6 +91,11 @@ export class UpdateCategoryComponent implements OnInit {
8691
this.initPartyInfo();
8792
}
8893

94+
ngOnDestroy(){
95+
this.destroy$.next();
96+
this.destroy$.complete();
97+
}
98+
8999
initPartyInfo(){
90100
let aux = this.localStorage.getObject('login_items') as LoginInfo;
91101
if(JSON.stringify(aux) != '{}' && (((aux.expire - moment().unix())-4) > 0)) {

src/app/pages/checkout/billing-address/billing-address.component.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
1-
import {Component, EventEmitter, HostListener, Input, OnInit, Output} from '@angular/core';
1+
import {Component, EventEmitter, HostListener, Input, OnDestroy, OnInit, Output} from '@angular/core';
22
import {billingAccountCart} from "../../../models/interfaces";
33
import {TranslateModule} from "@ngx-translate/core";
44
import {NgClass} from "@angular/common";
55
import {BillingAccountFormComponent} from "../../../shared/billing-account-form/billing-account-form.component";
66
import { AccountServiceService } from 'src/app/services/account-service.service';
77
import { LocalStorageService } from 'src/app/services/local-storage.service';
88
import {EventMessageService} from "../../../services/event-message.service";
9+
import { Subject } from 'rxjs';
10+
import { takeUntil } from 'rxjs/operators';
911

1012
@Component({
1113
selector: 'app-billing-address',
1214
templateUrl: './billing-address.component.html',
1315
styleUrl: './billing-address.component.css'
1416
})
15-
export class BillingAddressComponent {
17+
export class BillingAddressComponent implements OnDestroy {
1618
@Input() position: number = 0;
1719
@Input() data: billingAccountCart = {
1820
id: '',
@@ -32,13 +34,16 @@ export class BillingAddressComponent {
3234
};
3335
@Output() selectedEvent= new EventEmitter<billingAccountCart>();
3436
@Output() deletedEvent= new EventEmitter<billingAccountCart>();
37+
private destroy$ = new Subject<void>();
3538

3639
constructor(
3740
private localStorage: LocalStorageService,
3841
private accountService: AccountServiceService,
3942
private eventMessage: EventMessageService
4043
) {
41-
this.eventMessage.messages$.subscribe(ev => {
44+
this.eventMessage.messages$
45+
.pipe(takeUntil(this.destroy$))
46+
.subscribe(ev => {
4247
if(ev.value == false){
4348
this.editBill=false;
4449
}
@@ -84,4 +89,9 @@ export class BillingAddressComponent {
8489
return false
8590
}
8691
}
92+
93+
ngOnDestroy(){
94+
this.destroy$.next();
95+
this.destroy$.complete();
96+
}
8797
}

src/app/pages/checkout/checkout.component.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {ChangeDetectorRef, Component, HostListener, OnInit} from '@angular/core';
1+
import {ChangeDetectorRef, Component, HostListener, OnDestroy, OnInit} from '@angular/core';
22
import {firstValueFrom, lastValueFrom} from 'rxjs';
33
import {TranslateModule} from "@ngx-translate/core";
44
import {LocalStorageService} from "../../services/local-storage.service";
@@ -20,14 +20,16 @@ import {BillingAccountFormComponent} from "../../shared/billing-account-form/bil
2020
import { PaymentService } from 'src/app/services/payment.service';
2121
import { v4 as uuidv4 } from 'uuid';
2222
import { data } from 'jquery';
23+
import { Subject } from 'rxjs';
24+
import { takeUntil } from 'rxjs/operators';
2325

2426

2527
@Component({
2628
selector: 'app-checkout',
2729
templateUrl: './checkout.component.html',
2830
styleUrl: './checkout.component.css'
2931
})
30-
export class CheckoutComponent implements OnInit {
32+
export class CheckoutComponent implements OnInit, OnDestroy {
3133
protected readonly faCartShopping = faCartShopping;
3234
public static BASE_URL: String = environment.BASE_URL;
3335
PURCHASE_ENABLED: boolean = environment.PURCHASE_ENABLED;
@@ -52,6 +54,7 @@ export class CheckoutComponent implements OnInit {
5254
providerId:any = null;
5355
loadingItems:boolean=false;
5456
orderNote: string = '';
57+
private destroy$ = new Subject<void>();
5558

5659
constructor(
5760
private localStorage: LocalStorageService,
@@ -67,7 +70,9 @@ export class CheckoutComponent implements OnInit {
6770
private route: ActivatedRoute) {
6871
// Bind the method to preserve context
6972
this.orderProduct = this.orderProduct.bind(this);
70-
this.eventMessage.messages$.subscribe(async ev => {
73+
this.eventMessage.messages$
74+
.pipe(takeUntil(this.destroy$))
75+
.subscribe(async ev => {
7176
if (ev.type === 'BillAccChanged') {
7277
this.getBilling();
7378
}
@@ -363,6 +368,11 @@ export class CheckoutComponent implements OnInit {
363368
}
364369
}
365370

371+
ngOnDestroy(){
372+
this.destroy$.next();
373+
this.destroy$.complete();
374+
}
375+
366376
async initCheckoutData() {
367377
this.providerId = this.route.snapshot.paramMap.get('id');
368378
let aux = this.localStorage.getObject('login_items') as LoginInfo;

0 commit comments

Comments
 (0)