reorder children by text type

This commit is contained in:
axolotle
2022-05-27 20:56:16 +02:00
parent 0f7ed99ab3
commit c027c3a8f6
3 changed files with 31 additions and 4 deletions
+7 -3
View File
@@ -2,7 +2,7 @@
<nav class="node-view-child-list" :class="{ 'smartphone': smartphone }"> <nav class="node-view-child-list" :class="{ 'smartphone': smartphone }">
<ul> <ul>
<li <li
v-for="(child, i) in children" :key="child.id" v-for="(child, i) in orderedChildren" :key="child.id"
class="node-view-child-list-item" class="node-view-child-list-item"
> >
<dot-button <dot-button
@@ -21,7 +21,7 @@
<script> <script>
import { mapGetters } from 'vuex' import { mapGetters } from 'vuex'
import { orderByVariant } from '@/helpers/common'
export default { export default {
name: 'NodeViewChildList', name: 'NodeViewChildList',
@@ -37,7 +37,11 @@ export default {
}, },
computed: { computed: {
...mapGetters(['activeNodes']) ...mapGetters(['activeNodes']),
orderedChildren () {
return orderByVariant(this.children)
}
}, },
methods: { methods: {
@@ -3,7 +3,7 @@
<b-collapse :id="'collapse-child-list-' + id" v-model="visible"> <b-collapse :id="'collapse-child-list-' + id" v-model="visible">
<b-list-group> <b-list-group>
<b-list-group-item <b-list-group-item
v-for="child in children" :key="child.id" v-for="child in orderedChildren" :key="child.id"
:variant="child.variant" :variant="child.variant"
href="javascript:;" href="javascript:;"
@click="$parent.$emit('open-child', { childId: child.id })" @click="$parent.$emit('open-child', { childId: child.id })"
@@ -28,6 +28,8 @@
</template> </template>
<script> <script>
import { orderByVariant } from '@/helpers/common'
export default { export default {
name: 'NodeViewChildListGroup', name: 'NodeViewChildListGroup',
@@ -40,6 +42,12 @@ export default {
return { return {
visible: window.innerWidth > 769 visible: window.innerWidth > 769
} }
},
computed: {
orderedChildren () {
return orderByVariant(this.children)
}
} }
} }
</script> </script>
+15
View File
@@ -9,6 +9,21 @@ export function toCommaList (arr, key = 'name') {
return arr.map(item => item[key]).join(', ') return arr.map(item => item[key]).join(', ')
} }
export function orderByVariant (arr) {
const orderedVariants = [
'lecture',
'reflexion',
'critique',
'sensible',
'echo',
'kit',
'creation'
]
return [...arr].sort((a, b) => {
return orderedVariants.indexOf(a.variant) > orderedVariants.indexOf(b.variant)
})
}
export function shuffle (a) { export function shuffle (a) {
let j, x, i let j, x, i