Skip to content

Commit d8a3ce4

Browse files
committed
1.7 - Updating feed videos
1 parent 85d6fea commit d8a3ce4

File tree

7 files changed

+108
-25
lines changed

7 files changed

+108
-25
lines changed

src/app/components/youtube-search.component.html

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,19 @@
2828
</div>
2929
</form>
3030
<div *ngIf="feedVideos" id="feed-video-list" class="video-list" [ngClass]="{'grid-list': !listGrid }">
31+
<div *ngIf="trendingFirst.video.id" class="video-list-featured">
32+
<p>{{ trendingFirst.bannerURL }}</p>
33+
<p>{{ trendingFirst.video.title }}</p>
34+
<p>{{ trendingFirst.video.img }}</p>
35+
<p>{{ trendingFirst.stats.subscribers | number:'1.0' }}</p>
36+
<p>{{ trendingFirst.stats.views | number:'1.0' }}</p>
37+
<p>{{ trendingFirst.stats.videoCount | number:'1.0' }}</p>
38+
<div class="video-item-details">
39+
<p class="stats-views"><span class="fa fa-eye"></span> {{ trendingFirst.video.stats.views | number:'1.0' }}</p>
40+
<p class="stats-likes"><span class="fa fa-thumbs-up"></span> {{ trendingFirst.video.stats.likes | number:'1.0' }}</p>
41+
<p class="stats-dislikes"><span class="fa fa-thumbs-down"></span> {{ trendingFirst.video.stats.dislikes| number:'1.0' }}</p>
42+
</div>
43+
</div>
3144
<div *ngFor="let feedVideo of feedVideos; let i = index" [attr.data-index]="i" class="video-item" (click)="onClickVideo($event, i, 3)">
3245
<div *ngIf="thumbnails" class="video-item-image">
3346
<img src="{{ feedVideo.snippet.thumbnails.medium.url }}" alt="feed video thumbnail" />

src/app/components/youtube-search.component.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,30 @@ export class SearchComponent implements OnInit {
1717

1818
videos: any;
1919
feedVideos: any;
20+
channel: any;
2021

2122
_shared: any;
2223
_app: any;
2324

25+
trendingFirst = {
26+
bannerURL: '',
27+
video: {
28+
id: '',
29+
title: '',
30+
img: '',
31+
stats: {
32+
views: '',
33+
likes: '',
34+
dislikes: ''
35+
}
36+
},
37+
stats: {
38+
subscribers: '',
39+
views: '',
40+
videoCount: ''
41+
}
42+
}
43+
2444
private listGrid = true;
2545

2646
constructor(
@@ -69,6 +89,30 @@ export class SearchComponent implements OnInit {
6989
getFeedVideos() {
7090
this._shared.getFeed().subscribe(data => {
7191
this.feedVideos = data;
92+
this.getChannelTrending(this.feedVideos[0].snippet.channelId);
93+
});
94+
}
95+
96+
getChannelTrending(query: any) {
97+
this._shared.getChannel(query).subscribe(data => {
98+
this.feedVideos = this._shared.feedVideos;
99+
this.channel = this._shared.channel;
100+
this.trendingFirst.video.id = this.feedVideos[0].id;
101+
this.trendingFirst.video.title = this.feedVideos[0].snippet.title;
102+
this.trendingFirst.video.img = this.feedVideos[0].snippet.thumbnails.medium.url;
103+
this.trendingFirst.video.stats.likes = this.feedVideos[0].statistics.likeCount;
104+
this.trendingFirst.video.stats.dislikes = this.feedVideos[0].statistics.dislikeCount;
105+
this.trendingFirst.video.stats.views = this.feedVideos[0].statistics.viewCount;
106+
107+
this.trendingFirst.bannerURL = this.channel.items[0].brandingSettings.image.bannerTabletHdImageUrl;
108+
if (!this.channel.items[0].statistics.hiddenSubscriberCount) {
109+
this.trendingFirst.stats.subscribers = this.channel.items[0].statistics.subscriberCount;
110+
} else {
111+
this.trendingFirst.stats.subscribers = '0';
112+
}
113+
this.trendingFirst.stats.videoCount = this.channel.items[0].statistics.videoCount;
114+
this.trendingFirst.stats.views = this.channel.items[0].statistics.viewCount;
115+
this.feedVideos.shift();
72116
});
73117
}
74118

src/app/config/shared.module.ts

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import 'rxjs/add/operator/map';
88
export class SharedService {
99

1010
public feedVideos: Array<Object>;
11-
settings: Array<Object>;
11+
public settings: Array<Object>;
12+
public channel: Array<Object>;
1213

1314
notify = {
1415
enabled: false,
@@ -34,6 +35,11 @@ export class SharedService {
3435
this.youtube.feedVideos().subscribe(
3536
result => {
3637
this.feedVideos = result.items;
38+
this.youtube.getChannel(result.items[0].snippet.channelId).subscribe(
39+
result => {
40+
this.channel = result;
41+
console.log(result);
42+
});
3743
observer.next(this.feedVideos);
3844
observer.complete();
3945
},
@@ -45,6 +51,26 @@ export class SharedService {
4551
});
4652
}
4753

54+
getChannel(query: any): Observable<any> {
55+
return new Observable(observer => {
56+
if (this.channel) {
57+
observer.next(this.channel);
58+
return observer.complete();
59+
} else {
60+
this.youtube.getChannel(query).subscribe(
61+
result => {
62+
this.channel = result;
63+
observer.next(this.channel);
64+
observer.complete();
65+
},
66+
error => {
67+
console.log('error on get channel ' + error);
68+
}
69+
);
70+
}
71+
});
72+
}
73+
4874
getSettings(): Observable<any> {
4975
return new Observable(observer => {
5076
if (this.settings) {

src/app/config/youtube.config.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export class YoutubeGetVideo {
1212
private numSearchRes: string;
1313
private numRelatedRes: string;
1414
private videoDetails = 'part=snippet,contentDetails,statistics,status';
15+
private channelDetails = 'part=brandingSettings,snippet,contentDetails,statistics'
1516
private feedDetails = '&chart=mostPopular';
1617
private settings: Array<any>;
1718

@@ -27,6 +28,13 @@ export class YoutubeGetVideo {
2728
this.numRelatedRes = this.settings[3].value;
2829
}
2930

31+
getChannel(query: string) {
32+
if (this.apiKey) {
33+
return this.http.get(this.url + 'channels?'+ this.channelDetails +'&id=' + query + '&key=' + this.apiKey)
34+
.map(response => response.json());
35+
}
36+
}
37+
3038
searchVideo(query: string) {
3139
if (this.apiKey) {
3240
return this.http.get(this.url + 'search?part=snippet&q=' + query + '&maxResults=' + this.numSearchRes + '&type=video&key=' + this.apiKey)

src/assets/css/main.css

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -772,41 +772,36 @@ nav ul {
772772
}
773773

774774
nav li {
775-
padding-left: 15px;
775+
padding-left: 0;
776776
}
777777

778778
nav a {
779779
display: block;
780780
text-decoration: none;
781781
color: #ffffff;
782782
font-size: 14px;
783-
text-transform: uppercase;
784-
padding: 5px 15px;
785-
margin: 10px 0;
783+
padding: 10px 15px;
786784
transition: all 0.1s ease-out;
787785
border-left: 3px solid transparent;
788786
}
789787

790788
nav a .fa {
791789
margin-right: 10px;
792-
}
793-
794-
nav a:hover {
795790
color: #e52d27;
796791
}
797792

798-
nav a:active {
793+
nav a:hover {
799794
border-left-color: #e52d27;
800-
color: #ffffff;
801795
}
802796

803-
nav a.is-active {
797+
nav a.is-active, nav a:active {
798+
background: #e52d27;
804799
border-left-color: #e52d27;
805800
color: #ffffff;
806801
}
807802

808-
nav a.is-active:hover {
809-
color: #e52d27;
803+
nav a.is-active .fa, nav a:active .fa {
804+
color: #ffffff;
810805
}
811806

812807
#main-search {

src/assets/scss/_navbar.scss

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,33 +21,30 @@ nav {
2121
margin: 0;
2222
}
2323
li {
24-
padding-left: 15px;
24+
padding-left: 0;
2525
}
2626
a {
2727
display: block;
2828
text-decoration: none;
2929
color: $c-white;
3030
font-size: 14px;
31-
text-transform: uppercase;
32-
padding: 5px 15px;
33-
margin: 10px 0;
31+
padding: 10px 15px;
3432
transition: all 0.1s ease-out;
3533
border-left: 3px solid transparent;
3634
.fa {
3735
margin-right: 10px;
38-
}
39-
&:hover {
4036
color: $c-primary;
4137
}
42-
&:active {
38+
&:hover {
4339
border-left-color: $c-primary;
44-
color: $c-white;
4540
}
46-
&.is-active {
41+
&.is-active,
42+
&:active {
43+
background: $c-primary;
4744
border-left-color: $c-primary;
4845
color: $c-white;
49-
&:hover {
50-
color: $c-primary;
46+
.fa {
47+
color: $c-white;
5148
}
5249
}
5350
}

src/assets/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"value": "AIzaSyDcMvWlqPTHg7rHm-CTVXJwpaVGXKu7cBc"
1515
}, {
1616
"name": "Country trending",
17-
"value": "US"
17+
"value": "RO"
1818
}, {
1919
"name": "Number of search results",
2020
"value": 15

0 commit comments

Comments
 (0)