|
|
|
@ -1,4 +1,4 @@
|
|
|
|
|
import { Component, Input, ViewEncapsulation, OnInit } from "@angular/core";
|
|
|
|
|
import { Component, Input, ViewEncapsulation, OnInit, OnChanges, SimpleChanges } from "@angular/core";
|
|
|
|
|
import { IReleaseGroups } from "../../../../../interfaces/IMusicSearchResultV2";
|
|
|
|
|
import { SearchV2Service } from "../../../../../services/searchV2.service";
|
|
|
|
|
import { ActivatedRoute } from "@angular/router";
|
|
|
|
@ -9,19 +9,16 @@ import { ActivatedRoute } from "@angular/router";
|
|
|
|
|
selector: "artist-release-panel",
|
|
|
|
|
encapsulation: ViewEncapsulation.None
|
|
|
|
|
})
|
|
|
|
|
export class ArtistReleasePanel implements OnInit {
|
|
|
|
|
|
|
|
|
|
export class ArtistReleasePanel implements OnChanges {
|
|
|
|
|
@Input() public releases: IReleaseGroups[];
|
|
|
|
|
|
|
|
|
|
public albums: IReleaseGroups[];
|
|
|
|
|
|
|
|
|
|
constructor(private searchService: SearchV2Service, private route: ActivatedRoute) {
|
|
|
|
|
route.params.subscribe(() => {
|
|
|
|
|
// This is due to when we change the music Id, NgOnInit is not called again
|
|
|
|
|
// Since the component has not been destroyed (We are not navigating away)
|
|
|
|
|
// so we need to subscribe to custom changes so we can do the data manulipulation below
|
|
|
|
|
constructor(private searchService: SearchV2Service) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ngOnChanges(changes: SimpleChanges): void {
|
|
|
|
|
this.loadAlbums();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ngOnInit() {
|
|
|
|
@ -29,10 +26,19 @@ export class ArtistReleasePanel implements OnInit {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private loadAlbums(): void {
|
|
|
|
|
if (this.releases) {
|
|
|
|
|
this.albums = this.releases.filter(x => x.type === "Album");
|
|
|
|
|
this.albums = this.albums.sort((a: IReleaseGroups, b: IReleaseGroups) => {
|
|
|
|
|
return this.getTime(new Date(b.releaseDate)) - this.getTime(new Date(a.releaseDate));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
this.albums.forEach(a => {
|
|
|
|
|
this.searchService.getReleaseGroupArt(a.id).subscribe(x => a.image = x.image);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private getTime(date?: Date) {
|
|
|
|
|
return date != null ? date.getTime() : 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|