From b0a95a6153defb077d39ab0012ad32503cbee703 Mon Sep 17 00:00:00 2001 From: knownotunknown <78577376+knownotunknown@users.noreply.github.com> Date: Sun, 18 Feb 2024 14:10:13 -0600 Subject: [PATCH] Made CourseCells and CalendarGridCells more responsive. CourseCells now rendering onto grid. Still, need to make course cells more responsive, and add edge cases --- .../components/CalendarGrid.stories.tsx | 18 +-- .../CalendarCourseCell/CalendarCourseCell.tsx | 2 +- .../CalendarGrid/CalendarGrid.module.scss | 20 ++- .../common/CalendarGrid/CalendarGrid.tsx | 143 +++++++++++------- .../CalendarGridCell.module.scss | 8 +- .../CalendarGridCell/CalendarGridCell.tsx | 16 +- 6 files changed, 125 insertions(+), 82 deletions(-) diff --git a/src/stories/components/CalendarGrid.stories.tsx b/src/stories/components/CalendarGrid.stories.tsx index 1d05426c..7a6d3da2 100644 --- a/src/stories/components/CalendarGrid.stories.tsx +++ b/src/stories/components/CalendarGrid.stories.tsx @@ -1,8 +1,8 @@ import { Meta, StoryObj } from '@storybook/react'; -import CalendarGrid from 'src/views/components/common/CalendarGrid/CalendarGrid'; -import { getCourseColors } from 'src/shared/util/colors'; -import { CalendarGridCourse } from 'src/views/hooks/useFlattenedCourseSchedule'; -import { Status } from 'src/shared/types/Course'; +import CalendarGrid from '@views/components/common/CalendarGrid/CalendarGrid'; +import { getCourseColors } from '@shared/util/colors'; +import { CalendarGridCourse } from '@views/hooks/useFlattenedCourseSchedule'; +import { Status } from '@shared/types/Course'; const meta = { title: 'Components/Common/CalendarGrid', @@ -20,9 +20,9 @@ export default meta; const testData: CalendarGridCourse[] = [ { calendarGridPoint: { - dayIndex: 0, - startIndex: 4, - endIndex: 6, + dayIndex: 4, + startIndex: 10, + endIndex: 11, }, componentProps: { courseDeptAndInstr: 'Course 1', @@ -33,9 +33,9 @@ const testData: CalendarGridCourse[] = [ }, { calendarGridPoint: { - dayIndex: 4, + dayIndex: 1, startIndex: 10, - endIndex: 20, + endIndex: 12, }, componentProps: { courseDeptAndInstr: 'Course 2', diff --git a/src/views/components/common/CalendarCourseCell/CalendarCourseCell.tsx b/src/views/components/common/CalendarCourseCell/CalendarCourseCell.tsx index 1ea60c25..0e15e6e6 100644 --- a/src/views/components/common/CalendarCourseCell/CalendarCourseCell.tsx +++ b/src/views/components/common/CalendarCourseCell/CalendarCourseCell.tsx @@ -36,7 +36,7 @@ const CalendarCourseCell: React.FC = ({ return (
!['S', 'SU'].includes(key)); + +/* const daysOfWeek = Object.keys(DAY_MAP).filter(key => !['S', 'SU'].includes(key)); const hoursOfDay = Array.from({ length: 14 }, (_, index) => index + 8); const grid = []; for (let i = 0; i < 13; i++) { @@ -25,7 +25,7 @@ for (let i = 0; i < 13; i++) { ); row.push(Array.from({ length: 5 }, (_, j) => )); grid.push(row); -} +} */ interface Props { courseCells: CalendarGridCourse[]; @@ -38,8 +38,12 @@ interface Props { */ function CalendarGrid({ courseCells, saturdayClass }: React.PropsWithChildren): JSX.Element { const [iterator, setIterator] = useState(0); + const [grid, setGrid] = useState([]); const calendarRef = useRef(null); // Create a ref for the calendar grid + const daysOfWeek = Object.keys(DAY_MAP).filter(key => !['S', 'SU'].includes(key)); + const hoursOfDay = Array.from({ length: 14 }, (_, index) => index + 8); + const saveAsPNG = () => { if (calendarRef.current) { html2canvas(calendarRef.current).then(canvas => { @@ -52,65 +56,88 @@ function CalendarGrid({ courseCells, saturdayClass }: React.PropsWithChildren { + const newGrid = []; + for (let i = 0; i < 13; i++) { + const row = []; + let hour = hoursOfDay[i]; + let styleProp = { + gridColumn: '1', + gridRow: `${(2 * i) + 2}`, + }; + row.push( +
+
+

{(hour % 12 === 0 ? 12 : hour % 12) + (hour < 12 ? ' AM' : ' PM')}

+
+
+ ); + for (let k = 0; k < 5; k++) { + // let shouldRender = false; + styleProp = { + gridColumn: `${k + 2}`, + gridRow: `${2 * i + 2} / ${2 * i + 4}`, + }; + /* let shouldRenderChild = courseCells[iterator]?.calendarGridPoint && + k === courseCells[iterator].calendarGridPoint.dayIndex && i === courseCells[iterator].calendarGridPoint.startIndex; + let childElement =
; */ + /* let completeGridCell = shouldRenderChild ? + : ; */ + row.push(); + } + newGrid.push(row); + } + setGrid(newGrid); + }, []); + return (
-
- {/* Displaying the rest of the calendar */} -
- {/*
-
- {hoursOfDay.map((hour) => ( -
-
-

{hour % 12 === 0 ? 12 : hour % 12} {hour < 12 ? 'AM' : 'PM'}

-
-
- ))} -
*/} -
+
+ {/* Displaying the rest of the calendar */} +
+
{/* Displaying day labels */} -
- {daysOfWeek.map((day, x) => ( -
- {day} -
- ))} - {grid.map((row, y) => ( -
- {row.map((cell, x) => { - const shouldRenderChild = courseCells[iterator].calendarGridPoint && x === courseCells[iterator].calendarGridPoint.dayIndex && y === courseCells[iterator].calendarGridPoint.startIndex; - if (shouldRenderChild) { - setIterator((iterator) => iterator + 1); - } - return ( -
- {cell} - {shouldRenderChild && } -
- ); - })} +
+ {daysOfWeek.map(day => ( +
+ {day}
))} + {grid.map((row, rowIndex) => (row))} + {courseCells.map((block: CalendarGridCourse) => ( +
+ +
+ ))}
- -
-
{/* First divider */} - -
{/* Second divider */} - -
); } export default CalendarGrid; + + +/*
+
+ +
+ +
*/ \ No newline at end of file diff --git a/src/views/components/common/CalendarGridCell/CalendarGridCell.module.scss b/src/views/components/common/CalendarGridCell/CalendarGridCell.module.scss index b34ddb32..639c8fbb 100644 --- a/src/views/components/common/CalendarGridCell/CalendarGridCell.module.scss +++ b/src/views/components/common/CalendarGridCell/CalendarGridCell.module.scss @@ -1,7 +1,7 @@ .calendarCell { display: flex; - width: 213.8px; - height: 44.769px; + width: 100%; + height: 100%; min-width: 45px; min-height: 40px; flex-direction: column; @@ -11,8 +11,8 @@ } .hourLine { - width: 213.8px; + width: 100%; height: 1px; - border-radius: var(--border-radius-none, 0px); + border-radius: 0px; background: rgba(218, 220, 224, 0.25); } diff --git a/src/views/components/common/CalendarGridCell/CalendarGridCell.tsx b/src/views/components/common/CalendarGridCell/CalendarGridCell.tsx index 600a5712..77c35553 100644 --- a/src/views/components/common/CalendarGridCell/CalendarGridCell.tsx +++ b/src/views/components/common/CalendarGridCell/CalendarGridCell.tsx @@ -1,14 +1,20 @@ import React from 'react'; import styles from './CalendarGridCell.module.scss'; +interface Props { + styleProp: any; +} + /** * Component representing each 1 hour time block of a calendar * @param props */ -const CalendarCell: React.FC = props => ( -
-
-
-); +function CalendarCell({ styleProp }: Props): JSX.Element { + return ( +
+
+
+ ); +} export default CalendarCell;