From a23afc29d2c2875cb1ee3059256d68b43b9ee726 Mon Sep 17 00:00:00 2001 From: "konstantina.galouni" Date: Thu, 6 Jul 2023 16:14:31 +0300 Subject: [PATCH] [Explore | develop]: [Bug fix] Refactor code for showing help button or not. 1. home.component.ts: Removed field "showQuickContact" | In constructor set quickContactService.setDisplay(false) and in ngOnDestroy quickContactService.setDisplay(true) | Refactor intersectionObserver. 2. app.component.ts: Updated checks for | Added public bottomNotIntersecting: boolean; and public displayQuickContact: boolean; (check if intersecting with specific section in home page) | Added disconnect in ngOnDestroy for IntersectionObserver subscriptions. --- explore/src/app/app.component.ts | 33 ++++++++++++++++---------- explore/src/app/home/home.component.ts | 11 +++------ explore/src/app/openaireLibrary | 2 +- 3 files changed, 24 insertions(+), 22 deletions(-) diff --git a/explore/src/app/app.component.ts b/explore/src/app/app.component.ts index 5292ea5c..c92c2699 100644 --- a/explore/src/app/app.component.ts +++ b/explore/src/app/app.component.ts @@ -52,7 +52,7 @@ import {LayoutService} from './openaireLibrary/dashboard/sharedComponents/sideba - ` @@ -65,7 +65,10 @@ export class AppComponent { properties: EnvProperties = properties; user: User; header: Header; - public showQuickContact: boolean; + /* Contact */ + public showQuickContact: boolean; + public bottomNotIntersecting: boolean; + public displayQuickContact: boolean; // intersecting with specific section in home page public contactForm: FormGroup; public sending: boolean = false; @ViewChild('quickContact') quickContact: QuickContactComponent; @@ -85,10 +88,6 @@ export class AppComponent { if (typeof document !== 'undefined') { this.isClient = true; } - this.subscriptions.push(this.layoutService.hasQuickContact.subscribe(hasQuickContact => { - this.showQuickContact = hasQuickContact; - this.cdr.detectChanges(); - })); this.configurationService.initCommunityInformation(this.properties, this.properties.adminToolsCommunity); this.feedbackmail = this.properties.feedbackmail; if (this.properties.environment == "production" || this.properties.environment == "development") { @@ -111,9 +110,18 @@ export class AppComponent { badge: true }; this.reset(); + })); + this.subscriptions.push(this.layoutService.hasQuickContact.subscribe(hasQuickContact => { + if(this.showQuickContact !== hasQuickContact) { + this.showQuickContact = hasQuickContact; + this.cdr.detectChanges(); + } })); this.subscriptions.push(this.quickContactService.isDisplayed.subscribe(display => { - this.showQuickContact = display; + if(this.displayQuickContact !== display) { + this.displayQuickContact = display; + this.cdr.detectChanges(); + } })); } @@ -121,6 +129,8 @@ export class AppComponent { this.subscriptions.forEach(subscription => { if (subscription instanceof Subscriber) { subscription.unsubscribe(); + } else if (typeof IntersectionObserver !== "undefined" && subscription instanceof IntersectionObserver) { + subscription.disconnect(); } }); this.configurationService.clearSubscriptions(); @@ -142,12 +152,9 @@ export class AppComponent { }; let intersectionObserver = new IntersectionObserver(entries => { entries.forEach(entry => { - if (entry.isIntersecting && this.showQuickContact) { - this.showQuickContact = false; - this.quickContactService.setDisplay(this.showQuickContact); - } else if (!entry.isIntersecting && !this.showQuickContact) { - this.showQuickContact = true; - this.quickContactService.setDisplay(this.showQuickContact); + if(this.bottomNotIntersecting !== (!entry.isIntersecting)) { + this.bottomNotIntersecting = !entry.isIntersecting; + this.cdr.detectChanges(); } }); }, options); diff --git a/explore/src/app/home/home.component.ts b/explore/src/app/home/home.component.ts index c05576ed..c4a40ced 100644 --- a/explore/src/app/home/home.component.ts +++ b/explore/src/app/home/home.component.ts @@ -121,7 +121,6 @@ export class HomeComponent implements OnInit, OnDestroy, AfterViewInit { public properties: EnvProperties = properties; public openaireEntities = OpenaireEntities; public readMore: boolean = false; - public showQuickContact: boolean; @ViewChild('contact') contact: ElementRef; subscriptions: any[] = []; @ViewChildren('scrolling_element') elements: QueryList; @@ -173,6 +172,7 @@ export class HomeComponent implements OnInit, OnDestroy, AfterViewInit { this._meta.updateTag({content: description}, "name='description'"); this._meta.updateTag({content: description}, "property='og:description'"); this._meta.updateTag({content: title}, "property='og:title'"); + this.quickContactService.setDisplay(false); } private getPageContents() { @@ -281,6 +281,7 @@ export class HomeComponent implements OnInit, OnDestroy, AfterViewInit { public ngOnDestroy() { + this.quickContactService.setDisplay(true); this.clear(); } @@ -298,13 +299,7 @@ export class HomeComponent implements OnInit, OnDestroy, AfterViewInit { }; let intersectionObserver = new IntersectionObserver(entries => { entries.forEach(entry => { - if (entry.isIntersecting && this.showQuickContact) { - this.showQuickContact = false; - this.quickContactService.setDisplay(this.showQuickContact); - } else if (!entry.isIntersecting && !this.showQuickContact) { - this.showQuickContact = true; - this.quickContactService.setDisplay(this.showQuickContact); - } + this.quickContactService.setDisplay(!entry.isIntersecting); }); }, options); intersectionObserver.observe(this.contact.nativeElement); diff --git a/explore/src/app/openaireLibrary b/explore/src/app/openaireLibrary index ea1b054b..8b14aaf3 160000 --- a/explore/src/app/openaireLibrary +++ b/explore/src/app/openaireLibrary @@ -1 +1 @@ -Subproject commit ea1b054b63502fe0cd9dcc7a5559b456ea2a1fc7 +Subproject commit 8b14aaf325c4c18691be36a89dca882b945d8eb0