From c2db2c5c78ad2fed99f3a638d3e1a862dbcf988f Mon Sep 17 00:00:00 2001 From: Joffrey JAFFEUX Date: Fri, 21 Jul 2017 20:18:32 +0200 Subject: [PATCH] FIX: do not store scroll position in local storage --- .../discourse/components/emoji-picker.js.es6 | 17 +++++------------ .../acceptance/emoji-picker-test.js.es6 | 8 -------- 2 files changed, 5 insertions(+), 20 deletions(-) diff --git a/app/assets/javascripts/discourse/components/emoji-picker.js.es6 b/app/assets/javascripts/discourse/components/emoji-picker.js.es6 index 341767818d4..3d4a76df37c 100644 --- a/app/assets/javascripts/discourse/components/emoji-picker.js.es6 +++ b/app/assets/javascripts/discourse/components/emoji-picker.js.es6 @@ -7,7 +7,6 @@ import { extendedEmojiList, isSkinTonableEmoji } from "pretty-text/emoji"; const keyValueStore = new KeyValueStore("discourse_emojis_"); const EMOJI_USAGE = "emojiUsage"; -const EMOJI_SCROLL_Y = "emojiScrollY"; const EMOJI_SELECTED_DIVERSITY = "emojiSelectedDiversity"; const EMOJI_CACHED_SECTIONS = "emojiCachedSections"; const PER_ROW = 11; @@ -18,11 +17,10 @@ const customEmojis = _.map(_.keys(extendedEmojiList()), code => { export function resetCache() { keyValueStore.setObject({ key: EMOJI_CACHED_SECTIONS, value: [] }); keyValueStore.setObject({ key: EMOJI_USAGE, value: [] }); - keyValueStore.setObject({ key: EMOJI_SCROLL_Y, value: 0 }); keyValueStore.setObject({ key: EMOJI_SELECTED_DIVERSITY, value: 1 }); } -let $picker, $filter, $results, $list; +let $picker, $filter, $results, $list, scrollPosition; export default Ember.Component.extend({ willDestroyElement() { @@ -55,6 +53,8 @@ export default Ember.Component.extend({ // handle legacy format keyValueStore.setObject({ key: EMOJI_USAGE, value: _.keys(keyValueStore.getObject(EMOJI_USAGE)) }); } + + scrollPosition = 0; }, didUpdateAttrs() { @@ -302,7 +302,7 @@ export default Ember.Component.extend({ _bindSectionsScroll() { $list.on("scroll", () => { Ember.run.debounce(this, this._checkVisibleSection, 150); - Ember.run.debounce(this, this._storeScrollPosition, 100); + scrollPosition = $list.scrollTop(); }); }, @@ -504,13 +504,6 @@ export default Ember.Component.extend({ } }, - _storeScrollPosition() { - keyValueStore.setObject({ - key: EMOJI_SCROLL_Y, - value: $list.scrollTop() - }); - }, - _trackEmojiUsage(code) { let recent = keyValueStore.getObject(EMOJI_USAGE) || []; recent = recent.filter(r => r !== code); @@ -521,7 +514,7 @@ export default Ember.Component.extend({ }, _scrollTo(y) { - const yPosition = _.isUndefined(y) ? keyValueStore.getObject(EMOJI_SCROLL_Y) : y; + const yPosition = _.isUndefined(y) ? scrollPosition : y; $list.scrollTop(yPosition); diff --git a/test/javascripts/acceptance/emoji-picker-test.js.es6 b/test/javascripts/acceptance/emoji-picker-test.js.es6 index cb0c68b8984..0575bcc48e8 100644 --- a/test/javascripts/acceptance/emoji-picker-test.js.es6 +++ b/test/javascripts/acceptance/emoji-picker-test.js.es6 @@ -167,20 +167,12 @@ QUnit.skip("emoji picker persists state", assert => { click("button.emoji.btn"); andThen(() => { - $('.emoji-picker .list').scrollTop(2600); click('.emoji-picker a.diversity-scale.medium-dark'); }); - click("button.emoji.btn"); click("button.emoji.btn"); andThen(() => { - assert.equal( - find('.emoji-picker .list').scrollTop() > 2500, - true, - "it stores scroll position" - ); - assert.equal( find('.emoji-picker .diversity-scale.medium-dark').hasClass('selected'), true,