Skip to content

Commit 1244bec

Browse files
Lec47
1 parent 8591979 commit 1244bec

File tree

2 files changed

+4
-76
lines changed

2 files changed

+4
-76
lines changed

src/pages/search/search.html

Lines changed: 2 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -7,47 +7,12 @@
77
<ion-header>
88

99
<ion-navbar>
10-
<ion-title>Search : {{ searchQuery }}</ion-title>
10+
<ion-title>Search</ion-title>
1111
</ion-navbar>
1212

1313
</ion-header>
1414

1515

1616
<ion-content padding>
17-
<ion-list>
18-
<ion-item *ngFor="let product of products" text-wrap (click)="openProductPage(product)">
19-
<ion-thumbnail item-left>
20-
<img [src]="product.featured_src" />
21-
</ion-thumbnail>
22-
23-
<h2> {{ product.title }} </h2>
24-
25-
<p>
26-
<span [innerHTML]="product.short_description.substr(0, 50) + '...'"></span>
27-
<span [innerHTML]="product.price_html"></span>
28-
<span *ngIf="product.average_rating >= 1">
29-
<ion-icon style="color: #d4af37" small name="star"></ion-icon>
30-
</span>
31-
<span *ngIf="product.average_rating >= 2">
32-
<ion-icon style="color: #d4af37" small name="star"></ion-icon>
33-
</span>
34-
<span *ngIf="product.average_rating >= 3">
35-
<ion-icon style="color: #d4af37" small name="star"></ion-icon>
36-
</span>
37-
<span *ngIf="product.average_rating >= 4">
38-
<ion-icon style="color: #d4af37" small name="star"></ion-icon>
39-
</span>
40-
<span *ngIf="product.average_rating >= 5">
41-
<ion-icon style="color: #d4af37" small name="star"></ion-icon>
42-
</span>
43-
</p>
44-
45-
<button ion-button icon clear item-right>
46-
<ion-icon name="arrow-forward"></ion-icon>
47-
</button>
48-
</ion-item>
49-
</ion-list>
50-
<ion-infinite-scroll (ionInfinite)="loadMoreProducts($event)">
51-
<ion-infinite-scroll-content></ion-infinite-scroll-content>
52-
</ion-infinite-scroll>
17+
5318
</ion-content>

src/pages/search/search.ts

Lines changed: 2 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { Component } from '@angular/core';
2-
import { NavController, NavParams, ToastController } from 'ionic-angular';
3-
import * as WC from 'woocommerce-api';
2+
import { NavController, NavParams} from 'ionic-angular';
43

54
@Component({
65
selector: 'page-search',
@@ -9,50 +8,14 @@ import * as WC from 'woocommerce-api';
98
export class SearchPage {
109

1110
searchQuery: string = "";
12-
WooCommerce: any;
13-
products: any[] = [];
14-
page: number = 2;
1511

1612
constructor(public navCtrl: NavController, public navParams: NavParams, public toastCtrl: ToastController) {
1713
console.log(this.navParams.get("searchQuery"));
18-
this.searchQuery = this.navParams.get("searchQuery");
19-
20-
this.WooCommerce = WC({
21-
url: "http://samarth.cloudapp.net",
22-
consumerKey: "ck_d6c5feec9ea1c407d2f91661c5137c6e3e48ae3b",
23-
consumerSecret: "cs_de8e6cf03a5afd10491dfb1756415ac5a0169ae8"
24-
});
25-
26-
this.WooCommerce.getAsync("products?filter[q]=" + this.searchQuery).then((searchData) => {
27-
this.products = JSON.parse(searchData.body).products;
28-
});
29-
30-
14+
3115
}
3216

3317
ionViewDidLoad() {
3418
console.log('ionViewDidLoad SearchPage');
3519
}
3620

37-
loadMoreProducts(event){
38-
39-
this.WooCommerce.getAsync("products?filter[q]=" + this.searchQuery + "&page=" + this.page).then((searchData) => {
40-
this.products = this.products.concat(JSON.parse(searchData.body).products);
41-
42-
if(JSON.parse(searchData.body).products.length < 10){
43-
event.enable(false);
44-
45-
this.toastCtrl.create({
46-
message: "No more products!",
47-
duration: 5000
48-
}).present();
49-
50-
}
51-
52-
event.complete();
53-
this.page ++;
54-
55-
});
56-
}
57-
5821
}

0 commit comments

Comments
 (0)