Skip to content

Commit 72bdd21

Browse files
Ismaestroiramos
authored andcommitted
feat(hero loading): add as a component
1 parent 7488897 commit 72bdd21

File tree

8 files changed

+80
-23
lines changed

8 files changed

+80
-23
lines changed

src/app/modules/heroes/pages/hero-detail-page/hero-detail-page.component.html

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
<h1 class="header__title">{{'heroDetail' | translate}}</h1>
2-
<mat-progress-spinner *ngIf="!hero"
3-
class="progress__spinner"
4-
[color]="'primary'"
5-
[mode]="'indeterminate'">
6-
</mat-progress-spinner>
7-
<div id="heroe-detail" *ngIf="hero" [@fadeInOut]>
2+
<div class="container" *ngIf="!hero">
3+
<app-hero-loading></app-hero-loading>
4+
</div>
5+
<div class="container" *ngIf="hero" [@fadeInOut]>
86
<ng-container>
97
<app-hero-card [hero]="hero"></app-hero-card>
108
<div id="hero-json">

src/app/modules/heroes/pages/hero-detail-page/hero-detail-page.component.scss

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
@import "mixins";
22

3-
#heroe-detail {
3+
.container {
44
width: 65%;
55
@include push--auto();
66
margin-top: 2rem;
@@ -12,7 +12,7 @@ button {
1212
}
1313

1414
@media (max-width: 600px) {
15-
#heroe-detail {
15+
.container {
1616
width: 90%;
1717
}
18-
}
18+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<mat-card id="loading-card" class="hero-card">
2+
<mat-card-header>
3+
<div mat-card-avatar class="hero-header__image"></div>
4+
<mat-card-title>.</mat-card-title>
5+
<mat-card-subtitle>.</mat-card-subtitle>
6+
<div class="flex-spacer"></div>
7+
<div class="hero-actions">
8+
<mat-icon class="icon__like--grey">favorite</mat-icon>
9+
</div>
10+
</mat-card-header>
11+
<mat-progress-bar [color]="'warn'" [mode]="'indeterminate'"></mat-progress-bar>
12+
<app-spinner></app-spinner>
13+
<img mat-card-image src="assets/images/loading-hero.jpg">
14+
</mat-card>

src/app/shared/components/hero-loading/hero-loading.component.scss

Whitespace-only changes.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import {async, ComponentFixture, TestBed} from '@angular/core/testing';
2+
import {HeroLoadingComponent} from './hero-loading.component';
3+
import {TestsModule} from '../../modules/tests.module';
4+
import {CUSTOM_ELEMENTS_SCHEMA} from '@angular/core';
5+
import {APP_BASE_HREF} from '@angular/common';
6+
import {TranslateModule} from '@ngx-translate/core';
7+
import {APP_CONFIG, AppConfig} from '../../../configs/app.config';
8+
9+
describe('HeroLoadingComponent', () => {
10+
let component: HeroLoadingComponent;
11+
let fixture: ComponentFixture<HeroLoadingComponent>;
12+
13+
beforeEach(async(() => {
14+
TestBed.configureTestingModule({
15+
imports: [
16+
TestsModule,
17+
TranslateModule.forRoot()
18+
],
19+
declarations: [
20+
HeroLoadingComponent
21+
],
22+
providers: [
23+
{provide: APP_CONFIG, useValue: AppConfig},
24+
{provide: APP_BASE_HREF, useValue: '/'},
25+
],
26+
schemas: [CUSTOM_ELEMENTS_SCHEMA]
27+
}).compileComponents();
28+
}));
29+
30+
beforeEach(() => {
31+
fixture = TestBed.createComponent(HeroLoadingComponent);
32+
component = fixture.componentInstance;
33+
fixture.detectChanges();
34+
});
35+
36+
it('should create', () => {
37+
expect(component).toBeTruthy();
38+
});
39+
});
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import {Component, OnInit} from '@angular/core';
2+
3+
@Component({
4+
selector: 'app-hero-loading',
5+
templateUrl: './hero-loading.component.html',
6+
styleUrls: ['./hero-loading.component.scss']
7+
})
8+
export class HeroLoadingComponent implements OnInit {
9+
10+
constructor() {
11+
}
12+
13+
ngOnInit() {
14+
}
15+
16+
}

src/app/shared/pages/home-page/home-page.component.html

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,7 @@
22
<div fxFlex="10" fxFlex.gt-sm="20"></div>
33
<div fxFlex="90" fxFlex.gt-sm="80">
44
<h1 class="header__title">{{'topHeroes' | translate}}</h1>
5-
<mat-card id="loading-card" class="hero-card" *ngIf="!heroes">
6-
<mat-card-header>
7-
<div mat-card-avatar class="hero-header__image"></div>
8-
<mat-card-title>.</mat-card-title>
9-
<mat-card-subtitle>.</mat-card-subtitle>
10-
<div class="flex-spacer"></div>
11-
<div class="hero-actions">
12-
<mat-icon class="icon__like--grey">favorite</mat-icon>
13-
</div>
14-
</mat-card-header>
15-
<mat-progress-bar [color]="'warn'" [mode]="'indeterminate'"></mat-progress-bar>
16-
<app-spinner></app-spinner>
17-
<img mat-card-image src="assets/images/loading-hero.jpg">
18-
</mat-card>
5+
<app-hero-loading *ngIf="!heroes"></app-hero-loading>
196
<div id="heroes-list" *ngIf="heroes" [@fadeInOut]>
207
<ng-container *ngFor="let hero of heroes">
218
<app-hero-card [hero]="hero"></app-hero-card>

src/app/shared/shared.module.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {HeroCardComponent} from './components/hero-card/hero-card.component';
1515
import {ScrollToFirstInvalidDirective} from './directives/scroll-to-first-invalid.directive';
1616
import {NgxExampleLibraryModule} from '@ismaestro/ngx-example-library';
1717
import {WebStorageModule} from 'ngx-store';
18+
import { HeroLoadingComponent } from './components/hero-loading/hero-loading.component';
1819

1920
@NgModule({
2021
imports: [
@@ -35,6 +36,7 @@ import {WebStorageModule} from 'ngx-store';
3536
FooterComponent,
3637
SpinnerComponent,
3738
HeroCardComponent,
39+
HeroLoadingComponent,
3840
ScrollToFirstInvalidDirective
3941
],
4042
exports: [
@@ -49,6 +51,7 @@ import {WebStorageModule} from 'ngx-store';
4951
FooterComponent,
5052
SpinnerComponent,
5153
HeroCardComponent,
54+
HeroLoadingComponent,
5255
ScrollToFirstInvalidDirective
5356
]
5457
})

0 commit comments

Comments
 (0)