Merge pull request #64 from JustinDrake/patch-1

Add default frequently used defaults (closes #63)
release
Etienne Lemay 2017-04-23 22:32:34 -04:00 committed by GitHub
commit 84e0f68e76
2 changed files with 33 additions and 4 deletions

View File

@ -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

View File

@ -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')