Update default frequently used

nolan/hinaloe-test
Etienne Lemay 2017-04-24 04:27:21 +02:00
parent 956fb94656
commit 46cf7542c3
2 changed files with 31 additions and 16 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,24 +1,30 @@
import store from './store'
const increment = 1000000000
let defaults = {
"heart": 1 * increment,
"smile": 2 * increment,
"disappointed": 3 * increment,
"grinning": 4 * increment,
"slightly_smiling_face": 5 * increment,
"+1": 6 * increment
}
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')
if(!frequently) {
store.set('frequently', defaults)
frequently = defaults
}
function add(emoji) {
var { id } = emoji
frequently || (frequently = {})
frequently[id] || (frequently[id] = 0)
frequently[id] += 1
@ -26,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')