From 91a0cdfd5701be3e95758146e91151ed901b6449 Mon Sep 17 00:00:00 2001 From: stickyPiston Date: Sat, 28 Sep 2019 17:35:25 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=B8=20Added=20SongList=20component=20f?= =?UTF-8?q?or=20consistent=20song=20visuals=20everywhere.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/app-routing.module.ts | 4 +- src/app/app.module.ts | 6 +-- src/app/classes/entities.ts | 5 +- .../components/artists/artists.component.html | 26 ++++------- .../components/artists/artists.component.ts | 11 +++-- .../controls/controls.component.html | 5 +- .../controls/controls.component.scss | 12 ++++- .../components/controls/controls.component.ts | 2 +- src/app/components/home/home.component.html | 4 +- src/app/components/home/home.component.ts | 9 +--- src/app/components/song/song.component.html | 1 - src/app/components/song/song.component.ts | 15 ------ .../songlist/songlist.component.html | 23 ++++++++++ .../songlist.component.scss} | 0 .../songlist.component.spec.ts} | 12 ++--- .../components/songlist/songlist.component.ts | 46 +++++++++++++++++++ src/app/services/audio.service.ts | 2 +- 17 files changed, 117 insertions(+), 66 deletions(-) delete mode 100644 src/app/components/song/song.component.html delete mode 100644 src/app/components/song/song.component.ts create mode 100644 src/app/components/songlist/songlist.component.html rename src/app/components/{song/song.component.scss => songlist/songlist.component.scss} (100%) rename src/app/components/{song/song.component.spec.ts => songlist/songlist.component.spec.ts} (55%) create mode 100644 src/app/components/songlist/songlist.component.ts diff --git a/src/app/app-routing.module.ts b/src/app/app-routing.module.ts index fc74bd7..d65b5cd 100644 --- a/src/app/app-routing.module.ts +++ b/src/app/app-routing.module.ts @@ -3,15 +3,13 @@ import { Routes, RouterModule } from '@angular/router'; import { HomeComponent } from './components/home/home.component'; import { ArtistsComponent } from './components/artists/artists.component'; import { AlbumsComponent } from './components/albums/albums.component'; -import { SongComponent } from './components/song/song.component'; const routes: Routes = [ { path: '', component: HomeComponent }, { path: 'artists/:id', component: ArtistsComponent }, { path: 'artists', component: ArtistsComponent }, { path: 'albums/:id', component: AlbumsComponent }, - { path: 'albums', component: AlbumsComponent }, - { path: 'songs', component: SongComponent } + { path: 'albums', component: AlbumsComponent } ]; @NgModule({ diff --git a/src/app/app.module.ts b/src/app/app.module.ts index ca610cc..9473d50 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -8,19 +8,19 @@ import { FormsModule } from '@angular/forms'; import { AppRoutingModule } from './app-routing.module'; import { AppComponent } from './app.component'; import { HomeComponent } from './components/home/home.component'; -import { SongComponent } from './components/song/song.component'; import { ArtistsComponent } from './components/artists/artists.component'; import { AlbumsComponent } from './components/albums/albums.component'; import { ControlsComponent } from './components/controls/controls.component'; +import { SonglistComponent } from './components/songlist/songlist.component'; @NgModule({ declarations: [ AppComponent, HomeComponent, - SongComponent, ArtistsComponent, AlbumsComponent, - ControlsComponent + ControlsComponent, + SonglistComponent ], imports: [ BrowserModule, diff --git a/src/app/classes/entities.ts b/src/app/classes/entities.ts index 72d019a..e8723a0 100644 --- a/src/app/classes/entities.ts +++ b/src/app/classes/entities.ts @@ -32,8 +32,9 @@ export class Song { return new Album(await this.data.getAlbum(this.album)); } - async getDuration() { - return await this.data.getDuration(this.path); + async getDuration(): Promise { + const apiData = await this.data.getDuration(this.path); + return apiData.data.result; } } diff --git a/src/app/components/artists/artists.component.html b/src/app/components/artists/artists.component.html index f550799..1990e0a 100644 --- a/src/app/components/artists/artists.component.html +++ b/src/app/components/artists/artists.component.html @@ -10,26 +10,16 @@ -
+

{{ artistData.name }}'s profile

-

{{ data.name }}'s profile

+
-

{{ data.name }}'s albums

-
    -
  • - {{ album }} -
  • -
+

{{ artistData.name }}'s songs

-

{{ data.name }}'s songs

-
    -
  • - {{ song }} -
  • -
- - {{ data | json}} - -
+
    +
  • + {{ song.name }} +
  • +
diff --git a/src/app/components/artists/artists.component.ts b/src/app/components/artists/artists.component.ts index 513c49b..0ac572e 100644 --- a/src/app/components/artists/artists.component.ts +++ b/src/app/components/artists/artists.component.ts @@ -1,6 +1,7 @@ import { Component, OnInit } from '@angular/core'; import { ActivatedRoute } from '@angular/router'; import { ApiService } from 'src/app/services/api.service'; +import { Artist, Song } from '../../classes/entities'; @Component({ selector: 'app-artists', @@ -9,8 +10,9 @@ import { ApiService } from 'src/app/services/api.service'; }) export class ArtistsComponent implements OnInit { - artistData; - artists; + artistData: Artist; + artists: Promise>; + songs: Array; constructor( private api: ApiService, @@ -25,7 +27,10 @@ export class ArtistsComponent implements OnInit { if (params.has('id')) { // ... then get artist data ... - this.artistData = this.api.getArtist(Number(params.get('id'))); + this.api.getArtist(Number(params.get('id'))).then(async res => { + this.artistData = res; + this.songs = await this.api.getSong(res.songs.join()); + }); } else { diff --git a/src/app/components/controls/controls.component.html b/src/app/components/controls/controls.component.html index f50daf1..ada79c5 100644 --- a/src/app/components/controls/controls.component.html +++ b/src/app/components/controls/controls.component.html @@ -17,8 +17,9 @@ {{ duration > 0 ? audio.formatTime(duration) : '00:00' }} - +
+ - +
diff --git a/src/app/components/controls/controls.component.scss b/src/app/components/controls/controls.component.scss index 6f874bc..3b4e4ea 100644 --- a/src/app/components/controls/controls.component.scss +++ b/src/app/components/controls/controls.component.scss @@ -3,7 +3,7 @@ padding: 18px; line-height: 1.5em; display: grid; - grid-template-columns: 25% 10% 55% 10% + grid-template-columns: 25% 5% 55% 15% } .form-control-range { display: inline-block; @@ -18,6 +18,16 @@ div.time { } } +div.volume { + display: grid; + grid-template-columns: auto auto; + text-align: center; + + input { + width: 90%; + } +} + figure { margin: 0; diff --git a/src/app/components/controls/controls.component.ts b/src/app/components/controls/controls.component.ts index b7497a5..97bafc6 100644 --- a/src/app/components/controls/controls.component.ts +++ b/src/app/components/controls/controls.component.ts @@ -39,7 +39,7 @@ export class ControlsComponent implements OnInit { this.currentSong = await this.api.getSong(id); this.currentArtist = await this.currentSong.getArtist(); this.currentAlbum = await this.currentSong.getAlbum(); - this.duration = (await this.currentSong.getDuration()).data.result; + this.duration = await this.currentSong.getDuration(); }); } diff --git a/src/app/components/home/home.component.html b/src/app/components/home/home.component.html index 3f0b9dc..761e40b 100644 --- a/src/app/components/home/home.component.html +++ b/src/app/components/home/home.component.html @@ -1,3 +1 @@ -
-

{{ song.name }} by {{ artists[i].name }}

-
+ diff --git a/src/app/components/home/home.component.ts b/src/app/components/home/home.component.ts index 3dafe4e..7d436ae 100644 --- a/src/app/components/home/home.component.ts +++ b/src/app/components/home/home.component.ts @@ -10,7 +10,7 @@ import { ApiService } from 'src/app/services/api.service'; }) export class HomeComponent implements OnInit { - songs: Song[]; + songs: Promise; artists: Artist[] = []; constructor( @@ -21,12 +21,7 @@ export class HomeComponent implements OnInit { ngOnInit() { // Load the first song from the API // Removing the async / await from the .then() callback will load the artists async from the songs. - this.api.getSong('all').then(async res => { - this.songs = res; - await res.forEach(async (song: Song) => { - this.artists.push(await song.getArtist()); - }); - }); + this.songs = this.api.getSong('all'); } } diff --git a/src/app/components/song/song.component.html b/src/app/components/song/song.component.html deleted file mode 100644 index 7bc867c..0000000 --- a/src/app/components/song/song.component.html +++ /dev/null @@ -1 +0,0 @@ -

song works!

diff --git a/src/app/components/song/song.component.ts b/src/app/components/song/song.component.ts deleted file mode 100644 index fde26ff..0000000 --- a/src/app/components/song/song.component.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { Component, OnInit } from '@angular/core'; - -@Component({ - selector: 'app-song', - templateUrl: './song.component.html', - styleUrls: ['./song.component.scss'] -}) -export class SongComponent implements OnInit { - - constructor() { } - - ngOnInit() { - } - -} diff --git a/src/app/components/songlist/songlist.component.html b/src/app/components/songlist/songlist.component.html new file mode 100644 index 0000000..09ce74b --- /dev/null +++ b/src/app/components/songlist/songlist.component.html @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + + + + +
#Song nameArtist nameAlbum nameDuration
{{ i + 1 }}{{ song.name }}{{ song.artistInfo.name }}{{ song.albumInfo.name }}{{ audio.formatTime(song.duration) }}
diff --git a/src/app/components/song/song.component.scss b/src/app/components/songlist/songlist.component.scss similarity index 100% rename from src/app/components/song/song.component.scss rename to src/app/components/songlist/songlist.component.scss diff --git a/src/app/components/song/song.component.spec.ts b/src/app/components/songlist/songlist.component.spec.ts similarity index 55% rename from src/app/components/song/song.component.spec.ts rename to src/app/components/songlist/songlist.component.spec.ts index 81b1c32..12a070f 100644 --- a/src/app/components/song/song.component.spec.ts +++ b/src/app/components/songlist/songlist.component.spec.ts @@ -1,20 +1,20 @@ import { async, ComponentFixture, TestBed } from '@angular/core/testing'; -import { SongComponent } from './song.component'; +import { SonglistComponent } from './songlist.component'; -describe('SongComponent', () => { - let component: SongComponent; - let fixture: ComponentFixture; +describe('SonglistComponent', () => { + let component: SonglistComponent; + let fixture: ComponentFixture; beforeEach(async(() => { TestBed.configureTestingModule({ - declarations: [ SongComponent ] + declarations: [ SonglistComponent ] }) .compileComponents(); })); beforeEach(() => { - fixture = TestBed.createComponent(SongComponent); + fixture = TestBed.createComponent(SonglistComponent); component = fixture.componentInstance; fixture.detectChanges(); }); diff --git a/src/app/components/songlist/songlist.component.ts b/src/app/components/songlist/songlist.component.ts new file mode 100644 index 0000000..451aaf0 --- /dev/null +++ b/src/app/components/songlist/songlist.component.ts @@ -0,0 +1,46 @@ +import { Component, OnInit, Input } from '@angular/core'; +import { Song, Artist, Album } from '../../classes/entities'; +import { faPlay } from '@fortawesome/free-solid-svg-icons'; +import { AudioService } from 'src/app/services/audio.service'; + +@Component({ + selector: 'app-songlist', + templateUrl: './songlist.component.html', + styleUrls: ['./songlist.component.scss'] +}) +export class SonglistComponent implements OnInit { + @Input() songs: Song[]; + + songsInfo = []; + + // ? fontAwesome imports + faPlay = faPlay; + + constructor(public audio: AudioService) { } + + ngOnInit() { + this.songs.forEach(song => { + const index = this.songsInfo.push({}) - 1; + const result = { + ...song, + artistInfo: null as Artist, + albumInfo: null as Album, + duration: null as number + }; + song.getArtist().then((artist: Artist) => { + result.artistInfo = artist; + + song.getAlbum().then((album: Album) => { + result.albumInfo = album; + + song.getDuration().then((duration: number) => { + result.duration = duration; + + this.songsInfo[index] = result; + }); + }); + }); + }); + } + +} diff --git a/src/app/services/audio.service.ts b/src/app/services/audio.service.ts index dc3e3be..8230500 100644 --- a/src/app/services/audio.service.ts +++ b/src/app/services/audio.service.ts @@ -78,7 +78,7 @@ export class AudioService { /** * The setSong function set the song for the player. - * @param id The id of the song that needs to be played + * @param song The song object */ setSong(song: Song) { this.player.src = this.data.apiUrl + '/play/' + song.path;