Skip to content

Commit

Permalink
feat/Sidebar state in local storage Used LocalStorage to store the ex…
Browse files Browse the repository at this point in the history
…panded state of the sidebar, so it persists over sessions

Signed-off-by: Thomas Schauer-Köckeis <[email protected]>
  • Loading branch information
Gepardgame committed Sep 11, 2024
1 parent 441d3c4 commit 10fcb16
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 @@ -150,6 +151,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 @@ -186,6 +193,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 10fcb16

Please sign in to comment.