|
|
@@ -1,6 +1,8 @@
|
|
|
import { Component } from '@angular/core';
|
|
|
import { Track } from 'src/app/tracks/track';
|
|
|
import { TracksApiService } from 'src/app/tracks-api.service';
|
|
|
+import { TrackSearchParams } from 'src/app/tracks/track-search-params';
|
|
|
+import { Subject } from 'rxjs';
|
|
|
|
|
|
@Component({
|
|
|
selector: 'app-tracks-page',
|
|
|
@@ -8,11 +10,41 @@ import { TracksApiService } from 'src/app/tracks-api.service';
|
|
|
styleUrls: ['./tracks-page.component.scss']
|
|
|
})
|
|
|
export class TracksPageComponent {
|
|
|
- public tracks: Promise<Track[]>;
|
|
|
+ private _tracks: Track[] = [];
|
|
|
+ public tracks: Subject<Track[]> = new Subject<Track[]>();
|
|
|
+
|
|
|
+ public showMyTracks: boolean = false;
|
|
|
+ public nameFilter: string = '';
|
|
|
+
|
|
|
+ private searchParams: TrackSearchParams = new TrackSearchParams();
|
|
|
|
|
|
public constructor(
|
|
|
private readonly tracksApi: TracksApiService
|
|
|
) {
|
|
|
- this.tracks = this.tracksApi.getTracks();
|
|
|
+ this.updateTracks();
|
|
|
+ }
|
|
|
+
|
|
|
+ public search(event: SubmitEvent): void {
|
|
|
+ this.searchParams = new TrackSearchParams();
|
|
|
+ this.searchParams.owner = this.showMyTracks ? 'me' : undefined;
|
|
|
+ this.searchParams.filter = this.nameFilter ? this.nameFilter : undefined;
|
|
|
+ this.updateTracks()
|
|
|
+ }
|
|
|
+
|
|
|
+ public loadMore(): void {
|
|
|
+ this.searchParams.page++;
|
|
|
+ this.updateTracks();
|
|
|
+ }
|
|
|
+
|
|
|
+ private updateTracks(): void {
|
|
|
+ this.tracksApi.getTracks(this.searchParams)
|
|
|
+ .then(trackPage => {
|
|
|
+ if (this.searchParams.page === 0) {
|
|
|
+ this._tracks = trackPage;
|
|
|
+ } else {
|
|
|
+ this._tracks.push(...trackPage);
|
|
|
+ }
|
|
|
+ this.tracks.next(this._tracks)
|
|
|
+ });
|
|
|
}
|
|
|
}
|