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 }">
<ul>
<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"
>
<dot-button
@@ -21,7 +21,7 @@
<script>
import { mapGetters } from 'vuex'
import { orderByVariant } from '@/helpers/common'
export default {
name: 'NodeViewChildList',
@@ -37,7 +37,11 @@ export default {
},
computed: {
...mapGetters(['activeNodes'])
...mapGetters(['activeNodes']),
orderedChildren () {
return orderByVariant(this.children)
}
},
methods: {
@@ -3,7 +3,7 @@
<b-collapse :id="'collapse-child-list-' + id" v-model="visible">
<b-list-group>
<b-list-group-item
v-for="child in children" :key="child.id"
v-for="child in orderedChildren" :key="child.id"
:variant="child.variant"
href="javascript:;"
@click="$parent.$emit('open-child', { childId: child.id })"
@@ -28,6 +28,8 @@
</template>
<script>
import { orderByVariant } from '@/helpers/common'
export default {
name: 'NodeViewChildListGroup',
@@ -40,6 +42,12 @@ export default {
return {
visible: window.innerWidth > 769
}
},
computed: {
orderedChildren () {
return orderByVariant(this.children)
}
}
}
</script>
+15
View File
@@ -9,6 +9,21 @@ export function toCommaList (arr, key = 'name') {
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) {
let j, x, i