Skip to content

Commit

Permalink
Save sidebar state per session (#1606)
Browse files Browse the repository at this point in the history
Means sidebar stays open or close if you navigate.
For example using previous / next page navigation.
  • Loading branch information
cw789 authored Sep 16, 2022
1 parent 7d400e5 commit dd4f391
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions assets/js/sidebar/sidebar-drawer.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ export function initialize () {
}

function setDefaultSidebarState () {
// check & set persistent session state
const persistenSessionState = sessionStorage.getItem('sidebar_state')
if (persistenSessionState === 'opened') return setClass(SIDEBAR_CLASS.opened)
if (persistenSessionState === 'closed') return setClass(SIDEBAR_CLASS.closed)

// else
setClass(isScreenSmall() ? SIDEBAR_CLASS.closed : SIDEBAR_CLASS.opened)
}

Expand Down Expand Up @@ -98,6 +104,7 @@ function isSidebarOpen () {
export function openSidebar () {
clearTimeoutIfAny()
setClass(SIDEBAR_CLASS.opening)
sessionStorage.setItem('sidebar_state', 'opened')

return new Promise((resolve, reject) => {
state.togglingTimeout = setTimeout(() => {
Expand All @@ -115,6 +122,7 @@ export function openSidebar () {
export function closeSidebar () {
clearTimeoutIfAny()
setClass(SIDEBAR_CLASS.closing)
sessionStorage.setItem('sidebar_state', 'closed')

return new Promise((resolve, reject) => {
state.togglingTimeout = setTimeout(() => {
Expand Down

0 comments on commit dd4f391

Please sign in to comment.