Skip to content

Commit f69d24d

Browse files
committed
refactor: resolve feedback points
1 parent 32b2b11 commit f69d24d

38 files changed

Lines changed: 4201 additions & 204 deletions

package-lock.json

Lines changed: 4166 additions & 162 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/courseware/course/sequence/lock-paywall/LockPaywall.jsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,15 @@ const LockPaywall = ({
3737

3838
// the following variables are set and used for responsive layout to work with
3939
// whether any sidebar panel is open and if there's an offer with longer text
40-
const upgradePanelVisible = availableSidebarIds.includes(currentSidebar);
40+
const isSidebarOpen = availableSidebarIds.includes(currentSidebar);
4141
const { width: windowWidth } = useWindowSize();
4242
const shouldDisplayBulletPointsBelowCertificate = windowWidth <= breakpoints.large.minWidth;
4343
const shouldDisplayGatedContentOneColumn = windowWidth <= breakpoints.extraLarge.minWidth
44-
&& upgradePanelVisible;
44+
&& isSidebarOpen;
4545
const shouldDisplayGatedContentTwoColumns = windowWidth < breakpoints.large.minWidth
46-
&& upgradePanelVisible;
46+
&& isSidebarOpen;
4747
const shouldDisplayGatedContentTwoColumnsHalf = windowWidth <= breakpoints.large.minWidth
48-
&& !upgradePanelVisible;
48+
&& !isSidebarOpen;
4949
const shouldWrapTextOnButton = windowWidth > breakpoints.extraSmall.minWidth;
5050

5151
const accessExpirationDate = accessExpiration ? new Date(accessExpiration.expirationDate) : null;
@@ -98,7 +98,7 @@ const LockPaywall = ({
9898
</div>
9999
)}
100100

101-
<div className={classNames('d-inline-flex flex-row', { 'flex-wrap': upgradePanelVisible || shouldDisplayBulletPointsBelowCertificate })}>
101+
<div className={classNames('d-inline-flex flex-row', { 'flex-wrap': isSidebarOpen || shouldDisplayBulletPointsBelowCertificate })}>
102102
<div style={{ float: 'left' }} className="mr-3 mb-2">
103103
<img
104104
alt={intl.formatMessage(messages['learn.lockPaywall.example.alt'])}
@@ -128,7 +128,7 @@ const LockPaywall = ({
128128
<div
129129
className={
130130
classNames('d-md-flex align-items-md-center text-right', {
131-
'col-md-5 mx-md-0': upgradePanelVisible, 'col-md-4 mx-md-3 justify-content-center': !upgradePanelVisible && !shouldDisplayGatedContentTwoColumnsHalf, 'col-md-11 justify-content-end': shouldDisplayGatedContentOneColumn && !shouldDisplayGatedContentTwoColumns, 'col-md-6 justify-content-center': shouldDisplayGatedContentTwoColumnsHalf,
131+
'col-md-5 mx-md-0': isSidebarOpen, 'col-md-4 mx-md-3 justify-content-center': !isSidebarOpen && !shouldDisplayGatedContentTwoColumnsHalf, 'col-md-11 justify-content-end': shouldDisplayGatedContentOneColumn && !shouldDisplayGatedContentTwoColumns, 'col-md-6 justify-content-center': shouldDisplayGatedContentTwoColumnsHalf,
132132
})
133133
}
134134
>

src/courseware/course/sequence/sequence-navigation/SequenceNavigation.jsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ const SequenceNavigation = ({
4141
sequence.gatedContent !== undefined && sequence.gatedContent.gated
4242
) : undefined;
4343

44-
const shouldDisplayUpgradeTriggerInSequence = useWindowSize().width < breakpoints.small.minWidth;
44+
const isSmallScreen = useWindowSize().width < breakpoints.small.minWidth;
4545

4646
const renderUnitButtons = () => {
4747
if (isLocked) {
@@ -71,7 +71,7 @@ const SequenceNavigation = ({
7171
onClick={previousHandler}
7272
previousLink={previousLink}
7373
isFirstUnit={isFirstUnit}
74-
buttonLabel={shouldDisplayUpgradeTriggerInSequence ? null : intl.formatMessage(messages.previousButton)}
74+
buttonLabel={isSmallScreen ? null : intl.formatMessage(messages.previousButton)}
7575
/>
7676
);
7777

@@ -82,7 +82,7 @@ const SequenceNavigation = ({
8282

8383
if (isLastUnit && exitText) {
8484
buttonText = exitText;
85-
} else if (!shouldDisplayUpgradeTriggerInSequence) {
85+
} else if (!isSmallScreen) {
8686
buttonText = intl.formatMessage(messages.nextButton);
8787
}
8888
return navigationDisabledNextSequence || (
@@ -101,7 +101,7 @@ const SequenceNavigation = ({
101101
};
102102

103103
return sequenceStatus === LOADED ? (
104-
<nav id="courseware-sequence-navigation" data-testid="courseware-sequence-navigation" className={classNames('sequence-navigation', className, { 'mr-2': shouldDisplayUpgradeTriggerInSequence })}>
104+
<nav id="courseware-sequence-navigation" data-testid="courseware-sequence-navigation" className={classNames('sequence-navigation', className, { 'mr-2': isSmallScreen })}>
105105
{renderPreviousButton()}
106106
{renderUnitButtons()}
107107
{renderNextButton()}

src/courseware/course/sidebar/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44

55
The sidebar uses a pluggable widget framework that allows instances to customize which panels appear in the course sidebar.
66

7-
Widget implementations live in [`src/widgets/`](../../../widgets/):
7+
Widget implementations:
88

9-
- **[discussions](../../../widgets/discussions/README.md)** — built-in right-panel; always enabled
10-
- **[course-outline](../../../widgets/course-outline/README.md)** — built-in left-panel
9+
- **[discussions](../../../widgets/discussions/README.md)** — built-in right-panel; always enabled (in `src/widgets/`)
10+
- **[course-outline](sidebars/course-outline/README.md)** — built-in left-panel (in `sidebar/sidebars/`)
1111

1212
## Architecture
1313

src/courseware/course/sidebar/SidebarContextProvider.jsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ const SidebarProvider = ({
109109
unitId,
110110
shouldDisplayFullScreen,
111111
hasUserToggledRef,
112-
previousUnitIdRef,
113112
courseOutlineSetByUnitRef,
114113
});
115114

src/courseware/course/sidebar/SidebarTriggers.jsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const SidebarTriggers = () => {
77
const {
88
toggleSidebar,
99
currentSidebar,
10+
availableSidebarIds,
1011
SIDEBAR_ORDER,
1112
SIDEBARS,
1213
} = useContext(SidebarContext);
@@ -20,7 +21,7 @@ const SidebarTriggers = () => {
2021

2122
return (
2223
<div className="d-flex ml-auto">
23-
{SIDEBAR_ORDER.map((sidebarId) => {
24+
{SIDEBAR_ORDER.filter(id => availableSidebarIds.includes(id)).map((sidebarId) => {
2425
const { Trigger } = SIDEBARS[sidebarId];
2526
const isActive = sidebarId === currentSidebar;
2627
return (

src/courseware/course/sidebar/SidebarTriggers.test.jsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ function buildContext(overrides = {}) {
3939
return {
4040
toggleSidebar: mockToggleSidebar,
4141
currentSidebar: null,
42+
availableSidebarIds: ['WIDGET_A', 'WIDGET_B'],
4243
SIDEBAR_ORDER: ['WIDGET_A', 'WIDGET_B'],
4344
SIDEBARS: {
4445
WIDGET_A: { Trigger: MockTriggerA },
@@ -160,6 +161,7 @@ describe('SidebarTriggers - external widget integration', () => {
160161
<SidebarContext.Provider value={{
161162
toggleSidebar: jest.fn(),
162163
currentSidebar: null,
164+
availableSidebarIds: SIDEBAR_ORDER,
163165
SIDEBARS,
164166
SIDEBAR_ORDER,
165167
}}
@@ -193,6 +195,7 @@ describe('SidebarTriggers - external widget integration', () => {
193195
<SidebarContext.Provider value={{
194196
toggleSidebar: jest.fn(),
195197
currentSidebar: null,
198+
availableSidebarIds: SIDEBAR_ORDER,
196199
SIDEBARS,
197200
SIDEBAR_ORDER,
198201
}}
@@ -230,6 +233,7 @@ describe('SidebarTriggers - external widget integration', () => {
230233
<SidebarContext.Provider value={{
231234
toggleSidebar,
232235
currentSidebar: null,
236+
availableSidebarIds: SIDEBAR_ORDER,
233237
SIDEBARS,
234238
SIDEBAR_ORDER,
235239
}}

src/courseware/course/sidebar/hooks/useSidebarSync.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import {
2020
* @param {string} params.unitId - Current unit ID
2121
* @param {boolean} params.shouldDisplayFullScreen - Whether in mobile view
2222
* @param {Function} params.hasUserToggledRef - Ref tracking user manual toggles
23-
* @param {Function} params.previousUnitIdRef - Ref tracking previous unit ID
2423
* @param {Function} params.courseOutlineSetByUnitRef - Ref tracking COURSE_OUTLINE auto-set
2524
*/
2625
export function useSidebarSync({
@@ -31,12 +30,11 @@ export function useSidebarSync({
3130
unitId,
3231
shouldDisplayFullScreen,
3332
hasUserToggledRef,
34-
previousUnitIdRef,
3533
courseOutlineSetByUnitRef,
3634
}) {
3735
useEffect(() => {
38-
// Skip if on mobile or if unit shift effect hasn't run yet
39-
if (shouldDisplayFullScreen || previousUnitIdRef.current === null) {
36+
// Skip if on mobile
37+
if (shouldDisplayFullScreen) {
4038
return;
4139
}
4240

src/courseware/course/sidebar/hooks/useSidebarSync.test.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ function buildParams(overrides = {}) {
2121
unitId,
2222
shouldDisplayFullScreen: false,
2323
hasUserToggledRef: { current: false },
24-
previousUnitIdRef: { current: unitId }, // non-null = post-initial-load
2524
courseOutlineSetByUnitRef: { current: null },
2625
...overrides,
2726
};
@@ -41,13 +40,6 @@ describe('useSidebarSync', () => {
4140
expect(params.setCurrentSidebar).not.toHaveBeenCalled();
4241
});
4342

44-
it('skips when previousUnitIdRef is null (initial page load)', () => {
45-
const params = buildParams({ previousUnitIdRef: { current: null } });
46-
renderHook(() => useSidebarSync(params));
47-
48-
expect(params.setCurrentSidebar).not.toHaveBeenCalled();
49-
});
50-
5143
it('skips when user has manually toggled the sidebar', () => {
5244
const params = buildParams({ hasUserToggledRef: { current: true } });
5345
renderHook(() => useSidebarSync(params));

src/courseware/course/sidebar/hooks/useUnitShiftBehavior.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,7 @@ export function useUnitShiftBehavior({
120120
setCurrentSidebar(firstAvailable);
121121
setSidebarId(courseId, firstAvailable);
122122
} else if (currentWidget) {
123-
// Current RIGHT sidebar panel still available and no higher priority - keep it
124-
setCurrentSidebar(currentSidebar);
123+
// Current sidebar still valid at same priority — no state change needed
125124
} else {
126125
// Current panel not available - switch to first available RIGHT sidebar panel
127126
setCurrentSidebar(firstAvailable);

0 commit comments

Comments
 (0)