diff options
Diffstat (limited to 'animism-align/frontend/util/index.js')
| -rw-r--r-- | animism-align/frontend/util/index.js | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/animism-align/frontend/util/index.js b/animism-align/frontend/util/index.js index 37369f0..3567429 100644 --- a/animism-align/frontend/util/index.js +++ b/animism-align/frontend/util/index.js @@ -299,12 +299,20 @@ export const orderByFn = (s='name asc') => { case 'priority': mapFn = a => [parseInt(a.priority) || parseInt(a.id) || 1000, a] sortFn = numericSort[direction] + break case 'title': mapFn = a => [a.title || "", a] sortFn = stringSort[direction] + break case 'author': - mapFn = a => [a.author || "", a] + mapFn = a => { + let author = (a.author || "").split(' and ')[0].split(' ') + author.unshift(author.pop()) + author = author.join(' ') + return [author, a] + } sortFn = stringSort[direction] + break case 'name': default: mapFn = a => [a.name || "", a] @@ -313,7 +321,10 @@ export const orderByFn = (s='name asc') => { } return { mapFn, sortFn } } -export const getOrderedIds = (objects, sort, prepend=[]) => { +export const getOrderedIds = (objects, sort, prepend) => { + if (!prepend) { + prepend = [] + } const { mapFn, sortFn } = orderByFn(sort) return prepend.concat(objects.map(mapFn).sort(sortFn).map(a => a[1].id)) } |
