diff --git a/src/pages/stream/stream.html b/src/pages/stream/stream.html
index e76d835..190497d 100644
--- a/src/pages/stream/stream.html
+++ b/src/pages/stream/stream.html
@@ -82,11 +82,11 @@
0">{{ post.counts.replies }}
-
+
diff --git a/src/pages/stream/stream.ts b/src/pages/stream/stream.ts
index 7b8ee83..bb6a3e4 100644
--- a/src/pages/stream/stream.ts
+++ b/src/pages/stream/stream.ts
@@ -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: `
-
+
`
})
@@ -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();