Skip to content

Commit

Permalink
chore: update sidebar logic
Browse files Browse the repository at this point in the history
  • Loading branch information
leangseu-edx committed Nov 20, 2023
1 parent 748e73d commit f493a52
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
8 changes: 7 additions & 1 deletion src/courseware/course/sidebar/SidebarContextProvider.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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]);

Expand Down
5 changes: 1 addition & 4 deletions src/data/sessionStorage.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit f493a52

Please sign in to comment.