Skip to content

Commit e69000d

Browse files
committed
new starting point, with Angular 2
1 parent e129942 commit e69000d

8 files changed

+13
-275
lines changed

app/app.component.ts

+6-46
Original file line numberDiff line numberDiff line change
@@ -2,72 +2,32 @@ import {Component, OnInit} from '@angular/core';
22
import {Observable} from "rxjs";
33
import {Store} from "@ngrx/store";
44

5-
import {CurrentSearch} from "./models/current-search.model";
6-
import {SearchResult} from "./models/search-result.model";
7-
import {YouTubeService} from "./services/youtube.service";
8-
95
@Component({
106
selector: 'my-app',
117
template: `
128
<section class="col-md-8">
139
<h1>{{title}}</h1>
1410
<div class="row col-md-8">
15-
<search-box [store]="store"></search-box>
16-
<proximity-selector [store]="store" [disabled]="disableSearch"
17-
[ngClass]="{ disabled: disableSearch }"></proximity-selector>
18-
</div>
19-
<div class="row col-md-8 alert alert-danger" *ngIf="disableSearch">
20-
<p>Can't use geolocalization with an empty searchbox</p>
11+
<!-- put searchbox and proximity selector here -->
2112
</div>
2213
<div class="row col-md-8">
23-
<p>
24-
Try to type something in the searchbox, play with the location and with radius: the above state will
25-
always be consistent and up to date.
26-
</p>
27-
<p class="state">{{ state | json }}</p>
28-
<p class="state" *ngIf="disableSearch">state is empty</p>
29-
<h2 *ngIf="!disableSearch">Search results:</h2>
14+
<!-- put the state here -->
3015
</div>
31-
<h2 *ngIf="disableSearch || searchResults.length == 0">No results</h2>
32-
<div class="row col-md-8">
33-
<div *ngFor="let result of searchResults" class="thumbnail col-sm-6 col-md-4">
34-
<div class="caption">
35-
<h3>{{ result.title }}</h3>
36-
</div>
37-
<img src="{{ result.thumbnailUrl }}" />
38-
</div>
39-
</div>
40-
</section>
16+
</section>
4117
`
4218
})
4319
export class AppComponent implements OnInit {
4420

4521
title = 'One Source of Truth for Angular 2';
4622

47-
private state: CurrentSearch;
48-
private currentSearch: Observable<CurrentSearch>;
49-
private searchResults: SearchResult[] = [];
50-
private disableSearch = false;
51-
5223
constructor(
53-
private store: Store<CurrentSearch>,
54-
private youtube: YouTubeService
24+
// inject store and youtube service
5525
) {
56-
this.currentSearch = this.store.select<CurrentSearch>('currentSearch');
57-
this.youtube.searchResults.subscribe((results: SearchResult[]) => this.searchResults = results);
26+
// select the state here
5827
}
5928

6029
ngOnInit() {
61-
this.currentSearch.subscribe((state: CurrentSearch) => {
62-
this.state = state;
63-
if (state && state.name && state.name.length > 0) {
64-
this.disableSearch = false;
65-
this.youtube.search(state)
66-
} else {
67-
this.disableSearch = true;
68-
this.searchResults = [];
69-
}
70-
});
30+
// handle here the state's update
7131
}
7232

7333
}

app/app.module.ts

+7-13
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,13 @@
1-
import { NgModule } from '@angular/core';
2-
import { BrowserModule } from '@angular/platform-browser';
3-
import {AppComponent} from "./app.component";
4-
import {Store, StoreModule} from "@ngrx/store";
5-
import {SearchReducer} from "./reducers/search.reducer";
6-
import {YouTubeService} from "./services/youtube.service";
1+
import {NgModule} from '@angular/core';
2+
import {BrowserModule} from '@angular/platform-browser';
73
import {HttpModule} from "@angular/http";
8-
import {SearchBox} from "./components/search-box.component";
9-
import {ProximitySelector} from "./components/proximity-selector.component";
4+
import {Store, StoreModule} from "@ngrx/store";
105

11-
const storeManager = StoreModule.provideStore ({ currentSearch: SearchReducer });
6+
import {AppComponent} from "./app.component";
127

138
@NgModule({
14-
imports: [ BrowserModule, StoreModule, storeManager, HttpModule ],
15-
declarations: [ AppComponent, SearchBox, ProximitySelector ],
16-
bootstrap: [ AppComponent ],
17-
providers: [ YouTubeService ]
9+
imports: [ BrowserModule, HttpModule ],
10+
declarations: [ AppComponent, ],
11+
bootstrap: [ AppComponent ]
1812
})
1913
export class AppModule { }

app/components/proximity-selector.component.ts

-78
This file was deleted.

app/components/search-box.component.ts

-37
This file was deleted.

app/models/current-search.model.ts

-8
This file was deleted.

app/models/search-result.model.ts

-5
This file was deleted.

app/reducers/search.reducer.ts

-30
This file was deleted.

app/services/youtube.service.ts

-58
This file was deleted.

0 commit comments

Comments
 (0)