Skip to content

Commit

Permalink
Save sidebar state per session (#1619)
Browse files Browse the repository at this point in the history
Only restore close state.
Sidebar will still auto close on window resize.
  • Loading branch information
cw789 authored Oct 19, 2022
1 parent 787b3ad commit 31e8d69
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 persistentSessionState = sessionStorage.getItem('sidebar_state')
// set default for closed state only, so sidebar will still auto close on window resize
if (persistentSessionState === '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 31e8d69

Please sign in to comment.