Skip to content

Commit e40e37c

Browse files
committed
1.3 - Adding functionality for change country for trending videos and implementing list and grid functionality
2 parents 0b2f88f + d76d0d5 commit e40e37c

15 files changed

+175
-61
lines changed

src/app/app.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<div class="app-head">
1414
<div id="logo">
1515
<img src="assets/img/logo.svg" height="35"/>
16-
<small *ngIf="nregionCode">{{ regionCode }}</small>
16+
<small *ngIf="regionCode">{{ regionCode }}</small>
1717
</div>
1818
</div>
1919
<div class="app-content">

src/app/app.component.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,12 @@ export class AppComponent implements OnInit {
8989
}
9090

9191
getFeedVideos() {
92-
this._shared.getFeed().subscribe(data => {
93-
this.feedVideos = data;
94-
this.setDefaultPlayer();
95-
});
92+
this._shared.getFeed().subscribe(data => {
93+
this.feedVideos = data;
94+
if (typeof this.currentVideoID === 'undefined') {
95+
this.setDefaultPlayer();
96+
}
97+
});
9698
}
9799

98100
getRelatedVideos() {
@@ -107,12 +109,10 @@ export class AppComponent implements OnInit {
107109
}
108110

109111
setDefaultPlayer() {
110-
if (this.currentState < 0) {
111-
this.feedVideos = this._shared.feedVideos;
112-
this.currentVideoID = this.feedVideos[0].id;
113-
this.currentVideoName = this.feedVideos[0].snippet.title;
114-
this.getRelatedVideos();
115-
}
112+
this.feedVideos = this._shared.feedVideos;
113+
this.currentVideoID = this.feedVideos[0].id;
114+
this.currentVideoName = this.feedVideos[0].snippet.title;
115+
this.getRelatedVideos();
116116
}
117117

118118
setSettings(data: any, from: number) {
@@ -189,6 +189,7 @@ export class AppComponent implements OnInit {
189189
this.videoCurRange = this.player.getCurrentTime();
190190
this.videoCurFull = this.timeFormat(this.videoCurRange);
191191
this._ref.markForCheck();
192+
console.log('test');
192193
}, 1000);
193194
}
194195

src/app/app.module.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { NgModule } from '@angular/core';
22
import { BrowserModule } from '@angular/platform-browser';
33
import { HttpModule } from '@angular/http';
44
import { ReactiveFormsModule } from '@angular/forms';
5-
import { routes } from './app.routes';
5+
import { routes } from './app.router';
66

77
import { AppComponent } from './app.component';
88
import { SharedService } from './config/shared.module';
File renamed without changes.

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
<div class="settings">
1313
<span>List mode:</span>
1414
<div id="toggle-list-mode">
15-
<p class="fa fa-list"></p>
16-
<p class="fa fa-th"></p>
15+
<p class="fa fa-list" [ngClass]="{'active': listGrid }" (click)="toggleList(0)"></p>
16+
<p class="fa fa-th" [ngClass]="{'active': !listGrid }" (click)="toggleList(1)"></p>
1717
</div>
1818
</div>
1919
<div *ngIf="searchForm.valid" id="search-video-list" class="video-list">
@@ -27,7 +27,7 @@
2727
</div>
2828
</div>
2929
</form>
30-
<div *ngIf="feedVideos" id="feed-video-list" class="video-list">
30+
<div *ngIf="feedVideos" id="feed-video-list" class="video-list" [ngClass]="{'grid-list': !listGrid }">
3131
<div *ngFor="let feedVideo of feedVideos; let i = index" [attr.data-index]="i" class="video-item" (click)="onClickVideo($event, i, 3)">
3232
<div class="video-item-image">
3333
<img src="{{ feedVideo.snippet.thumbnails.default.url }}" alt="feed video thumbnail" />

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import 'rxjs/add/operator/map';
1313
export class SearchComponent implements OnInit {
1414

1515
searchForm: FormGroup;
16-
1716
searchVideoImage = false;
1817

1918
videos: any;
@@ -22,6 +21,8 @@ export class SearchComponent implements OnInit {
2221
_shared: any;
2322
_app: any;
2423

24+
private listGrid = true;
25+
2526
constructor(
2627
private youtube: YoutubeGetVideo,
2728
private shared: SharedService,
@@ -99,4 +100,12 @@ export class SearchComponent implements OnInit {
99100
}
100101
}
101102

103+
toggleList(int: number) {
104+
if (int === 1) {
105+
this.listGrid = false;
106+
} else {
107+
this.listGrid = true;
108+
}
109+
}
110+
102111
}

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@
88
<label [attr.for]="'setting-' + i">{{ settings[i].name }}<span class="round-check"></span></label>
99
</div>
1010
<div class="form-group form-select">
11-
<label for="val-search-results">Trending sort by country</label>
12-
<select class="form-field" [value]="regionCode" [formControl]="RegionSettings" (change)="changeRegion($event.target.value)">
11+
<label for="val-search-results">Set trending country</label>
12+
<span *ngIf="loadingRegion" class="loading-region fa fa-circle-o-notch fa-spin fa-fw"></span>
13+
<select class="form-field" [value]="regionCode" (change)="changeRegion($event.target.value)" [disabled]="loadingRegion">
1314
<option value="US">United States</option>
1415
<option value="GB">United Kingdom</option>
1516
<option value="RO">Romania</option>
@@ -31,7 +32,10 @@
3132
<span class="fa fa-exclamation-circle fa-color-danger"></span>
3233
</div>
3334
<div class="alert alert-danger" role="alert">
34-
<span class="fa fa-exclamation-circle"></span>All marked fields you can change in next version (<a href="https://github.com/quead/angular2-yt-player#changelog" target="_blank">check changelog</a>). Now you can only change it from "assets/settings.json".
35+
<span class="fa fa-exclamation-circle"></span>All marked fields you can change in upcoming verions (<a href="https://github.com/quead/angular2-yt-player#changelog" target="_blank">check changelog</a>). Now you can only change it from "assets/settings.json".
36+
</div>
37+
<div class="alert alert-info" role="alert">
38+
<span class="fa fa-info-circle"></span>The settings will be saved in upcoming versions (<a href="https://github.com/quead/angular2-yt-player#changelog" target="_blank">check changelog</a>). You can set default settings from "assets/settings.json".
3539
</div>
3640
</form>
3741
</div>

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Component, OnInit } from '@angular/core';
2-
import { FormControl, FormArray, FormGroup, FormBuilder, ReactiveFormsModule } from '@angular/forms';
2+
import { FormControl, FormArray, FormGroup, FormBuilder, ReactiveFormsModule, Validators } from '@angular/forms';
33
import { AppComponent } from '../app.component';
44
import { SearchComponent } from './youtube-search.component';
55
import { SharedService } from '../config/shared.module';
@@ -28,6 +28,7 @@ export class SettingsComponent implements OnInit {
2828
private regionCode: string;
2929
private numSearchRes: string;
3030
private numRelatedRes: string;
31+
private loadingRegion = false;
3132

3233
constructor(
3334
private fb: FormBuilder,
@@ -49,8 +50,7 @@ export class SettingsComponent implements OnInit {
4950

5051
setForm() {
5152
this.settingsForm = this._fb.group({
52-
settings: this.mapSettings(),
53-
RegionSettings: this.regionCode
53+
settings: this.mapSettings()
5454
});
5555
this.checkInputs();
5656
}
@@ -89,8 +89,12 @@ export class SettingsComponent implements OnInit {
8989
}
9090

9191
changeRegion(data: any) {
92+
this.loadingRegion = true;
9293
this._shared.settings.api_settings[1].value = data;
9394
this._shared.setApiSettings();
94-
console.log(this.shared.settings);
95+
this._shared.feedVideos = null;
96+
this._app.getSettings();
97+
this._app.getFeedVideos();
98+
setTimeout(() => this.loadingRegion = false, 3000);
9599
}
96100
}

src/app/config/shared.module.ts

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import 'rxjs/add/operator/map';
77
@Injectable()
88
export class SharedService {
99

10-
feedVideos: Array<Object>;
10+
public feedVideos: Array<Object>;
1111
settings: Array<Object>;
1212

1313
constructor(
@@ -22,23 +22,21 @@ export class SharedService {
2222
if (this.feedVideos) {
2323
observer.next(this.feedVideos);
2424
return observer.complete();
25-
} else {
26-
this.getSettings().subscribe(data => {
27-
this.setApiSettings();
28-
this.settings = data;
29-
this.youtube.feedVideos().subscribe(
30-
result => {
31-
console.log('fac feed de');
32-
this.feedVideos = result.items;
33-
observer.next(this.feedVideos);
34-
observer.complete();
35-
},
36-
error => {
37-
console.log('error on feed videos' + error);
38-
}
39-
);
40-
});
41-
}
25+
}
26+
this.getSettings().subscribe(data => {
27+
this.setApiSettings();
28+
this.settings = data;
29+
this.youtube.feedVideos().subscribe(
30+
result => {
31+
this.feedVideos = result.items;
32+
observer.next(this.feedVideos);
33+
observer.complete();
34+
},
35+
error => {
36+
console.log('error on feed videos' + error);
37+
}
38+
);
39+
});
4240
});
4341
}
4442

@@ -52,7 +50,6 @@ export class SharedService {
5250
.map(res => res.json())
5351
.subscribe(
5452
data => {
55-
console.log('fac settings de')
5653
this.settings = data;
5754
observer.next(this.settings);
5855
observer.complete();

src/app/config/youtube.config.ts

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export class YoutubeGetVideo {
88

99
private apiKey: string;
1010
private url = 'https://www.googleapis.com/youtube/v3/';
11-
private regionCode: string;
11+
public regionCode: string;
1212
private numSearchRes: string;
1313
private numRelatedRes: string;
1414
private videoDetails = 'part=snippet,contentDetails,statistics,status';
@@ -28,23 +28,20 @@ export class YoutubeGetVideo {
2828
}
2929

3030
searchVideo(query: string) {
31-
if (this.apiKey) {
32-
return this.http.get(this.url + 'search?part=snippet&q=' + query + '&maxResults=' + this.numSearchRes + '&type=video&key=' + this.apiKey)
33-
.map(response => response.json());
34-
}
31+
return this.http.get(this.url + 'search?part=snippet&q=' + query + '&maxResults=' + this.numSearchRes + '&type=video&key=' + this.apiKey)
32+
.map(response => response.json());
33+
3534
}
3635

3736
relatedVideos(query: string) {
38-
if (this.apiKey) {
39-
return this.http.get(this.url + 'search?part=snippet&relatedToVideoId=' + query + '&maxResults='+ this.numRelatedRes +'&type=video&key=' + this.apiKey)
40-
.map(response => response.json());
41-
}
37+
return this.http.get(this.url + 'search?part=snippet&relatedToVideoId=' + query + '&maxResults='+ this.numRelatedRes +'&type=video&key=' + this.apiKey)
38+
.map(response => response.json());
39+
4240
}
4341

4442
feedVideos() {
45-
if (this.apiKey) {
46-
return this.http.get(this.url + 'videos?' + this.videoDetails + this.feedDetails + '&regionCode=' + this.regionCode + '&maxResults=25&key=' + this.apiKey)
47-
.map(response => response.json());
48-
}
43+
return this.http.get(this.url + 'videos?' + this.videoDetails + this.feedDetails + '&regionCode=' + this.regionCode + '&maxResults=25&key=' + this.apiKey)
44+
.map(response => response.json());
45+
4946
}
5047
}

0 commit comments

Comments
 (0)