|
4 | 4 | SetStateAction, |
5 | 5 | useCallback, |
6 | 6 | useEffect, |
| 7 | + useMemo, |
7 | 8 | useState, |
8 | 9 | } from "react"; |
9 | 10 | import { |
@@ -89,34 +90,29 @@ export default function CreateWithTranscriptPanel({ |
89 | 90 | // Will likely change in the future! |
90 | 91 | useEffect(() => { |
91 | 92 | if (degreeID) { |
92 | | - const courses = []; |
93 | | - for (let semester of scrapedCourses) { |
94 | | - const formattedSemester: { sem: String; courses: String[] } = { |
95 | | - sem: "", |
96 | | - courses: [], |
97 | | - }; |
98 | | - let rawSem = semester.sem; |
| 93 | + const courses = scrapedCourses.map((semester: any) => { |
| 94 | + const rawSem = semester.sem; |
| 95 | + let sem: string; |
99 | 96 | if (rawSem === "_TRAN") { |
100 | | - formattedSemester.sem = "_TRAN"; |
| 97 | + sem = "_TRAN"; |
101 | 98 | } else { |
102 | | - let formattedSem = rawSem.match(/(\d+)/)[0]; |
103 | | - |
104 | | - if (rawSem.includes("spring")) formattedSem += "A"; |
105 | | - else if (rawSem.includes("summer")) formattedSem += "B"; |
106 | | - else formattedSem += "C"; |
107 | | - formattedSemester.sem = formattedSem; |
| 99 | + const year = rawSem.match(/(\d+)/)[0]; |
| 100 | + const suffix = rawSem.includes("spring") ? "A" : rawSem.includes("summer") ? "B" : "C"; |
| 101 | + sem = year + suffix; |
108 | 102 | } |
109 | | - formattedSemester.courses = semester.courses.map((course: String) => |
110 | | - course.replace(" ", "-").toUpperCase() |
111 | | - ); |
112 | | - courses.push(formattedSemester); |
113 | | - } |
| 103 | + return { |
| 104 | + sem, |
| 105 | + courses: semester.courses.map((course: string) => |
| 106 | + course.replace(" ", "-").toUpperCase() |
| 107 | + ), |
| 108 | + }; |
| 109 | + }); |
114 | 110 |
|
115 | | - if (courses.length == 0) { |
| 111 | + if (courses.length === 0) { |
116 | 112 | setShowOnboardingModal(false); |
117 | 113 | } else { |
118 | 114 | postFetcher(`/api/degree/onboard-from-transcript/${degreeID}`, { |
119 | | - courses: courses, |
| 115 | + courses, |
120 | 116 | }).then((r) => setShowOnboardingModal(false)); |
121 | 117 | } |
122 | 118 | } |
@@ -152,7 +148,7 @@ export default function CreateWithTranscriptPanel({ |
152 | 148 | JSON.stringify(semesters) |
153 | 149 | ); |
154 | 150 | } |
155 | | - postFetcher(`/api/degree/degreeplans/${_new.id}/degrees`, { |
| 151 | + await postFetcher(`/api/degree/degreeplans/${_new.id}/degrees`, { |
156 | 152 | degree_ids: majors.map((m) => m.value.id), |
157 | 153 | }); // add degree |
158 | 154 | setActiveDegreeplan(_new); |
@@ -200,13 +196,12 @@ export default function CreateWithTranscriptPanel({ |
200 | 196 | }; |
201 | 197 | }, [options]); |
202 | 198 |
|
203 | | - const startingYearOptions = getYearOptions()?.startYears; |
204 | | - const graduationYearOptions = getYearOptions()?.gradYears; |
| 199 | + const { startYears: startingYearOptions, gradYears: graduationYearOptions } = getYearOptions(); |
205 | 200 |
|
206 | | - const majorOptionsCallback = useCallback(() => { |
207 | | - const majorOptions = getMajorOptions(degrees, schools, startingYear?.value ?? null); |
208 | | - return majorOptions; |
209 | | - }, [schools, startingYear]); |
| 201 | + const majorOptions = useMemo( |
| 202 | + () => getMajorOptions(degrees, schools, startingYear?.value ?? null), |
| 203 | + [degrees, schools, startingYear] |
| 204 | + ); |
210 | 205 |
|
211 | 206 | return ( |
212 | 207 | <CenteredFlexContainer> |
@@ -285,7 +280,7 @@ export default function CreateWithTranscriptPanel({ |
285 | 280 | <FieldWrapper> |
286 | 281 | <Label required>Major(s)</Label> |
287 | 282 | <Select |
288 | | - options={majorOptionsCallback()} |
| 283 | + options={majorOptions} |
289 | 284 | value={majors} |
290 | 285 | onChange={(selectedOptions) => setMajors([...selectedOptions])} |
291 | 286 | isClearable |
|
0 commit comments