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>
|
||||
</button>
|
||||
</ion-col>
|
||||
<!-- <ion-col>
|
||||
<button ion-button icon-left clear small block (click)="presentPostMenu($event)">
|
||||
<ion-col>
|
||||
<button ion-button icon-left clear small block (click)="presentPostMenu($event, post)">
|
||||
<ion-icon name="more"></ion-icon>
|
||||
</button>
|
||||
</ion-col> -->
|
||||
</ion-col>
|
||||
</ion-row>
|
||||
</ion-card>
|
||||
</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 { ThreadPage } from '../thread/thread';
|
||||
import { Storage } from '@ionic/storage';
|
||||
import { Events } from 'ionic-angular';
|
||||
|
||||
import * as pnut from 'pnut-butter';
|
||||
|
||||
|
@ -31,7 +32,7 @@ export class StreamPage {
|
|||
|
||||
constructor(public navCtrl: NavController, public navParams: NavParams, public modalCtrl: ModalController,
|
||||
private changeDetectorRef: ChangeDetectorRef, public toastCtrl: ToastController, private storage: Storage,
|
||||
public popoverCtrl: PopoverController) {
|
||||
public popoverCtrl: PopoverController, public events: Events) {
|
||||
// console.log(JSON.stringify(navParams));
|
||||
|
||||
this.storage.get('unified').then((val) => {
|
||||
|
@ -72,6 +73,12 @@ export class StreamPage {
|
|||
// console.log('-*-');
|
||||
// console.log(JSON.stringify(err));
|
||||
});
|
||||
|
||||
this.events.subscribe('stream:reload', (event) => {
|
||||
console.log('-reload-');
|
||||
this.refreshPage();
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
ngAfterViewInit() {
|
||||
|
@ -86,6 +93,11 @@ export class StreamPage {
|
|||
});
|
||||
}
|
||||
|
||||
refreshPage() {
|
||||
// this.navCtrl.setRoot(this.navCtrl.getActive().component);
|
||||
this.navCtrl.setRoot(StreamPage, {stream: 'personal'});
|
||||
}
|
||||
|
||||
fetchOlderPosts(infiniteScroll) {
|
||||
let params = {
|
||||
include_deleted: 0,
|
||||
|
@ -281,11 +293,9 @@ export class StreamPage {
|
|||
toast.present();
|
||||
}
|
||||
|
||||
presentPostMenu(myEvent) {
|
||||
let popover = this.popoverCtrl.create(PostMenu);
|
||||
popover.present({
|
||||
ev: myEvent
|
||||
});
|
||||
presentPostMenu(myEvent, postData) {
|
||||
let popover = this.popoverCtrl.create(PostMenu, {post: postData, me: this.myUsername});
|
||||
popover.present({ev: myEvent});
|
||||
}
|
||||
|
||||
scrollToTop() {
|
||||
|
@ -338,7 +348,8 @@ export class NewPostModal {
|
|||
options: Object;
|
||||
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);
|
||||
this.myUsername = navParams.data.me;
|
||||
if (navParams.data.type === 'reply') {
|
||||
|
@ -372,6 +383,7 @@ export class NewPostModal {
|
|||
pnut.createPost(this.ptext, this.options).then(res => {
|
||||
console.log(res);
|
||||
this.presentToast("Status posted.");
|
||||
this.events.publish('stream:reload', {});
|
||||
}).catch(err => {
|
||||
console.log(err);
|
||||
});
|
||||
|
@ -407,7 +419,7 @@ export class NewPostModal {
|
|||
template: `
|
||||
<ion-list>
|
||||
<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>
|
||||
`
|
||||
})
|
||||
|
@ -415,11 +427,35 @@ export class PostMenu {
|
|||
|
||||
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() {
|
||||
// return this.showDelBtn ? _.state : _;
|
||||
// }
|
||||
delete() {
|
||||
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() {
|
||||
this.viewCtrl.dismiss();
|
||||
|
|
Reference in a new issue