From 27a908a656ab733671199faf6c8ece255c75a5cd Mon Sep 17 00:00:00 2001 From: PineND Date: Wed, 4 Dec 2024 20:36:57 -0800 Subject: [PATCH] attempt at making things compile (not quite working) --- apps/frontend/package.json | 3 +- .../Class/Ratings/RatingsContainer.tsx | 9 ++- apps/frontend/src/components/Detail/index.tsx | 72 ++++++++++--------- package-lock.json | 1 + 4 files changed, 51 insertions(+), 34 deletions(-) diff --git a/apps/frontend/package.json b/apps/frontend/package.json index cdb835cb0..8bfc24255 100644 --- a/apps/frontend/package.json +++ b/apps/frontend/package.json @@ -22,8 +22,8 @@ "@radix-ui/react-separator": "^1.1.0", "@radix-ui/react-tabs": "^1.1.1", "@radix-ui/react-tooltip": "^1.1.4", - "@repo/theme": "*", "@repo/shared": "*", + "@repo/theme": "*", "@shopify/draggable": "^1.1.3", "@tanstack/react-virtual": "^3.10.9", "classnames": "^2.5.1", @@ -42,6 +42,7 @@ "devDependencies": { "@repo/eslint-config": "*", "@repo/typescript-config": "*", + "@types/lodash": "^4.17.13", "@types/mapbox-gl": "^3.4.1", "@types/node": "^22.9.1", "@types/react": "^18.3.12", diff --git a/apps/frontend/src/components/Class/Ratings/RatingsContainer.tsx b/apps/frontend/src/components/Class/Ratings/RatingsContainer.tsx index 7609f331e..4a445407f 100644 --- a/apps/frontend/src/components/Class/Ratings/RatingsContainer.tsx +++ b/apps/frontend/src/components/Class/Ratings/RatingsContainer.tsx @@ -60,6 +60,13 @@ const isSemester = (value: string): boolean => { return Object.values(Semester).includes(firstWord as Semester); }; +interface Term { + semester: Semester; + year: number; + value: string; + label: string; +} + export function RatingsContainer() { const [isModalOpen, setIsModalOpen] = useState(false); const [isDeleteModalOpen, setIsDeleteModalOpen] = useState(false); @@ -263,7 +270,7 @@ export function RatingsContainer() { { + ...availableTerms.filter((term: Term) => { // Filter for past terms const termPosition = termsData?.find( (t) => diff --git a/apps/frontend/src/components/Detail/index.tsx b/apps/frontend/src/components/Detail/index.tsx index b81483086..315195736 100644 --- a/apps/frontend/src/components/Detail/index.tsx +++ b/apps/frontend/src/components/Detail/index.tsx @@ -22,17 +22,37 @@ import styles from "./Detail.module.scss"; import MyIcon2 from "./attended.svg"; import MyIcon1 from "./recorded.svg"; -interface AttendanceRequirementsProps { - attendanceRequired: boolean | null; - lecturesRecorded: boolean | null; - submissionAmount?: number; // Optional prop with default value +interface Props { + attendanceRequired?: boolean; + lecturesRecorded?: boolean; + submissionAmount?: number; +} + +interface ClassInfo { + semester: string; + year: number; +} + +interface TermInfo { + semester: Semester; + year: number; + value: string; + label: string; +} + +interface UserClass { + subject: string; + courseNumber: string; + semester: Semester; + year: number; + classNumber: string; } export default function AttendanceRequirements({ - attendanceRequired, - lecturesRecorded, - submissionAmount = 0, // Default value set to 0 -}: AttendanceRequirementsProps) { + attendanceRequired = false, + lecturesRecorded = false, + submissionAmount = 0, +}: Props) { const [isModalOpen, setModalOpen] = useState(false); const { class: currentClass } = useClass(); const { data: user } = useReadUser(); @@ -80,32 +100,32 @@ export default function AttendanceRequirements({ }; const availableTerms = React.useMemo(() => { - if (!courseData?.course?.classes) return []; + if (!courseData?.course?.classes) return [] as TermInfo[]; - return _.chain(courseData.course.classes) - .map((classInfo) => ({ + return _.chain(courseData.course.classes as ClassInfo[]) + .map((classInfo: ClassInfo): TermInfo => ({ value: `${classInfo.semester} ${classInfo.year}`, label: `${classInfo.semester} ${classInfo.year}`, semester: classInfo.semester as Semester, year: classInfo.year, })) - .uniqBy((term) => `${term.semester}-${term.year}`) + .uniqBy((term: TermInfo) => `${term.semester}-${term.year}`) .orderBy( [ - "year", - (term) => { + 'year', + (term: TermInfo) => { const semesterOrder = { [Semester.Spring]: 0, [Semester.Summer]: 1, [Semester.Fall]: 2, [Semester.Winter]: 3, }; - return semesterOrder[term.semester as Semester]; + return semesterOrder[term.semester]; }, - ], - ["desc", "asc"] + ] as const, + ['desc', 'asc'] ) - .value(); + .value() as TermInfo[]; }, [courseData]); if (submissionAmount < 5) { return ( @@ -132,13 +152,7 @@ export default function AttendanceRequirements({ availableTerms={availableTerms} onSubmit={handleSubmitRatings} initialUserClass={userRatingsData?.userRatings?.classes?.find( - (c: { - subject: string; - courseNumber: string; - semester: Semester; - year: number; - classNumber: string; - }) => + (c: UserClass) => c.subject === currentClass.subject && c.courseNumber === currentClass.courseNumber && c.semester === currentClass.semester && @@ -195,13 +209,7 @@ export default function AttendanceRequirements({ availableTerms={availableTerms} onSubmit={handleSubmitRatings} initialUserClass={userRatingsData?.userRatings?.classes?.find( - (c: { - subject: string; - courseNumber: string; - semester: Semester; - year: number; - classNumber: string; - }) => + (c: UserClass) => c.subject === currentClass.subject && c.courseNumber === currentClass.courseNumber && c.semester === currentClass.semester && diff --git a/package-lock.json b/package-lock.json index 17f284318..ba924f0ea 100644 --- a/package-lock.json +++ b/package-lock.json @@ -137,6 +137,7 @@ "devDependencies": { "@repo/eslint-config": "*", "@repo/typescript-config": "*", + "@types/lodash": "^4.17.13", "@types/mapbox-gl": "^3.4.1", "@types/node": "^22.9.1", "@types/react": "^18.3.12",