add game components
This commit is contained in:
parent
b00e28e7d1
commit
157b49ed85
@ -0,0 +1,2 @@
|
||||
<h1>{{game.title}}</h1>
|
||||
<p>{{game.description}}</p>
|
@ -0,0 +1,3 @@
|
||||
:host {
|
||||
display: block;
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
|
||||
import { GameInfoComponent } from './game-info.component';
|
||||
|
||||
describe('GameInfoComponent', () => {
|
||||
let component: GameInfoComponent;
|
||||
let fixture: ComponentFixture<GameInfoComponent>;
|
||||
|
||||
beforeEach(async () => {
|
||||
await TestBed.configureTestingModule({
|
||||
declarations: [ GameInfoComponent ]
|
||||
})
|
||||
.compileComponents();
|
||||
|
||||
fixture = TestBed.createComponent(GameInfoComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
@ -0,0 +1,15 @@
|
||||
import { Component, Input, OnInit } from '@angular/core';
|
||||
import { Game } from 'src/app/interfaces/game.interface';
|
||||
|
||||
@Component({
|
||||
selector: 'app-game-info[game]',
|
||||
templateUrl: './game-info.component.html',
|
||||
styleUrls: ['./game-info.component.scss'],
|
||||
})
|
||||
export class GameInfoComponent implements OnInit {
|
||||
@Input() game!: Game;
|
||||
|
||||
constructor() {}
|
||||
|
||||
ngOnInit(): void {}
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
<div class="game" [ngClass]="{'active': active}">
|
||||
<div class="game-title">{{game.title}}</div>
|
||||
</div>
|
@ -0,0 +1,11 @@
|
||||
:host {
|
||||
display: block;
|
||||
|
||||
.game {
|
||||
|
||||
&.active {
|
||||
background-color: green;
|
||||
color: #fff;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
|
||||
import { GameItemComponent } from './game-item.component';
|
||||
|
||||
describe('GameItemComponent', () => {
|
||||
let component: GameItemComponent;
|
||||
let fixture: ComponentFixture<GameItemComponent>;
|
||||
|
||||
beforeEach(async () => {
|
||||
await TestBed.configureTestingModule({
|
||||
declarations: [ GameItemComponent ]
|
||||
})
|
||||
.compileComponents();
|
||||
|
||||
fixture = TestBed.createComponent(GameItemComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
@ -0,0 +1,16 @@
|
||||
import { Component, Input, OnInit } from '@angular/core';
|
||||
import { Game } from 'src/app/interfaces/game.interface';
|
||||
|
||||
@Component({
|
||||
selector: 'app-game-item[game]',
|
||||
templateUrl: './game-item.component.html',
|
||||
styleUrls: ['./game-item.component.scss'],
|
||||
})
|
||||
export class GameItemComponent implements OnInit {
|
||||
@Input() game!: Game;
|
||||
@Input() active: boolean = false;
|
||||
|
||||
constructor() {}
|
||||
|
||||
ngOnInit(): void {}
|
||||
}
|
4
src/app/components/games-bar/games-bar.component.html
Normal file
4
src/app/components/games-bar/games-bar.component.html
Normal file
@ -0,0 +1,4 @@
|
||||
<div class="games">
|
||||
<app-game-item [active]="i === activeGame" *ngFor="let game of games; index as i" [game]="game" (click)="activeGame = i"></app-game-item>
|
||||
</div>
|
||||
<app-game-info *ngIf="activeGame !== null" [game]="games[activeGame]"></app-game-info>
|
11
src/app/components/games-bar/games-bar.component.scss
Normal file
11
src/app/components/games-bar/games-bar.component.scss
Normal file
@ -0,0 +1,11 @@
|
||||
:host {
|
||||
display: flex;
|
||||
|
||||
.games {
|
||||
|
||||
}
|
||||
|
||||
.game-info {
|
||||
|
||||
}
|
||||
}
|
23
src/app/components/games-bar/games-bar.component.spec.ts
Normal file
23
src/app/components/games-bar/games-bar.component.spec.ts
Normal file
@ -0,0 +1,23 @@
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
|
||||
import { GamesBarComponent } from './games-bar.component';
|
||||
|
||||
describe('GamesBarComponent', () => {
|
||||
let component: GamesBarComponent;
|
||||
let fixture: ComponentFixture<GamesBarComponent>;
|
||||
|
||||
beforeEach(async () => {
|
||||
await TestBed.configureTestingModule({
|
||||
declarations: [ GamesBarComponent ]
|
||||
})
|
||||
.compileComponents();
|
||||
|
||||
fixture = TestBed.createComponent(GamesBarComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
26
src/app/components/games-bar/games-bar.component.ts
Normal file
26
src/app/components/games-bar/games-bar.component.ts
Normal file
@ -0,0 +1,26 @@
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { Game } from 'src/app/interfaces/game.interface';
|
||||
import { GetGames } from 'src/app/services/go';
|
||||
|
||||
@Component({
|
||||
selector: 'app-games-bar',
|
||||
templateUrl: './games-bar.component.html',
|
||||
styleUrls: ['./games-bar.component.scss'],
|
||||
})
|
||||
export class GamesBarComponent implements OnInit {
|
||||
games: Game[] = [];
|
||||
activeGame: Game['id'] | null = null;
|
||||
|
||||
constructor() {}
|
||||
|
||||
ngOnInit(): void {
|
||||
this.getGames();
|
||||
}
|
||||
|
||||
getGames() {
|
||||
GetGames().then((value) => {
|
||||
console.log(value);
|
||||
this.games = value;
|
||||
});
|
||||
}
|
||||
}
|
12
src/app/components/games-bar/games-bar.module.ts
Normal file
12
src/app/components/games-bar/games-bar.module.ts
Normal file
@ -0,0 +1,12 @@
|
||||
import { NgModule } from '@angular/core';
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { GamesBarComponent } from './games-bar.component';
|
||||
import { GameItemComponent } from './game-item/game-item.component';
|
||||
import { GameInfoComponent } from './game-info/game-info.component';
|
||||
|
||||
@NgModule({
|
||||
declarations: [GamesBarComponent, GameItemComponent, GameInfoComponent],
|
||||
imports: [CommonModule],
|
||||
exports: [GamesBarComponent, GameItemComponent, GameInfoComponent],
|
||||
})
|
||||
export class GamesBarModule {}
|
6
src/app/interfaces/game.interface.ts
Normal file
6
src/app/interfaces/game.interface.ts
Normal file
@ -0,0 +1,6 @@
|
||||
export interface Game {
|
||||
id: number;
|
||||
title: string;
|
||||
image: string;
|
||||
description: string;
|
||||
}
|
Loading…
Reference in New Issue
Block a user