Skip to content

Commit

Permalink
chore: make notification display by default
Browse files Browse the repository at this point in the history
  • Loading branch information
leangseu-edx committed Nov 9, 2023
1 parent 308f03c commit 1a1b4a6
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 14 deletions.
12 changes: 0 additions & 12 deletions src/courseware/course/Course.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import SidebarProvider from './sidebar/SidebarContextProvider';
import SidebarTriggers from './sidebar/SidebarTriggers';

import { useModel } from '../../generic/model-store';
import { getSessionStorage, setSessionStorage } from '../../data/sessionStorage';

const Course = ({
courseId,
Expand All @@ -32,7 +31,6 @@ const Course = ({
const {
celebrations,
isStaff,
verifiedMode,
} = useModel('courseHomeMeta', courseId);
const sequence = useModel('sequences', sequenceId);
const section = useModel('sections', sequence ? sequence.sectionId : null);
Expand All @@ -55,16 +53,6 @@ const Course = ({
const shouldDisplayTriggers = windowWidth >= breakpoints.small.minWidth;
const daysPerWeek = course?.courseGoals?.selectedGoal?.daysPerWeek;

// 1. open the notification tray if the user has not purchased the course and is on a desktop
// 2. default to close on the first time access
// 3. use the last state if the user has access the course before
const shouldDisplayNotificationTrayOpenOnLoad = windowWidth > breakpoints.medium.minWidth && !!verifiedMode;
if (shouldDisplayNotificationTrayOpenOnLoad) {
setSessionStorage(`notificationTrayStatus.${courseId}`, 'open');
} else if (!getSessionStorage(`notificationTrayStatus.${courseId}`)) {
setSessionStorage(`notificationTrayStatus.${courseId}`, 'closed');
}

useEffect(() => {
const celebrateFirstSection = celebrations && celebrations.firstSection;
setFirstSectionCelebrationOpen(shouldCelebrateOnSectionLoad(
Expand Down
11 changes: 10 additions & 1 deletion src/courseware/course/sidebar/SidebarContextProvider.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import React, {
useEffect, useState, useMemo, useCallback,
} from 'react';

import { useModel } from '../../../generic/model-store';
import { getLocalStorage, setLocalStorage } from '../../../data/localStorage';
import { getSessionStorage } from '../../../data/sessionStorage';

import SidebarContext from './SidebarContext';
import { SIDEBARS } from './sidebars';

Expand All @@ -13,6 +16,8 @@ const SidebarProvider = ({
unitId,
children,
}) => {
const { verifiedMode } = useModel('courseHomeMeta', courseId);

const shouldDisplayFullScreen = useWindowSize().width < breakpoints.large.minWidth;
const shouldDisplaySidebarOpen = useWindowSize().width > breakpoints.medium.minWidth;
const query = new URLSearchParams(window.location.search);
Expand All @@ -22,7 +27,11 @@ const SidebarProvider = ({
const [upgradeNotificationCurrentState, setUpgradeNotificationCurrentState] = useState(getLocalStorage(`upgradeNotificationCurrentState.${courseId}`));

useEffect(() => {
setCurrentSidebar(SIDEBARS.DISCUSSIONS.ID);
// if the user has not purchased the course or previously opened the notification tray, show the notification tray
const showNotificationsOnLoad = !!verifiedMode || getSessionStorage(`notificationTrayStatus.${courseId}`) !== 'closed';
if (showNotificationsOnLoad) {
setCurrentSidebar(SIDEBARS.NOTIFICATIONS.ID);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [unitId]);

Expand Down
2 changes: 1 addition & 1 deletion src/data/sessionStorage.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function getSessionStorage(key) {
function setSessionStorage(key, value) {
try {
if (global.sessionStorage) {
global.sessionStorage.setItem(key, JSON.stringify(value));
global.sessionStorage.setItem(key, value);
}
} catch (e) {
// If this fails, just bail.
Expand Down

0 comments on commit 1a1b4a6

Please sign in to comment.