Skip to content

Instantly share code, notes, and snippets.

@haverchuck
Last active June 25, 2018 21:05
Show Gist options
  • Save haverchuck/11d31c800cdfa91bb013908d2989b4a4 to your computer and use it in GitHub Desktop.
Save haverchuck/11d31c800cdfa91bb013908d2989b4a4 to your computer and use it in GitHub Desktop.
ionic-amplify-part-1
import { Component, OnInit, Input } from '@angular/core';
import { ModalController, Events } from '@ionic/angular';
// import { ListItemModal } from './list.item.modal';
import { ToDoItem, ToDoList } from '../../classes/item.class';
@Component({
selector: 'app-list-page',
templateUrl: 'list.page.html'
})
export class ListPage implements OnInit {
modal: any;
data: any;
user: any;
itemList: ToDoList;
signedIn: boolean;
constructor(
public modalController: ModalController,
events: Events
) {
// Listen for changes to the AuthState in order to change item list appropriately
events.subscribe('data:AuthState', async (data) => {
if (data.loggedIn){
this.getItems();
} else {
// this.itemList.items = [];
}
})
}
async ngOnInit(){
this.getItems();
}
async modify(item, i) {
let props = {
itemList: this.itemList,
/*
We pass in an item paramenter only when the user clicks on an existing item
and therefore populate an editItem value so that our modal knows this is an edit operation.
*/
editItem: item || undefined
};
// Create the modal
// this.modal = await this.modalController.create({
// component: ListItemModal,
// componentProps: props
// });
// Listen for the modal to be closed...
// this.modal.onDidDismiss((result) => {
// if (result.data.newItem){
// // ...and add a new item if modal passes back newItem
// result.data.itemList.items.push(result.data.newItem)
// } else if (result.data.editItem){
// // ...or splice the items array if the modal passes back editItem
// result.data.itemList.items[i] = result.data.editItem
// }
// this.save(result.data.itemList);
// })
// return this.modal.present()
}
delete(i){
this.itemList.items.splice(i, 1);
// this.save(this.itemList);
}
complete(i){
this.itemList.items[i].status = "complete";
// this.save(this.itemList);
}
save(list){
// Use AWS Amplify to save the list...
// this.itemList = list;
}
getItems(){
this.itemList = {
userId: 1,
items: [
new ToDoItem({
id: '1',
title: 'test item 1',
description: 'my test item',
status: 'complete'
}),
new ToDoItem({
id: '2',
title: 'test item 3',
description: 'my other test item',
status: 'pending'
})
]
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment