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

Commit ec2949b

Browse files
Sam HSam H
authored andcommitted
fix: fix merge conflicts with develop
2 parents 79ee55e + b01c132 commit ec2949b

File tree

13 files changed

+485
-302
lines changed

13 files changed

+485
-302
lines changed

CHANGELOG.md

Lines changed: 196 additions & 125 deletions
Large diffs are not rendered by default.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@openforge/main-website",
33
"private": true,
4-
"version": "2.0.3",
4+
"version": "2.0.4",
55
"description": "The official website for OpenForge",
66
"files": [
77
"dist/"

sass-lint.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@ rules:
4646
- 2
4747
-
4848
style: lowercase
49-
indentation:
50-
- 2
5149
-
5250
size: 2
5351
single-line-per-selector: 1

src/components.d.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ import '@stencil/router';
1010
import '@stencil/state-tunnel';
1111

1212

13+
import {
14+
EventEmitter,
15+
} from '@stencil/core';
1316
import {
1417
MatchResults,
1518
RouterHistory,
@@ -50,6 +53,12 @@ declare global {
5053
'src': string;
5154
}
5255

56+
interface LazyImg {
57+
'alt': string;
58+
'src': string;
59+
'width': number;
60+
}
61+
5362
interface AppInput {
5463
'id': string;
5564
'label': string;
@@ -193,6 +202,14 @@ declare global {
193202
};
194203

195204

205+
interface HTMLLazyImgElement extends StencilComponents.LazyImg, HTMLStencilElement {}
206+
207+
var HTMLLazyImgElement: {
208+
prototype: HTMLLazyImgElement;
209+
new (): HTMLLazyImgElement;
210+
};
211+
212+
196213
interface HTMLAppInputElement extends StencilComponents.AppInput, HTMLStencilElement {}
197214

198215
var HTMLAppInputElement: {
@@ -368,6 +385,7 @@ declare global {
368385
'app-cta': JSXElements.AppCtaAttributes;
369386
'app-footer': JSXElements.AppFooterAttributes;
370387
'app-img': JSXElements.AppImgAttributes;
388+
'lazy-img': JSXElements.LazyImgAttributes;
371389
'app-input': JSXElements.AppInputAttributes;
372390
'app-members': JSXElements.AppMembersAttributes;
373391
'app-nav-header': JSXElements.AppNavHeaderAttributes;
@@ -413,6 +431,13 @@ declare global {
413431
'src'?: string;
414432
}
415433

434+
export interface LazyImgAttributes extends HTMLAttributes {
435+
'alt'?: string;
436+
'onLazyImgloaded'?: (event: CustomEvent<HTMLImageElement>) => void;
437+
'src'?: string;
438+
'width'?: number;
439+
}
440+
416441
export interface AppInputAttributes extends HTMLAttributes {
417442
'id'?: string;
418443
'label'?: string;
@@ -532,6 +557,7 @@ declare global {
532557
'app-cta': HTMLAppCtaElement
533558
'app-footer': HTMLAppFooterElement
534559
'app-img': HTMLAppImgElement
560+
'lazy-img': HTMLLazyImgElement
535561
'app-input': HTMLAppInputElement
536562
'app-members': HTMLAppMembersElement
537563
'app-nav-header': HTMLAppNavHeaderElement
@@ -560,6 +586,7 @@ declare global {
560586
'app-cta': HTMLAppCtaElement;
561587
'app-footer': HTMLAppFooterElement;
562588
'app-img': HTMLAppImgElement;
589+
'lazy-img': HTMLLazyImgElement;
563590
'app-input': HTMLAppInputElement;
564591
'app-members': HTMLAppMembersElement;
565592
'app-nav-header': HTMLAppNavHeaderElement;

src/components/app-img/app-img.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,6 @@ export class Img {
6868

6969
render() {
7070
this.changeImageFormat();
71-
return <img class={{ fit: this.fit }} src={this.loadSrc} alt={this.alt} decoding="async" />;
71+
return <lazy-img class={{ fit: this.fit }} src={this.loadSrc} alt={this.alt} />;
7272
}
7373
}
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
import { Component, Element, Event, EventEmitter, Prop, State } from '@stencil/core';
2+
3+
/*
4+
You can use this component to lazy load below the fold images to improve load time.
5+
Below the fold images are images that are not seen by the user until they have started to scroll.
6+
Instead of loading all these images up front before the user even sees them, which will eat up
7+
network bandwith, we can use this component to put off loading these images until the user has
8+
scrolled to where that image is in your PWA.
9+
To use this component use the following markup: <lazy-img src={/path/to/img} alt={alt text for img}></lazy-img>
10+
*/
11+
12+
@Component({
13+
tag: 'lazy-img',
14+
// styleUrl: 'lazy-img.scss'
15+
})
16+
export class LazyImg {
17+
@Element() el: HTMLElement;
18+
19+
@Prop() src: string;
20+
@Prop() alt: string;
21+
@Prop() width: number;
22+
23+
@State() oldSrc: string;
24+
25+
@Event() lazyImgloaded: EventEmitter<HTMLImageElement>;
26+
27+
image: HTMLImageElement;
28+
io: IntersectionObserver | null;
29+
30+
componentDidLoad() {
31+
this.addIntersectionObserver();
32+
}
33+
34+
componentDidUnload() {
35+
this.removeIntersectionObserver();
36+
}
37+
38+
componentWillUpdate() {
39+
if (this.src !== this.oldSrc) {
40+
this.addIntersectionObserver();
41+
}
42+
this.oldSrc = this.src;
43+
}
44+
45+
handleImage() {
46+
console.log('a');
47+
const image = this.image;
48+
image.setAttribute('src', this.src || '');
49+
image.onload = () => {
50+
image.removeAttribute('data-src');
51+
this.lazyImgloaded.emit(image);
52+
};
53+
}
54+
55+
addIntersectionObserver() {
56+
if (!this.src) {
57+
return;
58+
}
59+
if ('IntersectionObserver' in window) {
60+
this.io = new IntersectionObserver(data => {
61+
// because there will only ever be one instance
62+
// of the element we are observing
63+
// we can just use data[0]
64+
if (data[0].isIntersecting) {
65+
this.handleImage();
66+
this.removeIntersectionObserver();
67+
}
68+
});
69+
this.io.observe(this.image);
70+
} else {
71+
// fall back to just loading the image for Safari and IE
72+
this.handleImage();
73+
}
74+
}
75+
76+
removeIntersectionObserver() {
77+
if (this.io) {
78+
this.io.disconnect();
79+
this.io = null;
80+
}
81+
}
82+
83+
render() {
84+
return <img ref={el => (this.image = el as HTMLImageElement)} data-src={this.src} alt={this.alt} width={this.width} />;
85+
}
86+
}

src/components/content-graphic/content-graphic.scss

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@
66
text-align: center;
77
}
88

9-
img {
10-
max-height: 400px;
11-
@include media-breakpoint-down(sm) {
12-
padding: 15px 30px 30px;
13-
max-height: 200px;
9+
app-img {
10+
img {
11+
max-height: 400px;
12+
@include media-breakpoint-down(sm) {
13+
padding: 15px 30px 30px;
14+
max-height: 200px;
15+
}
1416
}
1517
}
1618

src/pages/app-404/app-404.scss

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@
1212
text-align: center;
1313
}
1414

15-
img {
16-
height: auto;
17-
margin: 7rem 0 2rem;
18-
width: 35%;
15+
app-img {
16+
img {
17+
height: auto;
18+
margin: 7rem 0 2rem;
19+
width: 35%;
20+
}
1921
}
2022
}
2123
}

src/pages/app-404/app-404.tsx

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,12 @@ export class App404 {
99
return (
1010
<div class="no-page">
1111
<section class="container">
12-
<img src="/assets/forge.png" />
12+
<app-img src="/assets/forge.png" />
1313

14-
<p>
15-
{' '}
16-
Utoh, we've detected that this page does not exist, or something
17-
else has gone wrong!{' '}
18-
</p>
14+
<p> Utoh, we've detected that this page does not exist, or something else has gone wrong! </p>
1915

2016
<p>
21-
It must be something to do with our awesomeness, the coolness of our
22-
apps, or some other equally awesome thing. Don't worry, we'll fix it
23-
soon but in the mean time feel free to email us at{' '}
17+
It must be something to do with our awesomeness, the coolness of our apps, or some other equally awesome thing. Don't worry, we'll fix it soon but in the mean time feel free to email us at{' '}
2418
<a href="mailto:hello@openforge.io">hello@openforge.io</a>!
2519
</p>
2620

0 commit comments

Comments
 (0)