Skip to content

Commit 8567675

Browse files
committed
Changes
1 parent 8f129f6 commit 8567675

File tree

7 files changed

+69
-12
lines changed

7 files changed

+69
-12
lines changed

projects/mugan86-youtube-api/src/lib/assets/styles/styles.css

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,21 @@ h1 {
4141
padding: 10px;
4242
border-radius: 8px;
4343
}
44+
45+
/** VIDEOS **/
46+
47+
.videos {
48+
max-width: 85%;
49+
margin: 0 auto;
50+
}
51+
52+
53+
.col-md-4 {
54+
max-width: 32%;
55+
margin-right: 1.33%;
56+
}
57+
58+
.card {
59+
padding: 5px;
60+
margin-bottom: 10px;
61+
}

projects/mugan86-youtube-api/src/lib/components/channel/channel.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<div class="row channel">
1+
<div class="row channel" *ngIf="channel">
22
<div class="col-md-2">
33
<img [src]="channel?.thumbnails.high.url" class="img-circle" />
44
</div>
Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1-
<p>
2-
playlist-items works!
3-
</p>
1+
<div class="row videos" *ngIf="videos">
2+
<ng-template ngFor [ngForOf]="videos" let-video let-i="index">
3+
<div class="card col-md-4">
4+
<img [src]="video.snippet.thumbnails.high.url" class="card-img-top" alt="...">
5+
<div class="card-body">
6+
<h5 class="card-title">{{ video?.snippet.title }}</h5>
7+
<p class="card-text">{{ video?.snippet.description }}</p>
8+
<p class="card-text"><small class="text-muted">{{ video?.snippet.publishedAt | dateHour}}</small></p>
9+
</div>
10+
</div>
11+
</ng-template>
12+
</div>
13+
<button (click)="loadMore()">Cargar más videos</button>
Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,42 @@
1-
import { Component, OnInit } from '@angular/core';
1+
import { ApiService } from './../../services/api.service';
2+
import { Component, OnInit, Input } from '@angular/core';
3+
import { Item } from '../../interfaces/api/playlis-items.interface';
24

35
@Component({
46
selector: 'mugan86-yt-api-playlist-items',
57
templateUrl: './playlist-items.component.html',
68
styles: []
79
})
810
export class PlaylistItemsComponent implements OnInit {
9-
10-
constructor() { }
11+
@Input() playlistId: string;
12+
videos: Item[];
13+
noMoreVideos = false;
14+
constructor(private api: ApiService) { }
1115

1216
ngOnInit() {
17+
if (this.playlistId === undefined || this.playlistId === null || this.playlistId === '') {
18+
this.playlistId = 'UUTh7-deUJBNv2tHRiMGcXxg';
19+
}
20+
this.loadData();
21+
}
22+
23+
loadData(loadMore: boolean = false) {
24+
25+
if ( this.api.pageToken === 'OK') {
26+
this.noMoreVideos = true;
27+
console.log('No hay más videos en este playlist');
28+
}
29+
// Cargar los datos
30+
this.api.getItemsByPlaylist(this.playlistId, loadMore).subscribe(
31+
(items: Item[]) => {
32+
this.videos = items;
33+
console.log(this.videos);
34+
}
35+
);
36+
}
37+
38+
loadMore() {
39+
this.loadData(true);
1340
}
1441

1542
}

projects/mugan86-youtube-api/src/lib/mugan86-youtube-api.module.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { throwError } from 'rxjs';
1313
import { DateHourPipe } from './pipes/date-hour.pipe';
1414
import { PlaylistItemsComponent } from './components/playlist-items/playlist-items.component';
1515
import { UserLastPlaylistComponent } from './components/user-last-playlist/user-last-playlist.component';
16+
import { CommonModule } from '@angular/common';
1617

1718
const COMPONENTS = [
1819
Mugan86YoutubeApiComponent,
@@ -28,7 +29,8 @@ const PIPES = [YoutubePipe, DomSecurePipe, DateHourPipe];
2829
declarations: [...COMPONENTS, ...PIPES],
2930
imports: [
3031
NgbModule,
31-
HttpClientModule
32+
HttpClientModule,
33+
CommonModule
3234
],
3335
exports: [...COMPONENTS, ...PIPES],
3436
entryComponents: [

projects/mugan86-youtube-api/src/lib/services/api.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export class ApiService {
5858
return this.http.get(this.getUrl(`playlistItems?${this.info}&playlistId=${ playlistId }${pageToken}`)).pipe(
5959
map(
6060
( res: PlaylistItems ) => {
61-
this.pageToken = res.nextPageToken;
61+
this.pageToken = (res.nextPageToken) ? res.nextPageToken : 'OK';
6262
this.playlistVideos = this.takeVideos(res.items);
6363
return this.playlistVideos;
6464
}

src/app/app.component.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<!--The content below is only a placeholder and can be replaced.-->
2-
<mugan86-yt-api></mugan86-yt-api>
32
<mugan86-yt-api-channel [channelId]="'UCTh7-deUJBNv2tHRiMGcXxg'"></mugan86-yt-api-channel>
43
<button (click)="show()">Mostrar</button>
5-
<div style="text-align:center">
4+
<mugan86-yt-api-playlist-items></mugan86-yt-api-playlist-items>
5+
<!--<div style="text-align:center">
66
<h1>
77
Welcome to {{ title }}!
88
</h1>
@@ -19,5 +19,5 @@ <h2><a target="_blank" rel="noopener" href="https://angular.io/cli">CLI Document
1919
<li>
2020
<h2><a target="_blank" rel="noopener" href="https://blog.angular.io/">Angular blog</a></h2>
2121
</li>
22-
</ul>
22+
</ul>-->
2323

0 commit comments

Comments
 (0)