dupplicates nodes for multiple authors in LibraryList

This commit is contained in:
axolotle
2021-06-29 14:07:13 +02:00
parent edbb45878d
commit e65ee2fcb8
2 changed files with 32 additions and 22 deletions
+22 -12
View File
@@ -229,18 +229,28 @@ export default {
orderedTextsDepart: (state, getters, rootState) => {
const departIds = rootState.ids.depart
if (departIds === undefined || rootState.nodes[departIds[0]] === undefined) return
return rootState.ids.depart.map(id => rootState.nodes[id]).sort((a, b) => {
if (!b.authors) return -1
if (!a.authors) return +1
if (a.authors[0].last_name < b.authors[0].last_name) return -1
if (a.authors[0].last_name > b.authors[0].last_name) return 1
return 0
}).reduce((dict, text) => {
const firstChar = text.authors ? text.authors[0].last_name[0].toUpperCase() : '~'
if (!(firstChar in dict)) dict[firstChar] = []
dict[firstChar].push(text)
return dict
}, {})
const nodesDict = {}
for (const node of rootState.ids.depart.map(id => rootState.nodes[id])) {
if (!node.authors) {
if (!('~' in nodesDict)) nodesDict['~'] = []
nodesDict['~'].push(node)
} else {
node.authors.forEach((author, i) => {
const firstChar = author.last_name[0].toUpperCase()
if (!(firstChar in nodesDict)) nodesDict[firstChar] = []
nodesDict[firstChar].push({ last_name: author.last_name, node })
})
}
}
return Object.entries(nodesDict).sort((a, b) => a[0] < b[0] ? -1 : 1).map(group => {
if (group[0] === '~') return group
return [group[0], group[1].sort((a, b) => {
const prev = a.last_name.toLowerCase()
const next = b.last_name.toLowerCase()
if (prev === next) return 0
return prev < next ? -1 : 1
}).map(node => node.node)]
})
},
// LibraryTree