diff --git a/src/components/category.js b/src/components/category.js index 21255d7..bed2259 100644 --- a/src/components/category.js +++ b/src/components/category.js @@ -71,7 +71,7 @@ export default class Category extends React.Component { var { name, emojis, perLine } = this.props if (name == 'Recent') { - let frequentlyUsed = frequently.get(perLine * 4) + let frequentlyUsed = frequently.get(perLine) if (frequentlyUsed.length) { emojis = frequentlyUsed diff --git a/src/utils/frequently.js b/src/utils/frequently.js index 73692ef..f9b5721 100644 --- a/src/utils/frequently.js +++ b/src/utils/frequently.js @@ -1,10 +1,30 @@ import store from './store' -let frequently = store.get('frequently') || {} +const DEFAULTS = [ + '+1', + 'grinning', + 'kissing_heart', + 'heart_eyes', + 'laughing', + 'stuck_out_tongue_winking_eye', + 'sweat_smile', + 'joy', + 'scream', + 'disappointed', + 'unamused', + 'weary', + 'sob', + 'sunglasses', + 'heart', + 'poop', +] + +let frequently = store.get('frequently') function add(emoji) { var { id } = emoji + frequently || (frequently = {}) frequently[id] || (frequently[id] = 0) frequently[id] += 1 @@ -12,8 +32,17 @@ function add(emoji) { store.set('frequently', frequently) } -function get(quantity) { - var sorted = Object.keys(frequently).sort((a, b) => frequently[a] - frequently[b]).reverse(), +function get(perLine) { + if (!frequently) { + frequently = {} + + Array(perLine).fill('').forEach((_, i) => { + frequently[DEFAULTS[i]] = perLine - i + }) + } + + var quantity = perLine * 4, + sorted = Object.keys(frequently).sort((a, b) => frequently[a] - frequently[b]).reverse(), sliced = sorted.slice(0, quantity), last = store.get('last')