Skip to content

Commit

Permalink
Merge pull request #64 from JustinDrake/patch-1
Browse files Browse the repository at this point in the history
Add default frequently used defaults (closes #63)
  • Loading branch information
EtienneLem authored Apr 24, 2017
2 parents bf3f8f8 + 46cf754 commit 84e0f68
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/components/category.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
35 changes: 32 additions & 3 deletions src/utils/frequently.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,48 @@
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

store.set('last', id)
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')

Expand Down

0 comments on commit 84e0f68

Please sign in to comment.