diff --git a/assets/js/app.js b/assets/js/app.js index b7168c4..de3f154 100644 --- a/assets/js/app.js +++ b/assets/js/app.js @@ -86,6 +86,16 @@ Hooks.SidebarState = { this.setSidebarState(!current) } }, + + updated() { + // LiveView patches data-sidebar-expanded back to the template default ("true") + // on every DOM update. Re-apply the stored state from localStorage after each patch. + const expanded = localStorage.getItem('sidebar-expanded') !== 'false' + const current = this.el.dataset.sidebarExpanded === 'true' + if (current !== expanded) { + this.setSidebarState(expanded) + } + }, setSidebarState(expanded) { // Convert boolean to string for consistency