mirror of
https://github.com/Lissy93/dashy.git
synced 2025-07-26 15:14:22 +02:00
🐛 Fix collapse state persistence (#1546)
This commit is contained in:
parent
1bbb91b3fe
commit
4594c99b57
@ -64,7 +64,6 @@ export default {
|
|||||||
return this.$store.state.editMode;
|
return this.$store.state.editMode;
|
||||||
},
|
},
|
||||||
sectionKey() {
|
sectionKey() {
|
||||||
if (this.isEditMode) return undefined;
|
|
||||||
return `collapsible-${this.uniqueKey}`;
|
return `collapsible-${this.uniqueKey}`;
|
||||||
},
|
},
|
||||||
collapseClass() {
|
collapseClass() {
|
||||||
@ -104,12 +103,23 @@ export default {
|
|||||||
watch: {
|
watch: {
|
||||||
checkboxState(newState) {
|
checkboxState(newState) {
|
||||||
this.isExpanded = newState;
|
this.isExpanded = newState;
|
||||||
|
this.updateLocalStorage(); // Save every change immediately
|
||||||
},
|
},
|
||||||
uniqueKey() {
|
uniqueKey(newVal, oldVal) {
|
||||||
this.checkboxState = this.isExpanded;
|
if (newVal !== oldVal) {
|
||||||
|
this.refreshCollapseState(); // Refresh state when key changes
|
||||||
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
refreshCollapseState() {
|
||||||
|
this.checkboxState = this.isExpanded;
|
||||||
|
},
|
||||||
|
updateLocalStorage() {
|
||||||
|
const collapseState = this.locallyStoredCollapseStates();
|
||||||
|
collapseState[this.uniqueKey] = this.checkboxState;
|
||||||
|
localStorage.setItem(localStorageKeys.COLLAPSE_STATE, JSON.stringify(collapseState));
|
||||||
|
},
|
||||||
/* Either expand or collapse section, based on it's current state */
|
/* Either expand or collapse section, based on it's current state */
|
||||||
toggle() {
|
toggle() {
|
||||||
this.checkboxState = !this.checkboxState;
|
this.checkboxState = !this.checkboxState;
|
||||||
|
@ -28,7 +28,7 @@ const HomeMixin = {
|
|||||||
return this.$store.state.modalOpen;
|
return this.$store.state.modalOpen;
|
||||||
},
|
},
|
||||||
pageId() {
|
pageId() {
|
||||||
return (this.subPageInfo && this.subPageInfo.pageId) ? this.subPageInfo.pageId : 'home';
|
return this.$store.state.currentConfigInfo?.confId || 'home';
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
data: () => ({
|
data: () => ({
|
||||||
@ -84,6 +84,14 @@ const HomeMixin = {
|
|||||||
searching(searchValue) {
|
searching(searchValue) {
|
||||||
this.searchValue = searchValue || '';
|
this.searchValue = searchValue || '';
|
||||||
},
|
},
|
||||||
|
/* Returns a unique ID based on the page and section name */
|
||||||
|
makeSectionId(section) {
|
||||||
|
const normalize = (str) => (
|
||||||
|
str ? str.trim().toLowerCase().replace(/[^a-zA-Z0-9]/g, '-')
|
||||||
|
: `unnamed-${(`000${Math.floor(Math.random() * 1000)}`).slice(-3)}`
|
||||||
|
);
|
||||||
|
return `${this.pageId || 'unknown-page'}-${normalize(section.name)}`;
|
||||||
|
},
|
||||||
/* Returns true if there is one or more sections in the config */
|
/* Returns true if there is one or more sections in the config */
|
||||||
checkTheresData(sections) {
|
checkTheresData(sections) {
|
||||||
const localSections = localStorage[localStorageKeys.CONF_SECTIONS];
|
const localSections = localStorage[localStorageKeys.CONF_SECTIONS];
|
||||||
|
@ -34,7 +34,7 @@
|
|||||||
:title="section.name"
|
:title="section.name"
|
||||||
:icon="section.icon || undefined"
|
:icon="section.icon || undefined"
|
||||||
:displayData="getDisplayData(section)"
|
:displayData="getDisplayData(section)"
|
||||||
:groupId="`${pageId}-section-${index}`"
|
:groupId="makeSectionId(section)"
|
||||||
:items="section.filteredItems"
|
:items="section.filteredItems"
|
||||||
:widgets="section.widgets"
|
:widgets="section.widgets"
|
||||||
:searchTerm="searchValue"
|
:searchTerm="searchValue"
|
||||||
|
@ -34,7 +34,7 @@
|
|||||||
:index="index"
|
:index="index"
|
||||||
:title="section.name"
|
:title="section.name"
|
||||||
:icon="section.icon || undefined"
|
:icon="section.icon || undefined"
|
||||||
:groupId="`section-${index}`"
|
:groupId="makeSectionId(section)"
|
||||||
:items="filterTiles(section.items)"
|
:items="filterTiles(section.items)"
|
||||||
:widgets="section.widgets"
|
:widgets="section.widgets"
|
||||||
:selected="selectedSection === index"
|
:selected="selectedSection === index"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user