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: prevent course info bar overflow #1042

Merged
merged 5 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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 @@ -187,7 +187,9 @@ const CourseInfoBar = (props: CourseInfoBarProps) => {
void togglePopover(currentTarget);
}}
>
{`${deptCode} ${courseNumber} | ${courseTitle}`}
<span style={{ whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis' }}>
{`${deptCode} ${courseNumber} | ${courseTitle}`}
</span>
</Button>
<Popover
anchorEl={anchorEl}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { Button, Paper, Popper, useMediaQuery } from '@material-ui/core';
import { Button, Paper, Popper } from '@material-ui/core';
import { withStyles } from '@material-ui/core/styles';
import { ClassNameMap } from '@material-ui/core/styles/withStyles';
import { useEffect, useState } from 'react';

import { MOBILE_BREAKPOINT } from '../../../globals';

import { logAnalytics } from '$lib/analytics';
import { useScheduleManagementStore } from '$stores/ScheduleManagementStore';

const styles = {
button: {
Expand Down Expand Up @@ -34,7 +33,6 @@ function CourseInfoButton({
analyticsCategory,
}: CourseInfoButtonProps) {
const [popupAnchor, setPopupAnchor] = useState<HTMLElement | null>(null);
const isMobileScreen = useMediaQuery(`(max-width: ${MOBILE_BREAKPOINT})`);
const [isClicked, setIsClicked] = useState(false);

useEffect(() => {
Expand Down Expand Up @@ -65,11 +63,13 @@ function CourseInfoButton({
}
};

const scheduleManagementWidth = useScheduleManagementStore((state) => state.scheduleManagementWidth);
const compact = scheduleManagementWidth && scheduleManagementWidth < 600;

KevinWu098 marked this conversation as resolved.
Show resolved Hide resolved
return (
<div onMouseEnter={handleMouseEnter} onMouseLeave={handleMouseLeave} style={{ display: 'flex' }}>
<Button
className={classes.button}
startIcon={!isMobileScreen && icon}
variant="contained"
size="small"
onClick={(event: React.MouseEvent<HTMLElement>) => {
Expand All @@ -87,7 +87,20 @@ function CourseInfoButton({
}
}}
>
{text}
<span style={{ display: 'flex', gap: 4 }}>
{icon}
{!compact && (
KevinWu098 marked this conversation as resolved.
Show resolved Hide resolved
<span
style={{
whiteSpace: 'nowrap',
overflow: 'hidden',
textOverflow: 'ellipsis',
}}
>
{text}
</span>
)}
</span>
</Button>

{popupContent && (
Expand Down
21 changes: 21 additions & 0 deletions apps/antalmanac/src/components/SharedRoot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import loadingGif from './RightPane/CoursePane/SearchForm/Gifs/loading.gif';

import { CoursePaneRoot } from '$components/RightPane/CoursePane/CoursePaneRoot';
import { getLocalStorageUserId } from '$lib/localStorage';
import { useScheduleManagementStore } from '$stores/ScheduleManagementStore';
import { useThemeStore } from '$stores/SettingsStore';
import { useTabStore } from '$stores/TabStore';

Expand Down Expand Up @@ -221,6 +222,26 @@ export default function ScheduleManagement() {
*/
const ref = useRef<HTMLDivElement>();

const setScheduleManagementWidth = useScheduleManagementStore((state) => state.setScheduleManagementWidth);

useEffect(() => {
const element = ref.current;

if (!element) return;

const observer = new ResizeObserver(([entry]) => {
if (entry.contentRect) {
setScheduleManagementWidth(entry.contentRect.width);
}
});

observer.observe(element);

return () => {
observer.disconnect();
};
}, [setScheduleManagementWidth]);

const value = isMobile ? activeTab : activeTab - 1 >= 0 ? activeTab - 1 : 0;

// Save the current scroll position to the store.
Expand Down
3 changes: 1 addition & 2 deletions apps/antalmanac/src/stores/HoveredStore.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { AASection, ScheduleCourse } from '@packages/antalmanac-types';
import { CourseDetails } from '@packages/antalmanac-types';
import { AASection, ScheduleCourse, CourseDetails } from '@packages/antalmanac-types';
import { create } from 'zustand';

import { calendarizeCourseEvents, calendarizeFinals } from './calendarizeHelpers';
Expand Down
11 changes: 11 additions & 0 deletions apps/antalmanac/src/stores/ScheduleManagementStore.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { create } from 'zustand';

interface ScheduleManagementStore {
scheduleManagementWidth: number | null;
setScheduleManagementWidth: (width: number) => void;
}

export const useScheduleManagementStore = create<ScheduleManagementStore>((set) => ({
scheduleManagementWidth: null,
setScheduleManagementWidth: (width) => set({ scheduleManagementWidth: width }),
}));
Loading