Skip to content

Commit e2b9c15

Browse files
committed
🐛 Fixes collapsible sections (#626)
1 parent 333ee83 commit e2b9c15

File tree

2 files changed

+31
-34
lines changed

2 files changed

+31
-34
lines changed

src/components/LinkItems/Collapsable.vue

+30-33
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
<template>
22
<div
3-
:class="`collapsable ${rowColSpanClass} ${collapseClass} ${!cutToHeight ? 'full-height' : ''}`"
3+
v-bind:class="[
4+
{ 'is-open': isExpanded, 'full-height': cutToHeight },
5+
`collapsable ${rowColSpanClass}`
6+
]"
47
:style="`${color ? 'background: '+color : ''}; ${sanitizeCustomStyles(customStyles)};`"
58
>
69
<input
@@ -72,12 +75,32 @@ export default {
7275
const { rows, cols, checkSpanNum } = this;
7376
return `${checkSpanNum(cols, 'col')} ${checkSpanNum(rows, 'row')}`;
7477
},
78+
isExpanded: {
79+
// getter
80+
get() {
81+
if (this.collapsed !== undefined) return !this.collapsed;
82+
const collapseStateObject = this.initialiseStorage(); // Check local storage
83+
if (collapseStateObject[this.uniqueKey] !== undefined) {
84+
return collapseStateObject[this.uniqueKey];
85+
}
86+
return true; // Nothing specified, return Open
87+
},
88+
// setter
89+
set(newState) {
90+
// Get the current localstorage collapse state object
91+
const collapseState = JSON.parse(localStorage[localStorageKeys.COLLAPSE_STATE]);
92+
// Add the new state to it
93+
collapseState[this.uniqueKey] = newState;
94+
// Stringify, and set the new object into local storage
95+
localStorage.setItem(localStorageKeys.COLLAPSE_STATE, JSON.stringify(collapseState));
96+
},
97+
},
7598
},
7699
data: () => ({
77-
isExpanded: false,
100+
// isExpanded: false,
78101
}),
79102
mounted() {
80-
this.isExpanded = this.getCollapseState();
103+
// this.isExpanded = this.getCollapseState();
81104
},
82105
methods: {
83106
/* Check that row & column span is valid, and not over the max */
@@ -93,43 +116,17 @@ export default {
93116
},
94117
/* Returns local storage collapse state data, and if not yet set then initialized is */
95118
initialiseStorage() {
96-
const storageKey = localStorageKeys.COLLAPSE_STATE;
97-
/* Initialize function will create and set a blank object to storage */
98-
const initStorage = () => localStorage.setItem(storageKey, JSON.stringify({}));
99119
// If not yet set, then call initialize
100-
if (!localStorage[storageKey]) {
101-
initStorage();
120+
if (!localStorage[localStorageKeys.COLLAPSE_STATE]) {
121+
localStorage.setItem(localStorageKeys.COLLAPSE_STATE, JSON.stringify({}));
102122
return {};
103123
}
104124
// Otherwise, return value of local storage
105-
return JSON.parse(localStorage[storageKey]);
106-
},
107-
/* If specified by user, return conf collapse state, otherwise check local storage */
108-
getCollapseState() {
109-
if (this.collapsed !== undefined) return !this.collapsed; // Check users config
110-
const collapseStateObject = this.initialiseStorage(); // Check local storage
111-
if (collapseStateObject[this.uniqueKey] !== undefined) {
112-
return collapseStateObject[this.uniqueKey];
113-
}
114-
// Nothing specified, return Open
115-
return true;
125+
return JSON.parse(localStorage[localStorageKeys.COLLAPSE_STATE]);
116126
},
117-
/* When section collapsed, update local storage, to remember for next time */
118-
setCollapseState(id, newState) {
119-
// Get the current localstorage collapse state object
120-
const collapseState = JSON.parse(localStorage[localStorageKeys.COLLAPSE_STATE]);
121-
// Add the new state to it
122-
collapseState[id] = newState;
123-
// Stringify, and set the new object into local storage
124-
localStorage.setItem(localStorageKeys.COLLAPSE_STATE, JSON.stringify(collapseState));
125-
},
126-
/* Called when collapse state changes, trigger local storage update if needed */
127+
// /* Called when collapse state changes, trigger local storage update if needed */
127128
collapseChanged(whatChanged) {
128129
this.isExpanded = whatChanged.srcElement.checked;
129-
if (this.collapseState === undefined) { // Only run, if user hasn't manually set prop
130-
this.initialiseStorage();
131-
this.setCollapseState(this.uniqueKey.toString(), this.isExpanded);
132-
}
133130
},
134131
openEditModal() {
135132
this.$emit('openEditSection');

src/mixins/WidgetMixin.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const WidgetMixin = {
2020
overrideUpdateInterval: null,
2121
disableLoader: false, // Prevent ever showing the loader
2222
updater: null, // Stores interval
23-
defaultTimeout: 1000,
23+
defaultTimeout: 10000,
2424
}),
2525
/* When component mounted, fetch initial data */
2626
mounted() {

0 commit comments

Comments
 (0)