chore: improve naming and explain fix in comment
All checks were successful
continuous-integration/drone/pr Build is passing

This commit is contained in:
Dominik Pschenitschni 2021-08-23 20:33:51 +02:00
parent 04c2877f42
commit 8e32d23bff
Signed by: dpschen
GPG Key ID: B257AC0149F43A77

View File

@ -78,9 +78,13 @@
class="more-container"
v-if="typeof listsVisible[n.id] !== 'undefined' ? listsVisible[n.id] : true"
>
<!--
NOTE: a v-model / computed setter is not possible, since the updateActiveLists function
triggered by the change needs to have access to the current namespace
-->
<draggable
:value="filteredLists[nk]"
@input="(lists) => updateFilteredLists(n, lists)"
:value="activeLists[nk]"
@input="(lists) => updateActiveLists(n, lists)"
:group="`namespace-${n.id}-lists`"
@start="() => drag = true"
@end="e => saveListPosition(e, nk)"
@ -96,7 +100,7 @@
class="menu-list can-be-hidden"
>
<li
v-for="l in filteredLists[nk]"
v-for="l in activeLists[nk]"
:key="l.id"
class="loader-container"
:class="{'is-loading': listUpdating[l.id]}"
@ -174,7 +178,7 @@ export default {
menuActive: MENU_ACTIVE,
loading: state => state[LOADING] && state[LOADING_MODULE] === 'namespaces',
}),
filteredLists() {
activeLists() {
return this.namespaces.map(({lists}) => lists.filter(item => !item.isArchived))
},
},
@ -215,7 +219,7 @@ export default {
toggleLists(namespaceId) {
this.$set(this.listsVisible, namespaceId, !this.listsVisible[namespaceId] ?? false)
},
updateFilteredLists(namespace, filteredLists) {
updateActiveLists(namespace, activeLists) {
// this is a bit hacky: since we do have to filter out the archived items from the list
// for vue draggable updating it is not as simple as replacing it.
// instead we iterate over the non archived items in the old list and replace them with the ones in their new order
@ -223,7 +227,7 @@ export default {
if (item.isArchived) {
return item
}
return filteredLists.shift()
return activeLists.shift()
})
const newNamespace = {
@ -234,10 +238,10 @@ export default {
this.$store.commit('namespaces/setNamespaceById', newNamespace)
},
saveListPosition(e, namespaceIndex) {
const listsFiltered = this.filteredLists[namespaceIndex]
const list = listsFiltered[e.newIndex]
const listBefore = listsFiltered[e.newIndex - 1] ?? null
const listAfter = listsFiltered[e.newIndex + 1] ?? null
const listsActive = this.activeLists[namespaceIndex]
const list = listsActive[e.newIndex]
const listBefore = listsActive[e.newIndex - 1] ?? null
const listAfter = listsActive[e.newIndex + 1] ?? null
this.$set(this.listUpdating, list.id, true)
const position = calculateItemPosition(listBefore !== null ? listBefore.position : null, listAfter !== null ? listAfter.position : null)