From ea50f823cbe51fbb85ac0eb937a50bfcc51e50a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Hanol?= Date: Wed, 6 Dec 2017 21:58:05 +0100 Subject: [PATCH] FIX: logging in after an anon :heart: does not count the :heart: --- .../discourse/widgets/post-menu.js.es6 | 24 +++++++++++++------ 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/app/assets/javascripts/discourse/widgets/post-menu.js.es6 b/app/assets/javascripts/discourse/widgets/post-menu.js.es6 index 7b4483c28af..dbe2d88eba8 100644 --- a/app/assets/javascripts/discourse/widgets/post-menu.js.es6 +++ b/app/assets/javascripts/discourse/widgets/post-menu.js.es6 @@ -43,6 +43,7 @@ export function buildButton(name, widget) { registerButton('like', attrs => { if (!attrs.showLike) { return; } + const className = attrs.liked ? 'toggle-like has-like fade-out' : 'toggle-like like'; const button = { @@ -51,13 +52,13 @@ registerButton('like', attrs => { className }; - if (attrs.canToggleLike) { button.title = attrs.liked ? 'post.controls.undo_like' : 'post.controls.like'; } else if (attrs.liked) { button.title = 'post.controls.has_liked'; button.disabled = true; } + return button; }); @@ -256,12 +257,18 @@ export default createWidget('post-menu', { }, html(attrs, state) { - const { siteSettings } = this; + const { currentUser, keyValueStore, siteSettings } = this; - const hiddenSetting = (siteSettings.post_menu_hidden_items || ''); - const hiddenButtons = hiddenSetting.split('|').filter(s => { - return !attrs.bookmarked || s !== 'bookmark'; - }); + const hiddenSetting = siteSettings.post_menu_hidden_items || ''; + const hiddenButtons = hiddenSetting.split('|').filter(s => !attrs.bookmarked || s !== 'bookmark'); + + if (currentUser) { + const likedPostId = keyValueStore.getInt("likedPostId"); + if (likedPostId === attrs.id) { + keyValueStore.remove("likedPostId"); + Ember.run.next(() => this.sendWidgetAction("toggleLike")); + } + } const allButtons = []; let visibleButtons = []; @@ -380,10 +387,13 @@ export default createWidget('post-menu', { }, like() { + const { attrs } = this; + if (!this.currentUser) { + this.keyValueStore.set({ key: "likedPostId", value: attrs.id }); return this.sendWidgetAction('showLogin'); } - const attrs = this.attrs; + if (attrs.liked) { return this.sendWidgetAction('toggleLike'); }