Skip to content

Commit d41f03e

Browse files
committed
2.1 - Adding categories
1 parent f55f372 commit d41f03e

File tree

6 files changed

+119
-1
lines changed

6 files changed

+119
-1
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@
6767
<p>{{ trendingFirst.stats.views | number:'1.0' }}</p>
6868
<p>{{ trendingFirst.stats.videoCount | number:'1.0' }}</p>-->
6969
</div>
70+
<div class="categories">
71+
<div *ngFor="let category of categories.items" id="category-{{category.id}}">
72+
<p>{{category.snippet.title}}</p>
73+
</div>
74+
</div>
7075
<div id="feed-video-list" class="video-list" [ngClass]="{'grid-list': !listGrid }">
7176
<div *ngFor="let feedVideo of feedVideos; let i = index" [ngClass]="{'hidden-thumbnails': !thumbnails }" [attr.data-index]="i" class="video-item">
7277
<div class="video-item-info">

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export class SearchComponent implements OnInit {
2222
videos: Array<ISearchVideo>;
2323
feedVideos: Array<IFeedVideo>;
2424
channel: IChannelList;
25+
categories: any;
2526

2627
_shared: any;
2728
_app: any;
@@ -62,6 +63,21 @@ export class SearchComponent implements OnInit {
6263
this.setSettings();
6364
this.searchFunction();
6465
this.getFeedVideos();
66+
this.initCategories();
67+
}
68+
69+
initCategories() {
70+
this._shared.getCategories().subscribe(
71+
data => {
72+
this.categories = data;
73+
console.log(this.categories);
74+
}
75+
);
76+
this._shared.getVideoCategories(2).subscribe(
77+
result => {
78+
console.log(result);
79+
}
80+
);
6581
}
6682

6783
searchFunction() {

src/app/shared/lists.service.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ export class SharedService {
1212
public historyVideos: Array<any> = [];
1313
public settings: any;
1414
public channel: any;
15+
public categories: any;
16+
public videoCategories: any;
1517
public playlist: Array<any>;
1618

1719
_update: any;
@@ -73,6 +75,46 @@ export class SharedService {
7375
});
7476
}
7577

78+
getCategories(): Observable<any> {
79+
return new Observable(observer => {
80+
if (this.categories) {
81+
observer.next(this.categories);
82+
return observer.complete();
83+
} else {
84+
this.youtube.categories().subscribe(
85+
result => {
86+
this.categories = result;
87+
observer.next(this.categories);
88+
observer.complete();
89+
},
90+
error => {
91+
console.log(error);
92+
}
93+
);
94+
}
95+
});
96+
}
97+
98+
getVideoCategories(value: number): Observable<any> {
99+
return new Observable(observer => {
100+
if (this.videoCategories) {
101+
observer.next(this.videoCategories);
102+
return observer.complete();
103+
} else {
104+
this.youtube.videoCategories(value).subscribe(
105+
result => {
106+
this.videoCategories = result;
107+
observer.next(this.videoCategories);
108+
observer.complete();
109+
},
110+
error => {
111+
console.log(error);
112+
}
113+
);
114+
}
115+
});
116+
}
117+
76118
getSettings(): Observable<any> {
77119
return new Observable(observer => {
78120
if (this.settings) {

src/app/shared/youtube.service.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,4 +88,27 @@ export class YoutubeGetVideo {
8888
.map(response => response);
8989
}
9090
}
91+
92+
categories() {
93+
if (this.apiKey) {
94+
return this.http.get(
95+
this.url + 'videoCategories?part=snippet&regionCode='
96+
+ this.regionCode + '&key='
97+
+ this.apiKey
98+
)
99+
.map(response => response);
100+
}
101+
}
102+
103+
videoCategories(category: number) {
104+
if (this.apiKey) {
105+
return this.http.get(
106+
this.url + 'videos?part=snippet,contentDetails&chart=mostPopular&maxResults=25&videoCategoryId='
107+
+ category + '&regionCode='
108+
+ this.regionCode + '&key='
109+
+ this.apiKey
110+
)
111+
.map(response => response);
112+
}
113+
}
91114
}

src/assets/scss/_search.scss

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,35 @@
6767
margin-top: 20px;
6868
align-items: center;
6969
}
70+
}
71+
72+
.categories {
73+
display: flex;
74+
flex-wrap: nowrap;
75+
width: 100%;
76+
height: 69px;
77+
overflow-x: scroll;
78+
> div {
79+
width: 80px;
80+
flex: 0 0 80px;
81+
}
82+
p {
83+
margin: 0;
84+
}
85+
&::-webkit-scrollbar-track {
86+
border-radius: 2px;
87+
}
88+
89+
&::-webkit-scrollbar {
90+
height: 6px;
91+
background-color: transparent;
92+
}
93+
94+
&::-webkit-scrollbar-thumb {
95+
border-radius: 20px;
96+
background-color: rgba(#FFF, 0.1);
97+
&:hover {
98+
background-color: rgba(#FFF, 0.4);
99+
}
100+
}
70101
}

src/assets/scss/_videos.scss

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,7 @@ iframe {
322322
.video-list-featured {
323323
margin: 0;
324324
height: 200px;
325+
width: 100%;
325326
background-position: center center;
326327
background-size: cover;
327328
position: relative;
@@ -386,7 +387,7 @@ iframe {
386387
#feed-video-list {
387388
top: inherit;
388389
bottom: 0;
389-
height: calc(100% - 200px);
390+
height: calc(100% - 270px);
390391
width: calc(100% - 40px);
391392
max-height: none;
392393
background-color: var(--c-gray);

0 commit comments

Comments
 (0)