start of post functions with bookmarks and reposts wired

This commit is contained in:
Morgan McMillian 2017-06-10 14:45:02 -07:00
parent ac0974d41c
commit fe25cf647e
4 changed files with 135 additions and 71 deletions

View file

@ -42,8 +42,6 @@ export class MyApp {
}
}).catch(err => {
console.log('ERROR: ' + err);
pnut.token = 'DOLORSITAmET6E6uaqT70D8R8o-yAG2eqa48wBihEqYhWKN3WQzlIzBd4V18vI-OCjKWCwGUQDPlNO2sS9DgkyYMM0SbJAirYH';
this.nav.setRoot(StreamPage, {stream: 'global'});
});
this.platform.ready().then(() => {

View file

@ -41,24 +41,45 @@
<ion-row>
<ion-col>
<button ion-button icon-left clear small block>
<ion-icon name="text"></ion-icon>
</button>
</ion-col>
<ion-col>
<button ion-button icon-left clear small block>
<ion-icon name="quote"></ion-icon>
</button>
</ion-col>
<ion-col>
<button ion-button icon-left clear small block (click)="bookmark(post.id, post.you_bookmarked)">
<ion-icon name="star"></ion-icon>
<div *ngIf="post.counts.bookmarks > 0">{{ post.counts.bookmarks }}</div>
</button>
</ion-col>
<ion-col>
<button ion-button icon-left clear small block>
<button ion-button icon-left clear small block (click)="repost(post.id, post.you_reposted)">
<ion-icon name="repeat"></ion-icon>
<div *ngIf="post.counts.reposts > 0">{{ post.counts.reposts }}</div>
</button>
</ion-col>
<ion-col>
<button ion-button icon-left clear small block>
<ion-icon name="text"></ion-icon>
<ion-icon name="chatboxes"></ion-icon>
<div *ngIf="post.counts.replies > 0">{{ post.counts.replies }}</div>
</button>
</ion-col>
<ion-col>
<button ion-button icon-left clear small block>
<ion-icon name="more"></ion-icon>
</button>
</ion-col>
</ion-row>
</ion-card>
</ion-list>
<ion-fab right bottom>
<button ion-fab>
<ion-icon name="add"></ion-icon>
</button>
</ion-fab>
</ion-content>

View file

@ -58,4 +58,49 @@ export class StreamPage {
this.navCtrl.push(PostDetailsPage, {post: postData});
}
bookmark(postid, bookmarked) {
if (bookmarked) {
pnut.deleteBookmark(postid).then(res => {
console.log(res);
this.updatePost(res.data);
}).catch(err => {
console.log(err);
});
} else {
pnut.bookmark(postid).then(res => {
console.log(res);
this.updatePost(res.data);
}).catch(err => {
console.log(err);
});
}
}
repost(postid, reposted) {
if (reposted) {
pnut.deleteRepost(postid).then(res => {
console.log(res);
this.updatePost(res.data);
}).catch(err => {
console.log(err);
});
} else {
pnut.repost(postid).then(res => {
console.log(res);
this.updatePost(res.data);
}).catch(err => {
console.log(err);
});
}
}
updatePost(postData) {
for (var i = 0; i < this.posts.length; i++) {
if (this.posts[i]['id'] === postData.id) {
this.posts[i] = postData;
break;
}
}
}
}