Skip to content

Commit 806faad

Browse files
author
pigr2
committed
improve UI, show empty results
1 parent 05b5a5e commit 806faad

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

app/app.component.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,22 @@ const storeManager = provideStore({ currentSearch: SearchReducer });
1919
<h1>{{title}}</h1>
2020
<div class="row col-md-8">
2121
<search-box [store]="store"></search-box>
22-
<proximity-selector [store]="store"></proximity-selector>
22+
<proximity-selector [store]="store" [disabled]="disableSearch"
23+
[ngClass]="{ disabled: disableSearch }"></proximity-selector>
24+
</div>
25+
<div class="row col-md-8 alert alert-danger" *ngIf="disableSearch">
26+
<p>Can't use geolocalization with an empty searchbox</p>
2327
</div>
2428
<div class="row col-md-8">
2529
<p>
2630
Try to type something in the searchbox, play with the location and with radius: the above state will
2731
always be consistent and up to date.
2832
</p>
29-
<p>{{ state | json }}</p>
33+
<p class="state">{{ state | json }}</p>
34+
<p class="state" *ngIf="disableSearch">{ }</p>
3035
</div>
36+
<h2 *ngIf="!disableSearch">Search results:</h2>
37+
<h2 *ngIf="disableSearch || searchResults.length == 0">No results</h2>
3138
<div class="row col-md-8">
3239
<div *ngFor="let result of searchResults" class="thumbnail col-sm-6 col-md-4">
3340
<div class="caption">
@@ -45,9 +52,9 @@ export class AppComponent implements OnInit {
4552
title = 'One Source of Truth for Angular 2';
4653

4754
private state: CurrentSearch;
48-
4955
private currentSearch: Observable<CurrentSearch>;
5056
private searchResults: SearchResult[] = [];
57+
private disableSearch = false;
5158

5259
constructor(
5360
private store: Store<CurrentSearch>,
@@ -61,8 +68,10 @@ export class AppComponent implements OnInit {
6168
this.currentSearch.subscribe((state: CurrentSearch) => {
6269
this.state = state;
6370
if (state && state.name && state.name.length > 0) {
71+
this.disableSearch = false;
6472
this.youtube.search(state)
6573
} else {
74+
this.disableSearch = true;
6675
this.searchResults = [];
6776
}
6877
});

app/components/proximity-selector.component.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {Store} from '@ngrx/store';
33

44
@Component({
55
selector: 'proximity-selector',
6-
inputs: ['store'],
6+
inputs: ['store', 'disabled'],
77
template: `
88
<div class="input-group">
99
<label for="useLocation">Use current location</label>
@@ -14,7 +14,7 @@ import {Store} from '@ngrx/store';
1414
<div class="input-group">
1515
<label for="locationRadius">Radius</label>
1616
<input type="range" min="1" max="100" value="50"
17-
[disabled]="!active"
17+
[disabled]="!active || disabled"
1818
(change)="onRadius($event)">
1919
</div>
2020
`
@@ -31,6 +31,9 @@ export class ProximitySelector {
3131
@Input()
3232
store: Store<any>;
3333

34+
@Input()
35+
disabled: boolean;
36+
3437
active = false;
3538

3639
onLocation($event: any) {

index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
<meta name="viewport" content="width=device-width, initial-scale=1">
66

77
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet">
8+
<link href="app/styles.css" rel="stylesheet">
89

910
<script src="node_modules/zone.js/dist/zone.js"></script>
1011
<script src="node_modules/reflect-metadata/Reflect.js"></script>

0 commit comments

Comments
 (0)