Skip to content

Commit f093399

Browse files
committed
2.3 - Refactoring remaining components
1 parent dd650c3 commit f093399

9 files changed

+63
-196
lines changed

src/app/components/category/category.component.ts

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,20 @@ export class CategoryComponent implements OnInit {
2121
private activatedRoute: ActivatedRoute,
2222
private router: Router
2323
) {
24+
// INIT SETTINGS
25+
this.shared.getSettings();
26+
this.shared.setSettings();
2427
}
2528

2629
ngOnInit() {
30+
2731
this.activatedRoute.paramMap.subscribe(data => {
2832
if (data['params'].id === 'all') {
2933
this.getFeedVideos();
3034
} else {
3135
this.globals.currentCategory = data['params'].id;
3236
}
33-
this.initCategories();
37+
this.getCategories();
3438
});
3539
}
3640

@@ -54,26 +58,11 @@ export class CategoryComponent implements OnInit {
5458
await this.shared.initChannel();
5559
}
5660

57-
async initCategories() {
58-
this.shared.setApiSettings();
59-
if (this.globals.settings) {
60-
this.getCategories();
61-
} else {
62-
await this.shared.initSettings().then(
63-
(done) => {
64-
this.getCategories();
65-
}
66-
);
67-
}
68-
}
69-
7061
async getFeedVideos() {
7162
if (!this.globals.feedVideos) {
7263
await this.shared.initFeed();
7364
}
74-
if (!this.globals.channel) {
75-
await this.shared.initChannel();
76-
}
65+
await this.shared.initChannel();
7766
this.loading = false;
7867
}
7968

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,29 +9,26 @@ import { GlobalsService } from '../services/globals.service';
99

1010
export class HistoryComponent implements OnInit {
1111

12-
_app: any;
13-
1412
constructor(
1513
private globals: GlobalsService,
1614
private app: AppComponent
1715
) {
18-
this._app = app;
1916
}
2017

2118
ngOnInit() {
2219
console.log('history');
2320
}
2421

2522
addPlaylistItem(i: number, list: number) {
26-
this._app.addPlaylistItem(i, list);
23+
this.app.addPlaylistItem(i, list);
2724
}
2825

2926
onCopyVideoItemLink(i: number, list: number) {
30-
this._app.onCopyVideoItemLink(i, list);
27+
this.app.onCopyVideoItemLink(i, list);
3128
}
3229

3330
onClickHistory(event: Event, i: number) {
34-
this._app.getVideo(this.globals.historyVideos[i]);
31+
this.app.getVideo(this.globals.historyVideos[i]);
3532
}
3633

3734
}

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

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,12 @@ export class SearchComponent implements OnInit {
1515
searchForm: FormGroup;
1616
noResults = false;
1717

18-
_app: any;
19-
2018
constructor(
2119
private youtube: YoutubeGetVideo,
2220
private globals: GlobalsService,
2321
private shared: SharedService,
2422
private app: AppComponent,
2523
) {
26-
this._app = app;
2724
}
2825

2926
ngOnInit() {
@@ -63,21 +60,21 @@ export class SearchComponent implements OnInit {
6360

6461
onClickVideo(event: Event, i: any, list: number) {
6562
if (list === 1) {
66-
this._app.getVideo(this.globals.searchedVideos[i]);
63+
this.app.getVideo(this.globals.searchedVideos[i]);
6764
this.clearSearch();
6865
} else if (list === 3) {
69-
this._app.getVideo(this.globals.feedVideos[i]);
66+
this.app.getVideo(this.globals.feedVideos[i]);
7067
}
7168
this.clearSearch();
7269
}
7370

7471
onCopyVideoItemLink(i: number, list: number) {
75-
this._app.onCopyVideoItemLink(i, list);
72+
this.app.onCopyVideoItemLink(i, list);
7673
this.clearSearch();
7774
}
7875

7976
addPlaylistItem(i: number, list: number) {
80-
this._app.addPlaylistItem(i, list);
77+
this.app.addPlaylistItem(i, list);
8178
this.clearSearch();
8279
}
8380
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<h2>Settings</h2>
33
</div>
44
<div class="app-content">
5-
<form *ngIf="finished" [formGroup]="internalSettings" id="internalSettings" class="settingsForm" novalidate>
5+
<form *ngIf="loading" [formGroup]="internalSettings" id="internalSettings" class="settingsForm" novalidate>
66
<h3>Internal Settings</h3>
77
<div *ngFor="let setting of initInternalForm.controls; let i=index" [ngClass]="{'hide': !globals.internal_settings[i].visible}" class="form-group">
88
<input type="checkbox" [attr.id]="'setting-' + i" [formControl]="setting"/>

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

Lines changed: 16 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { Component, OnInit } from '@angular/core';
22
import { FormControl, FormArray, FormGroup, FormBuilder, ReactiveFormsModule, Validators } from '@angular/forms';
33
import { AppComponent } from '../app.component';
4-
import { SearchComponent } from './youtube-search.component';
54
import { CategoryComponent } from './category/category.component';
65
import { SharedService } from '../services/shared.service';
76
import { GlobalsService } from '../services/globals.service';
@@ -11,18 +10,12 @@ import { HttpClient } from '@angular/common/http';
1110
@Component({
1211
selector: 'app-settings',
1312
templateUrl: 'youtube-settings.component.html',
14-
providers: [ SearchComponent, CategoryComponent, NumberVal ]
13+
providers: [ CategoryComponent, NumberVal ]
1514
})
1615

1716
export class SettingsComponent implements OnInit {
1817

19-
finished = false;
20-
21-
_shared: any;
22-
_fb: any;
23-
_app: any;
24-
_search: any;
25-
_category: any;
18+
loading = false;
2619

2720
internalSettings: FormGroup;
2821
externalSettings: FormGroup;
@@ -33,14 +26,8 @@ export class SettingsComponent implements OnInit {
3326
private shared: SharedService,
3427
private globals: GlobalsService,
3528
private app: AppComponent,
36-
private search: SearchComponent,
3729
private category: CategoryComponent,
3830
) {
39-
this._shared = shared;
40-
this._fb = fb;
41-
this._app = app;
42-
this._search = search;
43-
this._category = category;
4431
}
4532

4633
ngOnInit() {
@@ -49,7 +36,7 @@ export class SettingsComponent implements OnInit {
4936
}
5037

5138
setForm() {
52-
this.internalSettings = this._fb.group({
39+
this.internalSettings = this.fb.group({
5340
settings: this.mapSettings()
5441
});
5542
this.checkInputs();
@@ -82,49 +69,49 @@ export class SettingsComponent implements OnInit {
8269
this.globals.internal_settings[i].value = data.settings[i];
8370
});
8471
this.globals.settings.form_settings = this.globals.internal_settings;
85-
this._shared.updateSettings();
86-
this._shared.setSettings();
72+
this.shared.updateSettings();
73+
this.shared.setSettings();
8774

88-
this._app.checkVolumeRange();
75+
this.app.checkVolumeRange();
8976

90-
this._shared.triggerNotify('Changed');
77+
this.shared.triggerNotify('Changed');
9178
});
9279
}
9380

9481
mapSettings() {
9582
const arr = this.globals.internal_settings.map(s => {
96-
return this._fb.control(s.value);
83+
return this.fb.control(s.value);
9784
});
9885
return this.fb.array(arr);
9986
}
10087

10188
getDefaultSettings() {
102-
this._shared.setApiSettings();
89+
this.shared.getSettings();
10390
this.globals.internal_settings = this.globals.settings.form_settings;
10491
this.globals.external_settings = this.globals.settings.api_settings;
10592
this.initExternalForm();
106-
this.finished = true;
93+
this.loading = true;
10794
this.setForm();
10895
}
10996

11097
externalSave() {
11198
if (this.externalSettings.valid) {
112-
this._shared.triggerNotify('Saved');
99+
this.shared.triggerNotify('Saved');
113100
this.globals.external_settings[0].value = this.externalSettings.controls.fcApi.value;
114101
this.globals.external_settings[1].value = this.externalSettings.controls.fcRegion.value;
115102
this.globals.external_settings[2].value = parseInt(this.externalSettings.controls.fcSearchresults.value, 10);
116103
this.globals.external_settings[3].value = parseInt(this.externalSettings.controls.fcRelatedResults.value, 10);
117104
this.globals.settings.api_settings = this.globals.external_settings;
118105
this.globals.feedVideos = null;
119106

120-
this._shared.updateSettings();
121-
this._shared.setApiSettings();
122-
this._shared.setSettings();
107+
this.shared.updateSettings();
108+
this.shared.getSettings();
109+
this.shared.setSettings();
123110

124-
this._app.getFeedVideos();
111+
this.category.getFeedVideos();
125112

126113
} else {
127-
this._shared.triggerNotify('Please check external settings');
114+
this.shared.triggerNotify('Please check external settings');
128115
}
129116
}
130117
}

src/app/models/channel.model.ts

Lines changed: 0 additions & 93 deletions
This file was deleted.

src/app/services/globals.service.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ export class GlobalsService {
2929
darkMode = true;
3030

3131
regionCode = '';
32+
apiKey = '';
33+
numSearchRes = '';
34+
numRelatedRes = '';
3235

3336
settings: any;
3437

0 commit comments

Comments
 (0)