Added delete button with overflow menu. Issue #19
This commit is contained in:
parent
40d9f12f79
commit
384ad6ad75
2 changed files with 51 additions and 15 deletions
|
@ -82,11 +82,11 @@
|
||||||
<div *ngIf="post.counts.replies > 0">{{ post.counts.replies }}</div>
|
<div *ngIf="post.counts.replies > 0">{{ post.counts.replies }}</div>
|
||||||
</button>
|
</button>
|
||||||
</ion-col>
|
</ion-col>
|
||||||
<!-- <ion-col>
|
<ion-col>
|
||||||
<button ion-button icon-left clear small block (click)="presentPostMenu($event)">
|
<button ion-button icon-left clear small block (click)="presentPostMenu($event, post)">
|
||||||
<ion-icon name="more"></ion-icon>
|
<ion-icon name="more"></ion-icon>
|
||||||
</button>
|
</button>
|
||||||
</ion-col> -->
|
</ion-col>
|
||||||
</ion-row>
|
</ion-row>
|
||||||
</ion-card>
|
</ion-card>
|
||||||
</ion-list>
|
</ion-list>
|
||||||
|
|
|
@ -2,6 +2,7 @@ import { Component, ViewChild, ChangeDetectorRef } from '@angular/core';
|
||||||
import { ViewController, NavController, NavParams, ModalController, Content, ToastController, PopoverController } from 'ionic-angular';
|
import { ViewController, NavController, NavParams, ModalController, Content, ToastController, PopoverController } from 'ionic-angular';
|
||||||
import { ThreadPage } from '../thread/thread';
|
import { ThreadPage } from '../thread/thread';
|
||||||
import { Storage } from '@ionic/storage';
|
import { Storage } from '@ionic/storage';
|
||||||
|
import { Events } from 'ionic-angular';
|
||||||
|
|
||||||
import * as pnut from 'pnut-butter';
|
import * as pnut from 'pnut-butter';
|
||||||
|
|
||||||
|
@ -31,7 +32,7 @@ export class StreamPage {
|
||||||
|
|
||||||
constructor(public navCtrl: NavController, public navParams: NavParams, public modalCtrl: ModalController,
|
constructor(public navCtrl: NavController, public navParams: NavParams, public modalCtrl: ModalController,
|
||||||
private changeDetectorRef: ChangeDetectorRef, public toastCtrl: ToastController, private storage: Storage,
|
private changeDetectorRef: ChangeDetectorRef, public toastCtrl: ToastController, private storage: Storage,
|
||||||
public popoverCtrl: PopoverController) {
|
public popoverCtrl: PopoverController, public events: Events) {
|
||||||
// console.log(JSON.stringify(navParams));
|
// console.log(JSON.stringify(navParams));
|
||||||
|
|
||||||
this.storage.get('unified').then((val) => {
|
this.storage.get('unified').then((val) => {
|
||||||
|
@ -72,6 +73,12 @@ export class StreamPage {
|
||||||
// console.log('-*-');
|
// console.log('-*-');
|
||||||
// console.log(JSON.stringify(err));
|
// console.log(JSON.stringify(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.events.subscribe('stream:reload', (event) => {
|
||||||
|
console.log('-reload-');
|
||||||
|
this.refreshPage();
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ngAfterViewInit() {
|
ngAfterViewInit() {
|
||||||
|
@ -86,6 +93,11 @@ export class StreamPage {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
refreshPage() {
|
||||||
|
// this.navCtrl.setRoot(this.navCtrl.getActive().component);
|
||||||
|
this.navCtrl.setRoot(StreamPage, {stream: 'personal'});
|
||||||
|
}
|
||||||
|
|
||||||
fetchOlderPosts(infiniteScroll) {
|
fetchOlderPosts(infiniteScroll) {
|
||||||
let params = {
|
let params = {
|
||||||
include_deleted: 0,
|
include_deleted: 0,
|
||||||
|
@ -281,11 +293,9 @@ export class StreamPage {
|
||||||
toast.present();
|
toast.present();
|
||||||
}
|
}
|
||||||
|
|
||||||
presentPostMenu(myEvent) {
|
presentPostMenu(myEvent, postData) {
|
||||||
let popover = this.popoverCtrl.create(PostMenu);
|
let popover = this.popoverCtrl.create(PostMenu, {post: postData, me: this.myUsername});
|
||||||
popover.present({
|
popover.present({ev: myEvent});
|
||||||
ev: myEvent
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
scrollToTop() {
|
scrollToTop() {
|
||||||
|
@ -338,7 +348,8 @@ export class NewPostModal {
|
||||||
options: Object;
|
options: Object;
|
||||||
myUsername: string;
|
myUsername: string;
|
||||||
|
|
||||||
constructor(public navParams: NavParams, public viewCtrl: ViewController, public toastCtrl: ToastController) {
|
constructor(public navParams: NavParams, public viewCtrl: ViewController, public toastCtrl: ToastController,
|
||||||
|
public events: Events) {
|
||||||
console.log(this.navParams);
|
console.log(this.navParams);
|
||||||
this.myUsername = navParams.data.me;
|
this.myUsername = navParams.data.me;
|
||||||
if (navParams.data.type === 'reply') {
|
if (navParams.data.type === 'reply') {
|
||||||
|
@ -372,6 +383,7 @@ export class NewPostModal {
|
||||||
pnut.createPost(this.ptext, this.options).then(res => {
|
pnut.createPost(this.ptext, this.options).then(res => {
|
||||||
console.log(res);
|
console.log(res);
|
||||||
this.presentToast("Status posted.");
|
this.presentToast("Status posted.");
|
||||||
|
this.events.publish('stream:reload', {});
|
||||||
}).catch(err => {
|
}).catch(err => {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
});
|
});
|
||||||
|
@ -407,7 +419,7 @@ export class NewPostModal {
|
||||||
template: `
|
template: `
|
||||||
<ion-list>
|
<ion-list>
|
||||||
<button ion-item disabled (click)="close()">Share</button>
|
<button ion-item disabled (click)="close()">Share</button>
|
||||||
<button ion-item *ngIf="showDelBtn" (click)="close()">Delete</button>
|
<button ion-item *ngIf="showDelBtn" (click)="delete()">Delete</button>
|
||||||
</ion-list>
|
</ion-list>
|
||||||
`
|
`
|
||||||
})
|
})
|
||||||
|
@ -415,11 +427,35 @@ export class PostMenu {
|
||||||
|
|
||||||
showDelBtn: boolean = false;
|
showDelBtn: boolean = false;
|
||||||
|
|
||||||
constructor(public navParams: NavParams, public viewCtrl: ViewController) {}
|
constructor(public navParams: NavParams, public viewCtrl: ViewController, public toastCtrl: ToastController,
|
||||||
|
public events: Events) {
|
||||||
|
if (navParams.data.me == navParams.data.post.user.username) {
|
||||||
|
this.showDelBtn = true;
|
||||||
|
} else {
|
||||||
|
this.showDelBtn = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// buttonState() {
|
delete() {
|
||||||
// return this.showDelBtn ? _.state : _;
|
pnut.deletePost(this.navParams.data.post.id).then(res => {
|
||||||
// }
|
console.log(res);
|
||||||
|
this.presentToast('Post Deleted');
|
||||||
|
this.events.publish('stream:reload', {});
|
||||||
|
}).catch( err => {
|
||||||
|
console.log('-error-');
|
||||||
|
console.log(err);
|
||||||
|
});
|
||||||
|
this.close()
|
||||||
|
}
|
||||||
|
|
||||||
|
presentToast(text) {
|
||||||
|
let toast = this.toastCtrl.create({
|
||||||
|
position: 'top',
|
||||||
|
message: text,
|
||||||
|
duration: 2000
|
||||||
|
});
|
||||||
|
toast.present();
|
||||||
|
}
|
||||||
|
|
||||||
close() {
|
close() {
|
||||||
this.viewCtrl.dismiss();
|
this.viewCtrl.dismiss();
|
||||||
|
|
Reference in a new issue