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 3 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: 20 additions & 1 deletion apps/antalmanac/src/routes/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import NotificationSnackbar from '$components/NotificationSnackbar';
import PatchNotes from '$components/PatchNotes';
import ScheduleManagement from '$components/SharedRoot';
import { Tutorial } from '$components/Tutorial';
import { useScheduleManagementStore } from '$stores/ScheduleManagementStore';

function MobileHome() {
return (
Expand All @@ -22,6 +23,23 @@ function MobileHome() {

function DesktopHome() {
const theme = useTheme();
const setScheduleManagementWidth = useScheduleManagementStore((state) => state.setScheduleManagementWidth);

const handleDrag = (sizes: number[]) => {
if (!window.innerWidth) {
return;
}

/**
* Sizes is a two element array containing the size of each side (in percentages)
*
* @example [25, 75]
*/
const [_, scheduleManagementPercentage] = sizes;
const scheduleManagementWidth = window.innerWidth * scheduleManagementPercentage * 0.01;

setScheduleManagementWidth(scheduleManagementWidth);
};

return (
<>
Expand All @@ -30,7 +48,7 @@ function DesktopHome() {

<Split
sizes={[45, 55]}
minSize={100}
minSize={400}
expandToMin={false}
gutterSize={10}
gutterAlign="center"
Expand All @@ -43,6 +61,7 @@ function DesktopHome() {
backgroundColor: theme.palette.primary.main,
width: '10px',
})}
onDrag={handleDrag}
>
<Stack direction="column">
<Calendar isMobile={false} />
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