@@ -2,72 +2,32 @@ import {Component, OnInit} from '@angular/core';
2
2
import { Observable } from "rxjs" ;
3
3
import { Store } from "@ngrx/store" ;
4
4
5
- import { CurrentSearch } from "./models/current-search.model" ;
6
- import { SearchResult } from "./models/search-result.model" ;
7
- import { YouTubeService } from "./services/youtube.service" ;
8
-
9
5
@Component ( {
10
6
selector : 'my-app' ,
11
7
template : `
12
8
<section class="col-md-8">
13
9
<h1>{{title}}</h1>
14
10
<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 -->
21
12
</div>
22
13
<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 -->
30
15
</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>
41
17
`
42
18
} )
43
19
export class AppComponent implements OnInit {
44
20
45
21
title = 'One Source of Truth for Angular 2' ;
46
22
47
- private state : CurrentSearch ;
48
- private currentSearch : Observable < CurrentSearch > ;
49
- private searchResults : SearchResult [ ] = [ ] ;
50
- private disableSearch = false ;
51
-
52
23
constructor (
53
- private store : Store < CurrentSearch > ,
54
- private youtube : YouTubeService
24
+ // inject store and youtube service
55
25
) {
56
- this . currentSearch = this . store . select < CurrentSearch > ( 'currentSearch' ) ;
57
- this . youtube . searchResults . subscribe ( ( results : SearchResult [ ] ) => this . searchResults = results ) ;
26
+ // select the state here
58
27
}
59
28
60
29
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
71
31
}
72
32
73
33
}
0 commit comments