fix bookmark and repost from thread view issue #36
This commit is contained in:
parent
7e58365dac
commit
61024e18ca
1 changed files with 66 additions and 3 deletions
|
@ -1,8 +1,8 @@
|
|||
import { Component } from '@angular/core';
|
||||
import { NavController, NavParams, ModalController } from 'ionic-angular';
|
||||
import { NavController, NavParams, ModalController, ToastController } from 'ionic-angular';
|
||||
import { NewPostModal } from '../stream/stream';
|
||||
|
||||
// import * as pnut from 'pnut-butter';
|
||||
import * as pnut from 'pnut-butter';
|
||||
|
||||
/**
|
||||
* Generated class for the ThreadPage page.
|
||||
|
@ -19,7 +19,8 @@ export class ThreadPage {
|
|||
title: string;
|
||||
posts: Array<Object> = [];
|
||||
|
||||
constructor(public navCtrl: NavController, public navParams: NavParams, public modalCtrl: ModalController) {
|
||||
constructor(public navCtrl: NavController, public navParams: NavParams, public modalCtrl: ModalController,
|
||||
public toastCtrl: ToastController) {
|
||||
this.posts = this.navParams.data.posts;
|
||||
}
|
||||
|
||||
|
@ -34,4 +35,66 @@ export class ThreadPage {
|
|||
newPostModal.present();
|
||||
}
|
||||
|
||||
bookmark(postid, bookmarked) {
|
||||
if (bookmarked) {
|
||||
pnut.deleteBookmark(postid).then(res => {
|
||||
console.log(res);
|
||||
this.updatePost(res.data.id);
|
||||
this.presentToast("Bookmark updated.");
|
||||
}).catch(err => {
|
||||
console.log(err);
|
||||
});
|
||||
} else {
|
||||
pnut.bookmark(postid).then(res => {
|
||||
console.log(res);
|
||||
this.updatePost(res.data.id);
|
||||
this.presentToast("Bookmark updated.");
|
||||
}).catch(err => {
|
||||
console.log(err);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
repost(postid, reposted) {
|
||||
if (reposted) {
|
||||
pnut.deleteRepost(postid).then(res => {
|
||||
console.log(res);
|
||||
this.updatePost(res.data.id);
|
||||
this.presentToast("Repost updated.");
|
||||
}).catch(err => {
|
||||
console.log(err);
|
||||
});
|
||||
} else {
|
||||
pnut.repost(postid).then(res => {
|
||||
console.log(res);
|
||||
this.updatePost(res.data.id);
|
||||
this.presentToast("Repost updated.");
|
||||
}).catch(err => {
|
||||
console.log(err);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
updatePost(postid) {
|
||||
pnut.post(postid, {include_raw: 1}).then(res => {
|
||||
for (var i = 0; i < this.posts.length; i++) {
|
||||
if (this.posts[i]['id'] === postid) {
|
||||
this.posts[i] = res.data;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}).catch(err => {
|
||||
console.log(err);
|
||||
});
|
||||
}
|
||||
|
||||
presentToast(text) {
|
||||
let toast = this.toastCtrl.create({
|
||||
position: 'top',
|
||||
message: text,
|
||||
duration: 2000
|
||||
});
|
||||
toast.present();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Reference in a new issue