Skip to content

Commit 38c720d

Browse files
perf(champions): limit data use for small devices
1 parent 775b79d commit 38c720d

File tree

5 files changed

+28
-10
lines changed

5 files changed

+28
-10
lines changed

src/client/champion/champion.component.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@ import {Component, Input} from '@angular/core';
66
<a id="{{champion?.id}}" [routerLink]="[champion?.key]">
77
<img [attr.alt]="champion?.name"
88
class="nodrag"
9-
[attr.src]="'champion/loading/' + champion?.key + '_0.jpg' | lbDDragon">
9+
[attr.src]="'champion/' + champion?.image?.full | lbDDragon"
10+
[attr.srcset]="
11+
('champion/' + champion?.image?.full | lbDDragon:false) + ' 1350w, ' +
12+
('champion/loading/' + champion?.key + '_0.jpg' | lbDDragon:false) + ' 2000w'"
13+
[style.height]="imageHeight"
14+
(load)="loaded($event)">
1015
<div class="info">
1116
<p class="nodrag noselect">{{champion?.name}}</p>
1217
<lb-bar title="Attack Damage" class="attack" [value]="champion?.info.attack"></lb-bar>
@@ -18,5 +23,18 @@ import {Component, Input} from '@angular/core';
1823
})
1924

2025
export class ChampionComponent {
21-
@Input() champion: {key: ''};
26+
@Input() champion: any;
27+
imageHeight: string = '';
28+
29+
loaded(event: Event) {
30+
let img: any = event.target;
31+
if (!img.currentSrc) {
32+
return;
33+
}
34+
if (img.currentSrc.indexOf('champion/loading') > 0) {
35+
this.imageHeight = '';
36+
} else {
37+
this.imageHeight = '100px';
38+
}
39+
}
2240
}

src/client/champion/champion.css

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ lb-champions p {
1313
}
1414

1515
lb-champions lb-champion {
16-
height: 275px;
1716
margin: -1px -2px;
1817
}
1918

@@ -139,7 +138,6 @@ lb-filters .right label {
139138

140139
@media (max-width: 1350px) {
141140
lb-champions lb-champion {
142-
height: 181px;
143141
margin: initial;
144142
padding: 5px;
145143
width: 100px;

src/client/services/lolapi.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export class LolApiService {
3838
}
3939

4040
public getChampions(): Observable<any> {
41-
return this.get(Endpoint.static, 'static-data', '/champion?champData=info,tags');
41+
return this.get(Endpoint.static, 'static-data', '/champion?champData=info,tags,image');
4242
}
4343

4444
public getChampion(championKey: string): Observable<any> {

src/client/shared/ddragon.pipe.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ describe('DDragonPipe', () => {
4848
inject([DDragonPipe], (pipe) => {
4949
let result = pipe.buildImage('test.png', undefined);
5050
expect(result).toBeDefined();
51-
result = pipe.buildImage('test.png', undefined);
51+
result = pipe.buildImage(undefined, realm);
5252
expect(result).toBeDefined();
5353
}));
5454

src/client/shared/ddragon.pipe.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@ export class DDragonPipe implements PipeTransform {
1111
resolvedImage: SafeUrl = '';
1212
image: string = '';
1313

14-
constructor(private lolApi: LolApiService, sanitizer: DomSanitizer) {
15-
this.resolvedImage = sanitizer.bypassSecurityTrustUrl(defaultImage);
16-
}
1714

18-
transform(image: string): any {
15+
constructor(private lolApi: LolApiService, private sanitizer: DomSanitizer) {}
16+
17+
transform(image: string, addDefault: boolean = true): any {
18+
if (!this.resolvedImage && addDefault) {
19+
this.resolvedImage = this.sanitizer.bypassSecurityTrustUrl(defaultImage);
20+
}
1921
if (this.image === image) {
2022
return this.resolvedImage;
2123
}

0 commit comments

Comments
 (0)