-
Notifications
You must be signed in to change notification settings - Fork 2
graduate cleanup + qol #472
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. moving the guest page to base graduate url |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,87 @@ | ||
| import { GuestHeaderClient } from "@/components/graduate/GuestHeaderClient"; | ||
| import { GuestPlanClient } from "@/components/graduate/GuestPlanClient"; | ||
| import NewPlanModal from "@/components/graduate/modal/NewPlanModal"; | ||
| import { auth } from "@/lib/auth/auth"; | ||
| import { getAuditPlans } from "@/lib/dal/audits"; | ||
| import { getMajor, getMinor } from "@/lib/dal/catalog"; | ||
| import { getCourseNamesBatch } from "@/lib/dal/courses"; | ||
| import { Requirement } from "@/lib/graduate/types"; | ||
| import { headers } from "next/headers"; | ||
| import { redirect } from "next/navigation"; | ||
|
|
||
| export default async function Page() { | ||
| function collectCourseKeys(reqs: Requirement[], out: Set<string>): void { | ||
| for (const req of reqs) { | ||
| if (req.type === "COURSE") { | ||
| out.add(`${req.subject}-${req.classId}`); | ||
| } else if (req.type === "AND" || req.type === "OR" || req.type === "XOM") { | ||
| collectCourseKeys(req.courses, out); | ||
| } else if (req.type === "SECTION") { | ||
| collectCourseKeys(req.requirements, out); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| export default async function Page({ | ||
| searchParams, | ||
| }: { | ||
| searchParams: Promise<{ | ||
| majors?: string | string[]; | ||
| minors?: string | string[]; | ||
| catalogYear?: string; | ||
| courses?: string; | ||
| }>; | ||
| }) { | ||
| const session = await auth.api.getSession({ headers: await headers() }); | ||
|
|
||
| if (session) { | ||
| const plans = await getAuditPlans(session.user.id); | ||
| if (plans.length > 0) { | ||
| const lastModified = plans.reduce((latest, plan) => | ||
| plan.updatedAt > latest.updatedAt ? plan : latest, | ||
| ); | ||
| redirect(`/graduate/${lastModified.id}`); | ||
| } | ||
| return ( | ||
| <div> | ||
| <NewPlanModal isGuest={false} /> | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| const params = await searchParams; | ||
| const toArray = (v: string | string[] | undefined): string[] => { | ||
| if (!v) return []; | ||
| return Array.isArray(v) ? v.filter(Boolean) : [v]; | ||
| }; | ||
| const majorNames = toArray(params.majors); | ||
| const minorNames = toArray(params.minors); | ||
| const catalogYear = params.catalogYear ? Number(params.catalogYear) : null; | ||
| const scheduleCourseKeys = params.courses | ||
| ? params.courses.split(",").filter(Boolean) | ||
| : []; | ||
|
|
||
| let courseNames: Record<string, string> = {}; | ||
| if (catalogYear) { | ||
| const [majors, minors] = await Promise.all([ | ||
| Promise.all(majorNames.map((m) => getMajor(catalogYear, m))), | ||
| Promise.all(minorNames.map((m) => getMinor(catalogYear, m))), | ||
| ]); | ||
|
|
||
| const keys = new Set<string>(scheduleCourseKeys); | ||
| for (const m of [...majors, ...minors]) { | ||
| if (!m) continue; | ||
| for (const section of m.requirementSections) { | ||
| collectCourseKeys(section.requirements, keys); | ||
| } | ||
| } | ||
|
|
||
| courseNames = await getCourseNamesBatch(keys); | ||
| } | ||
|
|
||
| return ( | ||
| <div> | ||
| <NewPlanModal isGuest={session == null} /> | ||
| <div className="flex min-h-0 w-full flex-1 flex-col gap-4 px-6"> | ||
| <GuestHeaderClient /> | ||
| <GuestPlanClient initialCourseNames={courseNames} /> | ||
| </div> | ||
| ); | ||
| } |
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. code cleanup, moving fucntions to plan util file |
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. support for guest plan client on base /graduate url |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
import was bugging when i tried to build locally, because different root folder, just copied and pasted the function over