FIX: do not store scroll position in local storage

This commit is contained in:
Joffrey JAFFEUX 2017-07-21 20:18:32 +02:00
parent d5f53da43f
commit c2db2c5c78
2 changed files with 5 additions and 20 deletions

View File

@ -7,7 +7,6 @@ import { extendedEmojiList, isSkinTonableEmoji } from "pretty-text/emoji";
const keyValueStore = new KeyValueStore("discourse_emojis_"); const keyValueStore = new KeyValueStore("discourse_emojis_");
const EMOJI_USAGE = "emojiUsage"; const EMOJI_USAGE = "emojiUsage";
const EMOJI_SCROLL_Y = "emojiScrollY";
const EMOJI_SELECTED_DIVERSITY = "emojiSelectedDiversity"; const EMOJI_SELECTED_DIVERSITY = "emojiSelectedDiversity";
const EMOJI_CACHED_SECTIONS = "emojiCachedSections"; const EMOJI_CACHED_SECTIONS = "emojiCachedSections";
const PER_ROW = 11; const PER_ROW = 11;
@ -18,11 +17,10 @@ const customEmojis = _.map(_.keys(extendedEmojiList()), code => {
export function resetCache() { export function resetCache() {
keyValueStore.setObject({ key: EMOJI_CACHED_SECTIONS, value: [] }); keyValueStore.setObject({ key: EMOJI_CACHED_SECTIONS, value: [] });
keyValueStore.setObject({ key: EMOJI_USAGE, value: [] }); keyValueStore.setObject({ key: EMOJI_USAGE, value: [] });
keyValueStore.setObject({ key: EMOJI_SCROLL_Y, value: 0 });
keyValueStore.setObject({ key: EMOJI_SELECTED_DIVERSITY, value: 1 }); keyValueStore.setObject({ key: EMOJI_SELECTED_DIVERSITY, value: 1 });
} }
let $picker, $filter, $results, $list; let $picker, $filter, $results, $list, scrollPosition;
export default Ember.Component.extend({ export default Ember.Component.extend({
willDestroyElement() { willDestroyElement() {
@ -55,6 +53,8 @@ export default Ember.Component.extend({
// handle legacy format // handle legacy format
keyValueStore.setObject({ key: EMOJI_USAGE, value: _.keys(keyValueStore.getObject(EMOJI_USAGE)) }); keyValueStore.setObject({ key: EMOJI_USAGE, value: _.keys(keyValueStore.getObject(EMOJI_USAGE)) });
} }
scrollPosition = 0;
}, },
didUpdateAttrs() { didUpdateAttrs() {
@ -302,7 +302,7 @@ export default Ember.Component.extend({
_bindSectionsScroll() { _bindSectionsScroll() {
$list.on("scroll", () => { $list.on("scroll", () => {
Ember.run.debounce(this, this._checkVisibleSection, 150); 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) { _trackEmojiUsage(code) {
let recent = keyValueStore.getObject(EMOJI_USAGE) || []; let recent = keyValueStore.getObject(EMOJI_USAGE) || [];
recent = recent.filter(r => r !== code); recent = recent.filter(r => r !== code);
@ -521,7 +514,7 @@ export default Ember.Component.extend({
}, },
_scrollTo(y) { _scrollTo(y) {
const yPosition = _.isUndefined(y) ? keyValueStore.getObject(EMOJI_SCROLL_Y) : y; const yPosition = _.isUndefined(y) ? scrollPosition : y;
$list.scrollTop(yPosition); $list.scrollTop(yPosition);

View File

@ -167,20 +167,12 @@ QUnit.skip("emoji picker persists state", assert => {
click("button.emoji.btn"); click("button.emoji.btn");
andThen(() => { andThen(() => {
$('.emoji-picker .list').scrollTop(2600);
click('.emoji-picker a.diversity-scale.medium-dark'); click('.emoji-picker a.diversity-scale.medium-dark');
}); });
click("button.emoji.btn"); click("button.emoji.btn");
click("button.emoji.btn"); click("button.emoji.btn");
andThen(() => { andThen(() => {
assert.equal(
find('.emoji-picker .list').scrollTop() > 2500,
true,
"it stores scroll position"
);
assert.equal( assert.equal(
find('.emoji-picker .diversity-scale.medium-dark').hasClass('selected'), find('.emoji-picker .diversity-scale.medium-dark').hasClass('selected'),
true, true,