Skip to content

Commit 089a574

Browse files
author
pigr2
committed
finished... with youtube thingy
1 parent 7ab7087 commit 089a574

File tree

3 files changed

+9
-28
lines changed

3 files changed

+9
-28
lines changed

app/app.component.ts

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ const storeManager = provideStore({ currentSearch: SearchReducer });
3030
</div>
3131
<div class="row col-md-8">
3232
<ul>
33-
<li *ngFor="let result of searchResults">{{ result.title }}</li>
33+
<li *ngFor="let result of searchResults">
34+
<h3>{{ result.title }}</h3>
35+
<img src="{{ result.thumbnailUrl }}" />
36+
</li>
3437
</ul>
3538
</div>
3639
</section>
@@ -41,10 +44,6 @@ const storeManager = provideStore({ currentSearch: SearchReducer });
4144

4245
export class AppComponent implements OnInit {
4346

44-
static StoreEvents = {
45-
results: 'RESULTS'
46-
};
47-
4847
title = ''; //'One Source of Truth for Angular 2';
4948

5049
private state: SearchQuery;
@@ -57,27 +56,16 @@ export class AppComponent implements OnInit {
5756
private youtube: YouTubeService
5857
) {
5958
this.currentSearch = this.store.select<SearchQuery>('currentSearch');
59+
this.youtube.searchResults.subscribe((results: SearchResult[]) => this.searchResults = results);
6060
}
6161

6262
ngOnInit() {
6363
this.currentSearch.subscribe((state: SearchQuery) => {
6464
this.state = state;
65-
if (state && state.name) {
66-
this.youtube.search(state).subscribe((results: SearchResult[]) =>
67-
this.store.dispatch({
68-
type: AppComponent.StoreEvents.results,
69-
payload: {
70-
results: results
71-
}
72-
})
73-
)
65+
if (state && state.name && state.name.length > 0) {
66+
this.youtube.search(state)
7467
} else {
75-
this.store.dispatch({
76-
type: AppComponent.StoreEvents.results,
77-
payload: {
78-
results: []
79-
}
80-
})
68+
this.searchResults = [];
8169
}
8270
});
8371
}

app/models/search-query.model.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
import {SearchResult} from "./search-result.model";
21
export interface SearchQuery {
32
name: string;
43
location?: {
54
latitude: number,
65
longitude: number,
76
radius: number
8-
},
9-
results: SearchResult[]
7+
}
108
}

app/reducers/search.reducer.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { ActionReducer, Action } from '@ngrx/store';
22
import {SearchBox} from '../components/search-box.component';
33
import {ProximitySelector} from '../components/proximity-selector.component';
44
import {SearchQuery} from "../models/search-query.model";
5-
import {AppComponent} from "../app.component";
65

76
export const SearchReducer: ActionReducer<SearchQuery> = (state: SearchQuery, action: Action) => {
87
switch (action.type) {
@@ -28,10 +27,6 @@ export const SearchReducer: ActionReducer<SearchQuery> = (state: SearchQuery, ac
2827
return Object.assign({}, state, {
2928
location: null
3029
});
31-
case AppComponent.StoreEvents.results:
32-
return Object.assign({}, state, {
33-
results: action.payload.results
34-
});
3530
default:
3631
return state;
3732
}

0 commit comments

Comments
 (0)