From b906bee2a5abe7e9e0b270d589a9c0ba5879ce55 Mon Sep 17 00:00:00 2001 From: Dominic Barnes Date: Sat, 30 Jun 2018 20:35:41 -0700 Subject: [PATCH] fix(catalog): fix date sorting via custom mapper We can remove this hack once https://github.com/kvnneff/sort-by/pull/10 lands. --- store/catalog.js | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/store/catalog.js b/store/catalog.js index b7464a8..031249c 100644 --- a/store/catalog.js +++ b/store/catalog.js @@ -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, @@ -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 @@ -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() +}