Skip to content

Commit e07f298

Browse files
committed
🥅 Adds safty check when displayData undefined
- Fixes a NaN bug when `displayData.cols` was undefined - Resolves type error where `activeColCount` was being declared as a string but used as a number. - Also added some reactivity so it works when a window gets resized.
1 parent 7ff6141 commit e07f298

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

src/components/LinkItems/Section.vue

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ export default {
128128
widgets: Array,
129129
index: Number,
130130
isWide: Boolean,
131-
activeColCount: String,
131+
activeColCount: Number,
132132
},
133133
components: {
134134
Collapsable,
@@ -211,7 +211,9 @@ export default {
211211
return styles;
212212
},
213213
effectiveColsSpan() {
214-
return Math.min(this.activeColCount, this.displayData.cols);
214+
const { cols } = this.displayData;
215+
if (!cols) return cols;
216+
return Math.min(this.activeColCount, cols);
215217
},
216218
},
217219
methods: {

src/views/Home.vue

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ export default {
8585
layout: '',
8686
itemSizeBound: '',
8787
addNewSectionOpen: false,
88-
activeColCount: '1',
88+
activeColCount: 1,
8989
}),
9090
computed: {
9191
singleSectionView() {
@@ -179,8 +179,10 @@ export default {
179179
const { sectionsContainer } = this.$refs;
180180
if (!sectionsContainer) return;
181181
const cs = getComputedStyle(sectionsContainer);
182-
const varVal = cs.getPropertyValue('--col-count').trim();
183-
this.activeColCount = varVal;
182+
const varVal = parseInt(cs.getPropertyValue('--col-count'), 10);
183+
if (!Number.isNaN(varVal) && varVal > 0) {
184+
this.activeColCount = varVal;
185+
}
184186
},
185187
},
186188
mounted() {
@@ -189,6 +191,10 @@ export default {
189191
this.layout = this.layoutOrientation;
190192
this.itemSizeBound = this.iconSize;
191193
this.readActiveColCount();
194+
window.addEventListener('resize', this.readActiveColCount);
195+
},
196+
beforeDestroy() {
197+
window.removeEventListener('resize', this.readActiveColCount);
192198
},
193199
};
194200
</script>

0 commit comments

Comments
 (0)