fix(bug-2): isCollapsed as plain reactive property — getters unreliable in Alpine stores
parent
d3ad4b4740
commit
fe257ef75b
|
|
@ -63,10 +63,14 @@ document.addEventListener('alpine:init', () => {
|
||||||
mobileOpen: false,
|
mobileOpen: false,
|
||||||
collapsed: localStorage.getItem('sidebarCollapsed') === 'true',
|
collapsed: localStorage.getItem('sidebarCollapsed') === 'true',
|
||||||
isMobile: window.innerWidth < 768,
|
isMobile: window.innerWidth < 768,
|
||||||
get isCollapsed() { return this.collapsed && ! this.isMobile; },
|
isCollapsed: false,
|
||||||
init() {
|
init() {
|
||||||
|
this.isCollapsed = this.collapsed && ! this.isMobile;
|
||||||
this._syncDataset();
|
this._syncDataset();
|
||||||
window.addEventListener('resize', () => { this.isMobile = window.innerWidth < 768; });
|
window.addEventListener('resize', () => {
|
||||||
|
this.isMobile = window.innerWidth < 768;
|
||||||
|
this.isCollapsed = this.collapsed && ! this.isMobile;
|
||||||
|
});
|
||||||
},
|
},
|
||||||
_syncDataset() {
|
_syncDataset() {
|
||||||
if (this.collapsed) {
|
if (this.collapsed) {
|
||||||
|
|
@ -77,6 +81,7 @@ document.addEventListener('alpine:init', () => {
|
||||||
},
|
},
|
||||||
toggle() {
|
toggle() {
|
||||||
this.collapsed = ! this.collapsed;
|
this.collapsed = ! this.collapsed;
|
||||||
|
this.isCollapsed = this.collapsed && ! this.isMobile;
|
||||||
localStorage.setItem('sidebarCollapsed', this.collapsed);
|
localStorage.setItem('sidebarCollapsed', this.collapsed);
|
||||||
this._syncDataset();
|
this._syncDataset();
|
||||||
window.dispatchEvent(new CustomEvent('sidebar-toggled', { detail: { collapsed: this.collapsed } }));
|
window.dispatchEvent(new CustomEvent('sidebar-toggled', { detail: { collapsed: this.collapsed } }));
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue