Skip to content

Commit

Permalink
refactor:fixed naming convention and combine useeffects
Browse files Browse the repository at this point in the history
  • Loading branch information
sundasnoreen12 committed Dec 27, 2023
1 parent fe36b0d commit 30812ac
Show file tree
Hide file tree
Showing 14 changed files with 46 additions and 78 deletions.
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,4 @@ TWITTER_HASHTAG=''
TWITTER_URL=''
USER_INFO_COOKIE_NAME=''
OPTIMIZELY_FULL_STACK_SDK_KEY=''
ENABLE_SIDEBAR_NEW_VIEW='false'
ENABLE_NEW_SIDEBAR='false'
6 changes: 3 additions & 3 deletions src/courseware/course/Course.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const Course = ({
} = useModel('courseHomeMeta', courseId);
const sequence = useModel('sequences', sequenceId);
const section = useModel('sections', sequence ? sequence.sectionId : null);
const showSidebarNewView = getConfig().ENABLE_SIDEBAR_NEW_VIEW;
const showNewSidebar = getConfig().ENABLE_NEW_SIDEBAR;

const pageTitleBreadCrumbs = [
sequence,
Expand Down Expand Up @@ -67,7 +67,7 @@ const Course = ({
));
}, [sequenceId]);

const SidebarProviderComponent = showSidebarNewView === 'true' ? NewSidebarProvider : SidebarProvider;
const SidebarProviderComponent = showNewSidebar === 'true' ? NewSidebarProvider : SidebarProvider;

return (
<SidebarProviderComponent courseId={courseId} unitId={unitId}>
Expand All @@ -91,7 +91,7 @@ const Course = ({
courseId={courseId}
contentToolsEnabled={course.showCalculator || course.notes.enabled}
/>
{ showSidebarNewView === 'true' ? <NewSidebarTriggers /> : <SidebarTriggers /> }
{ showNewSidebar === 'true' ? <NewSidebarTriggers /> : <SidebarTriggers /> }
</>
)}
</div>
Expand Down
41 changes: 0 additions & 41 deletions src/courseware/course/new-sidebar/NewSidebarIcon.jsx

This file was deleted.

9 changes: 1 addition & 8 deletions src/courseware/course/new-sidebar/SidebarContextProvider.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,26 +37,19 @@ const SidebarProvider = ({
setIsDiscussionbarAvailable(true);
setHideDiscussionbar(false);

Check warning on line 38 in src/courseware/course/new-sidebar/SidebarContextProvider.jsx

View check run for this annotation

Codecov / codecov/patch

src/courseware/course/new-sidebar/SidebarContextProvider.jsx#L34-L38

Added lines #L34 - L38 were not covered by tests
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [topic]);

useEffect(() => {
if (isEmpty(verifiedMode)) {
setIsNotificationbarAvailable(false);
setHideNotificationbar(true);
} else {
setIsNotificationbarAvailable(true);
setHideNotificationbar(false);

Check warning on line 46 in src/courseware/course/new-sidebar/SidebarContextProvider.jsx

View check run for this annotation

Codecov / codecov/patch

src/courseware/course/new-sidebar/SidebarContextProvider.jsx#L42-L46

Added lines #L42 - L46 were not covered by tests
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [verifiedMode]);

useEffect(() => {
setCurrentSidebar(SidebarID);

Check warning on line 49 in src/courseware/course/new-sidebar/SidebarContextProvider.jsx

View check run for this annotation

Codecov / codecov/patch

src/courseware/course/new-sidebar/SidebarContextProvider.jsx#L49

Added line #L49 was not covered by tests
if (isDiscussionbarAvailable) { setHideDiscussionbar(false); } else { setHideDiscussionbar(true); }
if (isNotificationbarAvailable) { setHideNotificationbar(false); } else { setHideNotificationbar(true); }
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [unitId, isDiscussionbarAvailable, isNotificationbarAvailable]);
}, [unitId, topic, verifiedMode, isDiscussionbarAvailable, isNotificationbarAvailable]);

const onNotificationSeen = useCallback(() => {
setNotificationStatus('inactive');
Expand Down
23 changes: 23 additions & 0 deletions src/courseware/course/new-sidebar/SidebarIcon.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { useIntl } from '@edx/frontend-platform/i18n';
import { Icon } from '@edx/paragon';
import React, { useContext } from 'react';
import { RightSidebarFilled, RightSidebarOutlined } from './icons';
import SidebarContext from './SidebarContext';
import messages from '../messages';

const SidebarIcon = () => {
const intl = useIntl();
const { currentSidebar } = useContext(SidebarContext);

Check warning on line 10 in src/courseware/course/new-sidebar/SidebarIcon.jsx

View check run for this annotation

Codecov / codecov/patch

src/courseware/course/new-sidebar/SidebarIcon.jsx#L9-L10

Added lines #L9 - L10 were not covered by tests

return (

Check warning on line 12 in src/courseware/course/new-sidebar/SidebarIcon.jsx

View check run for this annotation

Codecov / codecov/patch

src/courseware/course/new-sidebar/SidebarIcon.jsx#L12

Added line #L12 was not covered by tests
<Icon
src={currentSidebar ? RightSidebarFilled : RightSidebarOutlined}
className="m-0 m-auto"
alt={intl.formatMessage(messages.openNotificationTrigger)}
/>
);
};

SidebarIcon.propTypes = { };

export default SidebarIcon;
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { injectIntl, intlShape } from '@edx/frontend-platform/i18n';
import { useIntl } from '@edx/frontend-platform/i18n';
import PropTypes from 'prop-types';
import React, { useContext, useEffect, useMemo } from 'react';
import { useDispatch } from 'react-redux';
Expand All @@ -10,12 +10,9 @@ import SidebarTriggerBase from './common/TriggerBase';
import SidebarContext from './SidebarContext';
import { useModel } from '../../../generic/model-store';
import { getCourseDiscussionTopics } from '../../data/thunks';
import NewSidebarIcon from './NewSidebarIcon';
import SidebarIcon from './SidebarIcon';

const NewSideBarTrigger = ({
intl,
onClick,
}) => {
const SideBarTrigger = ({ onClick }) => {
const {
courseId,
notificationStatus,
Expand All @@ -26,6 +23,7 @@ const NewSideBarTrigger = ({
} = useContext(SidebarContext);

Check warning on line 23 in src/courseware/course/new-sidebar/SidebarTrigger.jsx

View check run for this annotation

Codecov / codecov/patch

src/courseware/course/new-sidebar/SidebarTrigger.jsx#L23

Added line #L23 was not covered by tests

const dispatch = useDispatch();
const intl = useIntl();
const { tabs } = useModel('courseHomeMeta', courseId);
const baseUrl = getConfig().DISCUSSIONS_MFE_BASE_URL;
const edxProvider = useMemo(
Expand Down Expand Up @@ -78,14 +76,13 @@ const NewSideBarTrigger = ({

return (

Check warning on line 77 in src/courseware/course/new-sidebar/SidebarTrigger.jsx

View check run for this annotation

Codecov / codecov/patch

src/courseware/course/new-sidebar/SidebarTrigger.jsx#L77

Added line #L77 was not covered by tests
<SidebarTriggerBase onClick={handleClick} ariaLabel={intl.formatMessage(messages.openSidebarTrigger)}>
<NewSidebarIcon status={notificationStatus} sidebarColor="bg-danger-500" />
<SidebarIcon status={notificationStatus} />
</SidebarTriggerBase>
);
};

NewSideBarTrigger.propTypes = {
intl: intlShape.isRequired,
SideBarTrigger.propTypes = {
onClick: PropTypes.func.isRequired,
};

export default injectIntl(NewSideBarTrigger);
export default SideBarTrigger;
4 changes: 2 additions & 2 deletions src/courseware/course/new-sidebar/SidebarTriggers.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import classNames from 'classnames';
import React, { useContext } from 'react';
import SidebarContext from './SidebarContext';
import NewSidebarTrigger from './NewSidebarTrigger';
import SidebarTrigger from './SidebarTrigger';
import { SidebarID } from './constants';

const SidebarTriggers = () => {
Expand All @@ -17,7 +17,7 @@ const SidebarTriggers = () => {
style={{ borderBottom: isActive ? '2px solid' : null }}
key={SidebarID}
>
<NewSidebarTrigger onClick={() => toggleSidebar(SidebarID)} key={SidebarID} />
<SidebarTrigger onClick={() => toggleSidebar(SidebarID)} key={SidebarID} />

Check warning on line 20 in src/courseware/course/new-sidebar/SidebarTriggers.jsx

View check run for this annotation

Codecov / codecov/patch

src/courseware/course/new-sidebar/SidebarTriggers.jsx#L20

Added line #L20 was not covered by tests
</div>
</div>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';

const SvgRightSidebarFilled = (props) => (
const RightSidebarFilled = (props) => (
<svg

Check warning on line 4 in src/courseware/course/new-sidebar/icons/RightSidebarFilled.jsx

View check run for this annotation

Codecov / codecov/patch

src/courseware/course/new-sidebar/icons/RightSidebarFilled.jsx#L4

Added line #L4 was not covered by tests
width={24}
height={24}
Expand All @@ -17,4 +17,4 @@ const SvgRightSidebarFilled = (props) => (
/>
</svg>
);
export default SvgRightSidebarFilled;
export default RightSidebarFilled;
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';

const SvgRightSidebarOutlined = (props) => (
const RightSidebarOutlined = (props) => (
<svg

Check warning on line 4 in src/courseware/course/new-sidebar/icons/RightSidebarOutlined.jsx

View check run for this annotation

Codecov / codecov/patch

src/courseware/course/new-sidebar/icons/RightSidebarOutlined.jsx#L4

Added line #L4 was not covered by tests
width={24}
height={24}
Expand All @@ -17,4 +17,4 @@ const SvgRightSidebarOutlined = (props) => (
/>
</svg>
);
export default SvgRightSidebarOutlined;
export default RightSidebarOutlined;
4 changes: 2 additions & 2 deletions src/courseware/course/new-sidebar/icons/index.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export { default as RightSidebarFilled } from './SvgRightSidebarFilled';
export { default as RightSidebarOutlined } from './SvgRightSidebarOutlined';
export { default as RightSidebarFilled } from './RightSidebarFilled';
export { default as RightSidebarOutlined } from './RightSidebarOutlined';
2 changes: 1 addition & 1 deletion src/courseware/course/sequence/Sequence.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const Sequence = ({
const sequenceStatus = useSelector(state => state.courseware.sequenceStatus);
const sequenceMightBeUnit = useSelector(state => state.courseware.sequenceMightBeUnit);
const shouldDisplayNotificationTriggerInSequence = useWindowSize().width < breakpoints.small.minWidth;
const showSidebarNewView = getConfig().ENABLE_SIDEBAR_NEW_VIEW;
const showSidebarNewView = getConfig().ENABLE_NEW_SIDEBAR;

const handleNext = () => {
const nextIndex = sequence.unitIds.indexOf(unitId) + 1;
Expand Down
2 changes: 1 addition & 1 deletion src/generic/upgrade-notification/UpgradeNotification.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ const UpgradeNotification = ({
iconAs={Icon}
onClick={() => toggleSidebar(sidebarId, tabId)}

Check warning on line 504 in src/generic/upgrade-notification/UpgradeNotification.jsx

View check run for this annotation

Codecov / codecov/patch

src/generic/upgrade-notification/UpgradeNotification.jsx#L504

Added line #L504 was not covered by tests
variant="light"
className="text-black"
className="text-primary-500"
/>
</div>
)}
Expand Down
4 changes: 0 additions & 4 deletions src/generic/upgrade-notification/UpgradeNotification.scss
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,3 @@
.font-size-18 {
font-size: 18px !important;
}

.text-black {
color: black !important
}
2 changes: 1 addition & 1 deletion src/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ initialize({
PROCTORED_EXAM_RULES_URL: process.env.PROCTORED_EXAM_RULES_URL || null,
CHAT_RESPONSE_URL: process.env.CHAT_RESPONSE_URL || null,
PRIVACY_POLICY_URL: process.env.PRIVACY_POLICY_URL || null,
ENABLE_SIDEBAR_NEW_VIEW: process.env.ENABLE_SIDEBAR_NEW_VIEW || false,
ENABLE_NEW_SIDEBAR: process.env.ENABLE_NEW_SIDEBAR || false,
}, 'LearnerAppConfig');
},
},
Expand Down

0 comments on commit 30812ac

Please sign in to comment.