Skip to content
This repository was archived by the owner on Feb 5, 2022. It is now read-only.

Commit 4f282a1

Browse files
fix(app-team-landing): add resize to function and remove event listener on leave
1 parent 0559fae commit 4f282a1

File tree

2 files changed

+37
-24
lines changed

2 files changed

+37
-24
lines changed

src/pages/app-team-landing/app-team-landing.scss

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,16 +96,17 @@ section.team-landing {
9696
}
9797

9898
.hero {
99+
background-position: center;
100+
background-repeat: no-repeat;
101+
background-size: cover;
102+
margin-bottom: 5rem;
103+
99104
@include media-breakpoint-down(md) {
100105
margin-bottom: 4rem;
101106
}
102107
@include media-breakpoint-down(sm) {
103108
margin-bottom: 1rem;
104109
}
105-
background-position: center;
106-
background-repeat: no-repeat;
107-
background-size: cover;
108-
margin-bottom: 5rem;
109110

110111
.header-text {
111112
@include media-breakpoint-down(md) {

src/pages/app-team-landing/app-team-landing.tsx

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import { translate } from '../../services/translation.service';
88
})
99
export class AppTeamLanding {
1010
// private allowWebp = localStorage.getItem('allowWebp') === 'true' ? true : false;
11-
11+
backgroundPhoto: string;
12+
headshotPhoto: string;
1213
@Prop() match: MatchResults;
1314
@Prop() history: RouterHistory;
1415

@@ -402,6 +403,10 @@ export class AppTeamLanding {
402403
this.changeMetadata();
403404
}
404405

406+
componentDidUnload() {
407+
window.removeEventListener('resize', this.updateBackground, false);
408+
}
409+
405410
changeMetadata() {
406411
if (this.data[this.match.params.member]) {
407412
// Change meta tags dynamically
@@ -421,32 +426,39 @@ export class AppTeamLanding {
421426
return img;
422427
}
423428

429+
updateBackground() {
430+
console.error('this is the background photo - ', this.backgroundPhoto);
431+
const hero = document.querySelector('.team-landing > .container-fluid > .hero') as HTMLElement;
432+
if (window.innerWidth > 767.98) {
433+
hero.style.backgroundColor = '#292A2D';
434+
if (this.backgroundPhoto != null) {
435+
console.error('THIS IS THE RESIZE');
436+
hero.style.backgroundImage = `linear-gradient(90deg, #000000 20%, rgba(255, 255, 255, 0) 70%), url(${this.backgroundPhoto})`;
437+
}
438+
} else {
439+
hero.style.backgroundImage = 'none';
440+
hero.style.backgroundColor = 'transparent';
441+
}
442+
}
443+
424444
render() {
425-
const backgroundPhoto = this.changeImageFormat(this.data[this.match.params.member].backgroundPhoto ? this.data[this.match.params.member].backgroundPhoto : null);
426-
const headshotPhoto = this.changeImageFormat(this.data[this.match.params.member].headshotPhoto);
445+
console.error('render - ', this.data[this.match.params.member].backgroundPhoto);
446+
console.error('again - ', this.data[this.match.params.member].headshotPhoto);
447+
448+
this.backgroundPhoto = this.changeImageFormat(this.data[this.match.params.member].backgroundPhoto ? this.data[this.match.params.member].backgroundPhoto : null);
449+
this.headshotPhoto = this.changeImageFormat(this.data[this.match.params.member].headshotPhoto);
427450
let style = {};
428451
if (window.innerWidth > 767.98) {
429-
style = backgroundPhoto
452+
style = this.backgroundPhoto
430453
? {
431-
'background-image': `linear-gradient(90deg, #000000 20%, rgba(255, 255, 255, 0) 70%), url(${backgroundPhoto})`,
454+
'background-image': `linear-gradient(90deg, #000000 20%, rgba(255, 255, 255, 0) 70%), url(${this.backgroundPhoto})`,
432455
}
433456
: {
434457
'background-color': '#292A2D',
435458
};
436459
}
437-
window.addEventListener('resize', () => {
438-
const backgroundPhoto = this.changeImageFormat(this.data[this.match.params.member].backgroundPhoto ? this.data[this.match.params.member].backgroundPhoto : null);
439-
const hero = document.querySelector('.team-landing > .container-fluid > .hero') as HTMLElement;
440-
if (window.innerWidth > 767.98) {
441-
hero.style.backgroundColor = '#292A2D';
442-
if (backgroundPhoto) {
443-
hero.style.backgroundImage = `linear-gradient(90deg, #000000 20%, rgba(255, 255, 255, 0) 70%), url(${backgroundPhoto})`;
444-
}
445-
} else {
446-
hero.style.backgroundImage = 'none';
447-
hero.style.backgroundColor = 'transparent';
448-
}
449-
});
460+
461+
window.addEventListener('resize', this.updateBackground);
450462

451463
return (
452464
<section class="team-landing">
@@ -456,7 +468,7 @@ export class AppTeamLanding {
456468
<div class="container-fluid">
457469
<div class="row justify-content-center align-items-center hero" style={style}>
458470
<div class="col-10 col-sm-12 d-block d-md-none">
459-
<app-img class="headshot-mobile" src={headshotPhoto} />
471+
<app-img class="headshot-mobile" src={this.headshotPhoto} />
460472
</div>
461473
<div class="col-11 col-sm-9 col-md-7 col-lg-6 align-self-start">
462474
<div class="header-text">
@@ -470,7 +482,7 @@ export class AppTeamLanding {
470482
<p>{this.data[this.match.params.member].headerText}</p>
471483
</div>
472484
</div>
473-
<div class="col-md-4 d-none d-md-block">{!backgroundPhoto && <app-img class="headshot" src={headshotPhoto} />}</div>
485+
<div class="col-md-4 d-none d-md-block">{!this.backgroundPhoto && <app-img class="headshot" src={this.headshotPhoto} />}</div>
474486
</div>
475487

476488
<div class="row align-items-center justify-content-center bio">

0 commit comments

Comments
 (0)