瀏覽代碼

Fix bug where you couldn't like a post if it was by a deleted user; TODO: fix bug involving component state when user logs out

sbkwgh 8 年之前
父節點
當前提交
619fdeea5c
共有 1 個文件被更改,包括 12 次插入2 次删除
  1. 12 2
      src/components/HeartButton.vue

+ 12 - 2
src/components/HeartButton.vue

@@ -25,10 +25,13 @@
 		},
 		computed: {
 			likeable () {
+				let postUsername = this.post.User ?
+					this.post.User.username : 
+					null
+
 				return (
 					this.$store.state.username &&
-					this.post.User &&
-					this.post.User.username !== this.$store.state.username
+					postUsername !== this.$store.state.username
 				)
 			},
 			likes: {
@@ -81,6 +84,13 @@
 						})
 				}
 			}
+		},
+		watch: {
+			//TODO: fix this subtle bug
+			'$store.state.username': function() {
+				this._liked = false
+				this.$forceUpdate()
+			}
 		}
 	}
 </script>