Skip to content

Commit

Permalink
Merge pull request #988 from Gepardgame/feat/Navigation-sidebar-state…
Browse files Browse the repository at this point in the history
…-not-retained-between-sessions

feat/Save Sidebar state in local storage
  • Loading branch information
nscuro authored Sep 11, 2024
2 parents 441d3c4 + 10fcb16 commit 1e5f3b9
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 1e5f3b9

Please sign in to comment.