Skip to content

Commit

Permalink
feat/Save Sidebar state in local storage
Browse files Browse the repository at this point in the history
Co-Authored-By: Thomas Schauer-Köckeis <[email protected]>
  • Loading branch information
sahibamittal and Gepardgame committed Oct 10, 2024
1 parent 274aa02 commit 553a2ae
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion src/containers/DefaultContainer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<div class="app">
<DefaultHeader />
<div class="app-body">
<AppSidebar fixed>
<AppSidebar ref="sidebar" fixed>
<SidebarHeader />
<SidebarForm />
<SidebarNav :navItems="permissibleNav"></SidebarNav>
Expand Down Expand Up @@ -60,6 +60,7 @@ export default {
},
data() {
return {
isSidebarMinimized: true,
breadcrumbs: [],
nav: [
{
Expand Down Expand Up @@ -168,6 +169,12 @@ export default {
};
},
methods: {
handleMinimizedUpdate() {
this.isSidebarMinimized = !this.isSidebarMinimized;
if (localStorage) {
localStorage.setItem('isSidebarMinimized', this.isSidebarMinimized);
}
},
generateBreadcrumbs: function generateBreadcrumbs(
crumbName,
subSectionName,
Expand Down Expand Up @@ -204,6 +211,28 @@ export default {
mounted() {
if (this.$dtrack && this.$dtrack.version.includes('SNAPSHOT')) {
this.$root.$emit('bv::show::modal', 'snapshotModal');
this.isSidebarMinimized =
localStorage && localStorage.getItem('isSidebarMinimized') !== null
? localStorage.getItem('isSidebarMinimized') === 'true'
: false;
const sidebar = document.body;
if (sidebar) {
if (this.isSidebarMinimized) {
sidebar.classList.add('sidebar-minimized');
} else {
sidebar.classList.remove('sidebar-minimized');
}
}
this.$nextTick(() => {
const sidebarMinimizer = this.$el.querySelector('.sidebar-minimizer');
if (sidebarMinimizer) {
sidebarMinimizer.addEventListener(
'click',
this.handleMinimizedUpdate,
);
}
});
}
},
computed: {
Expand Down

0 comments on commit 553a2ae

Please sign in to comment.