浏览代码

Add events to hookup heart button component to thread route

sbkwgh 8 年之前
父节点
当前提交
00b2c7bd14
共有 2 个文件被更改,包括 14 次插入2 次删除
  1. 10 2
      src/components/ThreadPost.vue
  2. 4 0
      src/components/routes/Thread.vue

+ 10 - 2
src/components/ThreadPost.vue

@@ -31,7 +31,12 @@
 				class='post__footer_group'
 			>
 				<div class='post__footer_sub_group'>
-					<heart-button v-model='liked' :likes='post.likes' :likeable='$store.state.username !== post.User.username'></heart-button>
+					<heart-button
+						v-model='likeState'
+						:likes='post.Likes'
+						:likeable='$store.state.username !== post.User.username'
+						@input='emitLikeUpdate'
+					></heart-button>
 				</div>
 				<div class='post__footer_sub_group' v-if='post.Replies.length'>
 						<span class='post__footer_sub_group__text post__footer_sub_group__text--replies'>replies</span>
@@ -88,7 +93,7 @@
 				hover: false,
 				showShareModal: false,
 				postURL: `${location.origin}/thread/${post.Thread.slug}/${post.ThreadId}/${post.postNumber}`,
-				liked: false
+				likeState: false
 			}
 		},
 		computed: {
@@ -109,6 +114,9 @@
 			},
 			goToThread () {
 				this.$router.push(`/thread/${this.post.Thread.slug}/${this.post.Thread.id}`)
+			},
+			emitLikeUpdate () {
+				this.$emit('like', this.post.id, this.likeState)
 			}
 		}
 	}

+ 4 - 0
src/components/routes/Thread.vue

@@ -37,6 +37,7 @@
 					v-for='(post, index) in posts'
 					@reply='replyUser'
 					@goToPost='goToPost'
+					@like='updatePostLike'
 					:post='post'
 					:show-reply='true'
 					:highlight='highlightedPostIndex === index'
@@ -124,6 +125,9 @@
 			addPost () {
 				this.$store.dispatch('addPostAsync', this);
 			},
+			updatePostLike (id, state) {
+				console.log(arguments)
+			},
 			loadNextPosts () {
 				let vue = this
 				this.$store.dispatch('loadPostsAsync', { vue, previous: false });