Skip to content

Commit

Permalink
Remove lisk task method created without server call
Browse files Browse the repository at this point in the history
  • Loading branch information
monicagonzalezg committed Dec 19, 2017
1 parent c1c7f1d commit 27040a5
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/pages/lists/lists.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
<ion-header>

<ion-navbar color="secondary">
<ion-buttons end *ngIf="selectedList != null">
<button ion-button (click)="removeSelectedList()">
<ion-icon name="trash"></ion-icon>
</button>
</ion-buttons>
<ion-title>My lists</ion-title>
</ion-navbar>

Expand All @@ -15,7 +20,7 @@

<ion-content padding>
<ion-list>
<ion-item *ngFor="let list of listService.list" (click)="goToList(list)">{{list.name}}</ion-item>
<ion-item *ngFor="let list of listService.list" (tap)="goToList(list)" (press)="selectList(list)">{{list.name}}</ion-item>
</ion-list>
</ion-content>
<ion-fab right bottom>
Expand Down
20 changes: 20 additions & 0 deletions src/pages/lists/lists.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ import { ListModel} from "../../data/list-model";
})
export class ListsPage {

public selectedList:ListModel = null;
constructor(public navCtrl: NavController, public navParams: NavParams,
public alertCtrl: AlertController, public listService:ListServiceProvider,
private loadingCtrl: LoadingController) {
}

goToList(list: ListModel):void{
this.clearSelected();
this.navCtrl.push(TodosPage, {list});
}

Expand Down Expand Up @@ -77,4 +79,22 @@ export class ListsPage {
});

}

clearSelected(){
this.selectedList = null;
}

selectList(list:ListModel){
if(this.selectedList == list){
this.clearSelected();
}
else{
this.selectedList = list;
}
}

removeSelectedList(){
this.listService.removeList(this.selectedList);
this.clearSelected();
}
}
12 changes: 11 additions & 1 deletion src/providers/list-service/list-service.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// import { Http } from "@angular/http";
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { ListModel} from "../../data/list-model";
import { ListModel } from "../../data/list-model";
import { Storage} from "@ionic/storage";
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/share';
Expand Down Expand Up @@ -99,4 +99,14 @@ export class ListServiceProvider {

return observable;
}

public removeList(list: ListModel){
this.deleteListFromServer(list.id).subscribe(
()=> {
let index = this.list.indexOf((list));
this.list = [...this.list.slice(0,index), ...this.list.slice(index+1)];
this.saveStorage();
}
)
}
}

0 comments on commit 27040a5

Please sign in to comment.