Skip to content

Commit 2f7fe59

Browse files
committed
recursively checks for nested children for badges
1 parent ff79a10 commit 2f7fe59

File tree

1 file changed

+28
-6
lines changed
  • src/components/left-sidebar/ComponentTab

1 file changed

+28
-6
lines changed

src/components/left-sidebar/ComponentTab/Icons.vue

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,8 @@ Description:
66

77
<template>
88
<section class="icon-grid">
9-
<button
10-
@click.prevent="changeState(elementName)"
11-
v-for="([elementName, iconString], idx) in Object.entries(icons)"
12-
:key="idx + Date.now()"
13-
>
9+
<button @click.prevent="changeState(elementName)" v-for="([elementName, iconString], idx) in Object.entries(icons)"
10+
:key="idx + Date.now()">
1411
<span class="badge"> {{ elementStorage[elementName] }}</span>
1512
<br />
1613
<i :class="iconString"></i>
@@ -41,13 +38,33 @@ export default {
4138
elementStorage: function () {
4239
let computedElementalStorage = {};
4340
if (this.activeComponent) {
41+
4442
this.componentMap[this.activeComponent].htmlList.forEach((el) => {
4543
if (!computedElementalStorage[el.text]) {
4644
computedElementalStorage[el.text] = 1;
47-
} else {
45+
}
46+
else if (computedElementalStorage[el.text]) {
4847
computedElementalStorage[el.text] += 1;
4948
}
5049
});
50+
//show the badge for all nested children arrays
51+
const checkChild = array => {
52+
for (let html of array) {
53+
console.log(html)
54+
if (html.children.length) {
55+
checkChild(html.children)
56+
} else {
57+
if (!computedElementalStorage[html.text]) {
58+
computedElementalStorage[html.text] = 1
59+
} else {
60+
++computedElementalStorage[html.text]
61+
}
62+
}
63+
}
64+
}
65+
//invoke the recursive function
66+
checkChild(this.componentMap[this.activeComponent].htmlList)
67+
5168
} else if (this.activeComponent === "") {
5269
// if component was switched from existing component to '', reset cache and update items
5370
if (computedElementalStorage !== {}) computedElementalStorage = {};
@@ -104,23 +121,28 @@ export default {
104121
width: 100%;
105122
}
106123
}
124+
107125
button {
108126
background: none;
109127
color: $menutext;
110128
border: none;
111129
}
130+
112131
button:hover {
113132
cursor: pointer;
114133
color: $secondary;
115134
}
135+
116136
button:focus {
117137
outline: none;
118138
color: $secondary;
119139
}
140+
120141
button:active {
121142
box-shadow: 0 5px inherit;
122143
transform: translateY(4px);
123144
}
145+
124146
.badge {
125147
width: 15px;
126148
line-height: 15px;

0 commit comments

Comments
 (0)