-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: using only course units that have an eligible exchange active p…
…eriod
- Loading branch information
1 parent
49a468f
commit d20dea1
Showing
6 changed files
with
109 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { useMemo } from "react"; | ||
import api from "../api/backend"; | ||
import useSWR from "swr"; | ||
|
||
export default () => { | ||
const isEligible = async () => { | ||
try { | ||
const res = await fetch(`${api.BACKEND_URL}/student/exchange/eligible`, { | ||
credentials: "include", | ||
}); | ||
|
||
const json = await res.json(); | ||
} catch (error) { | ||
console.error(error); | ||
} | ||
}; | ||
|
||
const { data, error, mutate, isLoading } = useSWR("", isEligible); | ||
const courseUnits = useMemo(() => data ? data : null, [data]); | ||
|
||
return { | ||
courseUnits, | ||
error, | ||
loading: isLoading, | ||
mutate, | ||
}; | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,52 @@ | ||
import { ClassDescriptor, CourseInfo } from "../@types"; | ||
import { useMemo } from "react"; | ||
import api from "../api/backend"; | ||
import useSWR from "swr"; | ||
|
||
export default (schedule: Array<ClassDescriptor>): Array<CourseInfo> => { | ||
if (!schedule) return []; | ||
export default () => { | ||
const getEligibileCourseUnits = async () => { | ||
try { | ||
const res = await fetch(`${api.BACKEND_URL}/student/course_units/eligible`, { | ||
credentials: "include" | ||
}); | ||
|
||
const duplicates = new Set<number>(); | ||
const result = []; | ||
if (res.ok) { | ||
return await res.json(); | ||
} | ||
|
||
schedule?.forEach((scheduleItem: ClassDescriptor) => { | ||
if (!duplicates.has(scheduleItem.courseInfo.id)) { | ||
result.push(scheduleItem.courseInfo); | ||
duplicates.add(scheduleItem.courseInfo.id); | ||
return []; | ||
} catch (e) { | ||
console.error(e); | ||
return []; | ||
} | ||
}); | ||
|
||
return result.sort((a: CourseInfo, b: CourseInfo) => Number(a.acronym < b.acronym)); | ||
} | ||
|
||
const { data, error, mutate, isValidating } = useSWR("eligibleCourseUnits", getEligibileCourseUnits, {}); | ||
const enrolledCourseUnits = useMemo(() => data ? data : null, [data]); | ||
|
||
return { | ||
enrolledCourseUnits, | ||
error, | ||
loading: !data, | ||
isValidating, | ||
mutate, | ||
}; | ||
}; | ||
|
||
|
||
// export default (schedule: Array<ClassDescriptor>): Array<CourseInfo> => { | ||
// if (!schedule) return []; | ||
// | ||
// const duplicates = new Set<number>(); | ||
// const result = []; | ||
// | ||
// schedule?.forEach((scheduleItem: ClassDescriptor) => { | ||
// if (!duplicates.has(scheduleItem.courseInfo.id)) { | ||
// result.push(scheduleItem.courseInfo); | ||
// duplicates.add(scheduleItem.courseInfo.id); | ||
// } | ||
// }); | ||
// return result.sort((a: CourseInfo, b: CourseInfo) => Number(a.acronym < b.acronym)); | ||
// }; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters