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,
|
||||
collapsed: localStorage.getItem('sidebarCollapsed') === 'true',
|
||||
isMobile: window.innerWidth < 768,
|
||||
get isCollapsed() { return this.collapsed && ! this.isMobile; },
|
||||
isCollapsed: false,
|
||||
init() {
|
||||
this.isCollapsed = this.collapsed && ! this.isMobile;
|
||||
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() {
|
||||
if (this.collapsed) {
|
||||
|
|
@ -77,6 +81,7 @@ document.addEventListener('alpine:init', () => {
|
|||
},
|
||||
toggle() {
|
||||
this.collapsed = ! this.collapsed;
|
||||
this.isCollapsed = this.collapsed && ! this.isMobile;
|
||||
localStorage.setItem('sidebarCollapsed', this.collapsed);
|
||||
this._syncDataset();
|
||||
window.dispatchEvent(new CustomEvent('sidebar-toggled', { detail: { collapsed: this.collapsed } }));
|
||||
|
|
|
|||
Loading…
Reference in New Issue