浏览代码

Merge pull request #4676 from viviicat/fix-post-follow

Update Post component, adding follow and unfollow methods.
daniel 1 年之前
父节点
当前提交
d85c0c3d0a
共有 1 个文件被更改,包括 26 次插入0 次删除
  1. 26 0
      resources/assets/components/Post.vue

+ 26 - 0
resources/assets/components/Post.vue

@@ -37,6 +37,8 @@
 						v-on:bookmark="handleBookmark()"
 						v-on:share="shareStatus()"
 						v-on:unshare="unshareStatus()"
+						v-on:follow="follow()"
+						v-on:unfollow="unfollow()"
 						v-on:counter-change="counterChange"
 						/>
 				</div>
@@ -333,6 +335,30 @@
 				})
 			},
 
+			follow() {
+				axios.post('/api/v1/accounts/' + this.post.account.id + '/follow')
+				.then(res => {
+					this.$store.commit('updateRelationship', [res.data]);
+					this.user.following_count++;
+					this.post.account.followers_count++;
+				}).catch(err => {
+					swal('Oops!', 'An error occurred when attempting to follow this account.', 'error');
+					this.post.relationship.following = false;
+				});
+			},
+
+			unfollow() {
+				axios.post('/api/v1/accounts/' + this.post.account.id + '/unfollow')
+				.then(res => {
+					this.$store.commit('updateRelationship', [res.data]);
+					this.user.following_count--;
+					this.post.account.followers_count--;
+				}).catch(err => {
+					swal('Oops!', 'An error occurred when attempting to unfollow this account.', 'error');
+					this.post.relationship.following = true;
+				});
+			},
+
 			openContextMenu() {
 				this.$nextTick(() => {
 					this.$refs.contextMenu.open();