Skip to content

Commit

Permalink
feat: handle resizes
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinWu098 committed Nov 21, 2024
1 parent 2acf533 commit c790cac
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions apps/antalmanac/src/routes/Home.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import DateFnsUtils from '@date-io/date-fns';
import { MuiPickersUtilsProvider } from '@material-ui/pickers';
import { CssBaseline, useMediaQuery, useTheme, Stack } from '@mui/material';
import { useRef } from 'react';
import { useCallback, useEffect, useRef } from 'react';
import Split from 'react-split';

import Calendar from '$components/Calendar/CalendarRoot';
Expand All @@ -27,15 +27,25 @@ function DesktopHome() {

const scheduleManagementRef = useRef<HTMLDivElement>();

const handleDrag = () => {
const handleDrag = useCallback(() => {
const scheduleManagementElement = scheduleManagementRef.current;
if (!scheduleManagementElement) {
return;
}

const elementWidth = scheduleManagementElement.getBoundingClientRect().width;
setScheduleManagementWidth(elementWidth);
};
}, [setScheduleManagementWidth]);

useEffect(() => {
handleDrag();

window.addEventListener('resize', handleDrag);

return () => {
window.removeEventListener('resize', handleDrag);
};
}, [handleDrag]);

return (
<>
Expand Down

0 comments on commit c790cac

Please sign in to comment.