From 5735b330be100b5d0ea8faea73bd1d5b29dfa217 Mon Sep 17 00:00:00 2001 From: axolotle Date: Mon, 15 Mar 2021 10:03:31 +0100 Subject: [PATCH] add CardList cards & add temp ordered text by authors getter --- src/pages/library/CardList.vue | 46 ++++++++++++++++++++++++++++++++-- src/store/modules/texts.js | 17 +++++++++++++ 2 files changed, 61 insertions(+), 2 deletions(-) diff --git a/src/pages/library/CardList.vue b/src/pages/library/CardList.vue index a11ea33..178256d 100644 --- a/src/pages/library/CardList.vue +++ b/src/pages/library/CardList.vue @@ -1,12 +1,54 @@ diff --git a/src/store/modules/texts.js b/src/store/modules/texts.js index e3c2918..3d72216 100644 --- a/src/store/modules/texts.js +++ b/src/store/modules/texts.js @@ -58,6 +58,23 @@ export default { value: id, text: `(${id}) ${title}` })) + }, + + orderedParents: state => { + // FIXME duplicates references if multiple authors ? + if (!state.textsDepart) return undefined + return state.textsDepart.sort((a, b) => { + if (!b.authors) return -1 + if (!a.authors) return +1 + if (a.authors[0].name < b.authors[0].name) return -1 + if (a.authors[0].name > b.authors[0].name) return 1 + return 0 + }).reduce((dict, text) => { + const firstChar = text.authors ? text.authors[0].name[0] : '&' + if (!(firstChar in dict)) dict[firstChar] = [] + dict[firstChar].push(text) + return dict + }, {}) } } }