Skip to content

Commit

Permalink
fix(catalog): fix date sorting via custom mapper
Browse files Browse the repository at this point in the history
We can remove this hack once kvnneff/sort-by#10
lands.
  • Loading branch information
dominicbarnes committed Jul 1, 2018
1 parent 7550fbd commit b906bee
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions store/catalog.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const getters = {
return {
added: hoodie.createdAt && moment(hoodie.createdAt).toDate(),
attackIV: attackIV,
caught: moment(catalog.caughtAt).toDate(),
caught: catalog.caughtAt && moment(catalog.caughtAt).toDate(),
chargeMove: catalog && movesByID(catalog.chargeMove),
cp: calculateCP(catalog, metadata, multiplier),
defenseIV: defenseIV,
Expand Down Expand Up @@ -88,12 +88,12 @@ const getters = {
},
sorter (state) {
switch (state.sortBy) {
case 'recent': return sortBy('-caught', '-added')
case 'dex': return sortBy('dex', '-cp')
case 'name': return sortBy('name', '-cp')
case 'cp': return sortBy('-cp')
case 'ivs': return sortBy('-ivs', '-added')
case 'level': return sortBy('-level', '-cp')
case 'recent': return sortBy('-caught', '-added', sortMapper)
case 'dex': return sortBy('dex', '-cp', sortMapper)
case 'name': return sortBy('name', '-cp', sortMapper)
case 'cp': return sortBy('-cp', sortMapper)
case 'ivs': return sortBy('-ivs', '-added', sortMapper)
case 'level': return sortBy('-level', '-cp', sortMapper)
default:
console.warn('catalog: unrecognized sort by', state.sortBy)
return null
Expand Down Expand Up @@ -216,3 +216,9 @@ function nextEvolutions ({ pokemonByID, itemsByID }, list) {
}
})
}

// this helper function will only be necessary until kvnneff/sort-by#10 lands
// @see https://github.com/kvnneff/sort-by/pull/10
function sortMapper (key, value) {
return value.valueOf()
}

0 comments on commit b906bee

Please sign in to comment.