Skip to content

Commit

Permalink
feat(hero top): added hero detail links
Browse files Browse the repository at this point in the history
  • Loading branch information
Ismaestro authored and Ismael Ramos committed Apr 16, 2018
1 parent 8ee8e2e commit b565f1d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
8 changes: 4 additions & 4 deletions src/app/heroes/hero-top/hero-top.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ <h1 class="section-title">{{'topHeroes' | translate}}</h1>
<ng-container *ngFor="let hero of heroes">
<mat-card class="hero-card">
<mat-card-header>
<div mat-card-avatar class="hero-header-image"
<div (click)="seeHeroDetails(hero)" mat-card-avatar class="hero-header-image"
[ngStyle]="{'background-image': 'url(assets/images/heroes/' + hero.id + '-thumbnail.jpg)'}"></div>
<mat-card-title>{{hero.name}}</mat-card-title>
<mat-card-subtitle>{{hero.alterEgo}}</mat-card-subtitle>
<mat-card-title (click)="seeHeroDetails(hero)">{{hero.name}}</mat-card-title>
<mat-card-subtitle (click)="seeHeroDetails(hero)">{{hero.alterEgo}}</mat-card-subtitle>
<div class="flex-spacer"></div>
<div class="hero-actions">
{{hero.likes}}
Expand All @@ -24,7 +24,7 @@ <h1 class="section-title">{{'topHeroes' | translate}}</h1>
</mat-icon>
</div>
</mat-card-header>
<img mat-card-image src="assets/images/heroes/{{hero.id}}.jpg">
<img (click)="seeHeroDetails(hero)" mat-card-image src="assets/images/heroes/{{hero.id}}.jpg">
</mat-card>
</ng-container>
</div>
Expand Down
4 changes: 4 additions & 0 deletions src/app/heroes/hero-top/hero-top.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
margin: 2em;
}

.hero-header-image, mat-card-title, mat-card-subtitle, .mat-card-image {
cursor: pointer;
}

.hero-card {
margin: 2em auto;
}
Expand Down
12 changes: 9 additions & 3 deletions src/app/heroes/hero-top/hero-top.component.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import {Component} from '@angular/core';

import {Hero} from '../shared/hero.model';

import {HeroService} from '../shared/hero.service';
import {AppConfig} from '../../config/app.config';
import {Router} from '@angular/router';

@Component({
selector: 'app-hero-top',
Expand All @@ -15,7 +14,8 @@ export class HeroTopComponent {
heroes: Hero[] = null;
canVote = false;

constructor(private heroService: HeroService) {
constructor(private heroService: HeroService,
private router: Router) {
this.canVote = this.heroService.checkIfUserCanVote();

this.heroService.getAllHeroes().subscribe((heroes) => {
Expand All @@ -35,4 +35,10 @@ export class HeroTopComponent {
});
});
}

seeHeroDetails(hero): void {
if (hero.default) {
this.router.navigate([AppConfig.routes.heroes + '/' + hero.id]);
}
}
}

0 comments on commit b565f1d

Please sign in to comment.