diff options
| author | Jules Laplace <julescarbon@gmail.com> | 2020-07-16 18:55:00 +0200 |
|---|---|---|
| committer | Jules Laplace <julescarbon@gmail.com> | 2020-07-16 18:55:00 +0200 |
| commit | dc35755748ee05abde3f3eda585d12df732e38ae (patch) | |
| tree | 2752d2ee3560db6ce23a8dc572d59fdcdbdb6fce /animism-align/frontend/util/index.js | |
| parent | e2e27ed91b8ed8a024223ad03be9d2566750e880 (diff) | |
properly sort media
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)) } |
