Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fixed width issues of old and new sidebar #1374

Merged
merged 1 commit into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@ const DiscussionsNotificationsSidebar = () => {
const { hideNotificationbar } = useContext(SidebarContext);

return (
<div className="sticky-top vh-100">
<SidebarBase
ariaLabel={intl.formatMessage(messages.discussionNotificationTray)}
sidebarId={ID}
className="d-flex flex-column flex-fill"
showTitleBar={false}
showBorder={false}
>
<SidebarBase
ariaLabel={intl.formatMessage(messages.discussionNotificationTray)}
sidebarId={ID}
className="d-flex flex-column flex-fill"
showTitleBar={false}
showBorder={false}
>
<div className="sticky-top vh-100">
<NotificationTray />
{!hideNotificationbar && <div className="my-1.5" />}
<DiscussionsSidebar />
</SidebarBase>
</div>
</div>
</SidebarBase>
);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import classNames from 'classnames';
import UnitButton from './UnitButton';
import SequenceNavigationDropdown from './SequenceNavigationDropdown';
import useIndexOfLastVisibleChild from '../../../../generic/tabs/useIndexOfLastVisibleChild';
import { useIsOnXLDesktop, useIsSidebarOpen } from './hooks';
import {
useIsOnXLDesktop, useIsOnMediumDesktop, useIsOnLargeDesktop, useIsSidebarOpen,
} from './hooks';

const SequenceNavigationTabs = ({
unitIds, unitId, showCompletion, onNavigate,
Expand All @@ -15,21 +17,28 @@ const SequenceNavigationTabs = ({
indexOfLastVisibleChild,
containerRef,
invisibleStyle,
] = useIndexOfLastVisibleChild();
] = useIndexOfLastVisibleChild(isSidebarOpen);
const isOnXLDesktop = useIsOnXLDesktop();
const shouldDisplayDropdown = indexOfLastVisibleChild === -1;
const isOnLargeDesktop = useIsOnLargeDesktop();
const isOnMediumDesktop = useIsOnMediumDesktop();
const shouldDisplayDropdown = indexOfLastVisibleChild === -1 || indexOfLastVisibleChild < unitIds.length - 1;

return (
<div style={{ flexBasis: '100%', minWidth: 0 }}>
<div
style={{ flexBasis: '100%', minWidth: 0 }}
className={classNames({
'navigation-tab-width-xl': isOnXLDesktop && isSidebarOpen,
'navigation-tab-width-large': isOnLargeDesktop && isSidebarOpen,
'navigation-tab-width-medium': isOnMediumDesktop && isSidebarOpen,
})}
>
<div
ref={containerRef}
className={classNames('sequence-navigation-tabs-container', {
'navigation-tab-width': isOnXLDesktop && isSidebarOpen,
})}
className="sequence-navigation-tabs-container"
>
<div
className="sequence-navigation-tabs d-flex flex-grow-1"
style={shouldDisplayDropdown ? invisibleStyle : null}
ref={containerRef}
>
{unitIds.map(buttonUnitId => (
<UnitButton
Expand Down
14 changes: 12 additions & 2 deletions src/courseware/course/sequence/sequence-navigation/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,19 @@ export function useSequenceNavigationMetadata(currentSequenceId, currentUnitId)
};
}

export function useIsOnMediumDesktop() {
const windowSize = useWindowSize();
return windowSize.width >= breakpoints.medium.minWidth && windowSize.width < breakpoints.extraLarge.minWidth;
}

export function useIsOnLargeDesktop() {
const windowSize = useWindowSize();
return windowSize.width >= breakpoints.extraLarge.minWidth && windowSize.width < breakpoints.extraLarge.maxWidth;
}

export function useIsOnXLDesktop() {
const windowSize = useWindowSize();
return windowSize.width >= breakpoints.extraLarge.minWidth;
return windowSize.width >= breakpoints.extraLarge.maxWidth;
}

export function useIsSidebarOpen(unitId) {
Expand All @@ -84,6 +94,6 @@ export function useIsSidebarOpen(unitId) {
const { currentSidebar } = useContext(isNewDiscussionSidebarViewEnabled ? NewSidebarContext : SidebarContext);
const topic = useModel('discussionTopics', unitId);

return (currentSidebar === WIDGETS.NOTIFICATIONS) || (
return (currentSidebar === WIDGETS.NOTIFICATIONS) || (currentSidebar === 'DISCUSSIONS_NOTIFICATIONS') || (
currentSidebar === WIDGETS.DISCUSSIONS && !!(topic?.id || topic?.enabledInContext));
}
4 changes: 2 additions & 2 deletions src/generic/tabs/useIndexOfLastVisibleChild.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const invisibleStyle = {
* included when determining which children will fit or not. Usage of this ref
* is optional.
*/
export default function useIndexOfLastVisibleChild() {
export default function useIndexOfLastVisibleChild(isSidebarOpen) {
const containerElementRef = useRef(null);
const overflowElementRef = useRef(null);
const containingRectRef = useRef({});
Expand Down Expand Up @@ -72,7 +72,7 @@ export default function useIndexOfLastVisibleChild() {

setIndexOfLastVisibleChild(nextIndexOfLastVisibleChild);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [windowSize, containerElementRef.current]);
}, [windowSize, containerElementRef.current, isSidebarOpen]);

return [indexOfLastVisibleChild, containerElementRef, invisibleStyle, overflowElementRef];
}
12 changes: 10 additions & 2 deletions src/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,16 @@
}
}

.navigation-tab-width {
max-width: 46rem;
.navigation-tab-width-xl {
max-width: 47rem;
}

.navigation-tab-width-large {
max-width: 28rem;
}

.navigation-tab-width-medium{
max-width: 23.5rem;
}

.sequence-navigation-dropdown {
Expand Down
Loading