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
+10 -10
View File
@@ -1,19 +1,19 @@
<template>
<div class="library-list">
<div class="library-list-container" @click="onContainerClick">
<div v-for="(parents, char) in filteredNodes" :key="char">
<div v-for="([char, nodes]) in filteredNodes" :key="char">
<h3>{{ char }}</h3>
<div class="library-list-nodes-group">
<node-view
v-for="parent in parents" :key="parent.id"
:node="parent"
v-for="node in nodes" :key="char + '-' + node.id"
:node="node"
mode="card"
@click.native.capture="previewNode = parent"
:preview="previewNode === parent"
@click.native.capture="previewNode = node"
:preview="previewNode === node"
@open-node="$emit('open-node', $event)"
@open-child="$emit('open-node', { parentId: parent.id, ...$event })"
:style="`--opacity: ${getStrangenessOpacity(strangeness, parent)};`"
@open-child="$emit('open-node', { parentId: node.id, ...$event })"
:style="`--opacity: ${getStrangenessOpacity(strangeness, node)};`"
/>
</div>
</div>
@@ -46,14 +46,14 @@ export default {
filteredNodes () {
if (!this.orderedTextsDepart) return {}
const nodesGroups = {}
const nodesGroups = []
const search = this.search.toLowerCase()
Object.entries(this.orderedTextsDepart).forEach(([char, nodes]) => {
this.orderedTextsDepart.forEach(([char, nodes]) => {
const filteredNodes = nodes
.filter(node => tagsInNode(this.tags, node.tags))
.filter(node => searchInNode(search, node))
if (filteredNodes.length) {
nodesGroups[char] = filteredNodes
nodesGroups.push([char, filteredNodes])
}
})
return nodesGroups
+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