From f493a5203b2f9b6d82d2b32c1df3d2cabd681d07 Mon Sep 17 00:00:00 2001 From: Leangseu Kim Date: Fri, 17 Nov 2023 12:13:42 -0500 Subject: [PATCH] chore: update sidebar logic --- src/courseware/course/sidebar/SidebarContextProvider.jsx | 8 +++++++- src/data/sessionStorage.js | 5 +---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/courseware/course/sidebar/SidebarContextProvider.jsx b/src/courseware/course/sidebar/SidebarContextProvider.jsx index b61c577b19..3d4a703745 100644 --- a/src/courseware/course/sidebar/SidebarContextProvider.jsx +++ b/src/courseware/course/sidebar/SidebarContextProvider.jsx @@ -22,7 +22,13 @@ const SidebarProvider = ({ const [upgradeNotificationCurrentState, setUpgradeNotificationCurrentState] = useState(getLocalStorage(`upgradeNotificationCurrentState.${courseId}`)); useEffect(() => { - setCurrentSidebar(SIDEBARS.DISCUSSIONS.ID); + // if the user left the tray open in the previous session, open it again + // if the user is not verified, open the tray iff the previous session was open and the user on large screen + const openBySession = getSessionStorage(`notificationTrayStatus.${courseId}`) !== 'closed'; + const showNotificationsOnLoad = openBySession || (!!verifiedMode && shouldDisplaySidebarOpen && openBySession ); + if (showNotificationsOnLoad) { + setCurrentSidebar(SIDEBARS.NOTIFICATIONS.ID); + } // eslint-disable-next-line react-hooks/exhaustive-deps }, [unitId]); diff --git a/src/data/sessionStorage.js b/src/data/sessionStorage.js index fe86b577d0..9e98077baa 100644 --- a/src/data/sessionStorage.js +++ b/src/data/sessionStorage.js @@ -7,10 +7,7 @@ function getSessionStorage(key) { try { if (global.sessionStorage) { - const rawItem = global.sessionStorage.getItem(key); - if (rawItem) { - return JSON.parse(rawItem); - } + return global.sessionStorage.getItem(key); } } catch (e) { // If this fails for some reason, just return null.