diff --git a/app/page.tsx b/app/page.tsx index 4ef48f6..61c0dfd 100644 --- a/app/page.tsx +++ b/app/page.tsx @@ -10,6 +10,18 @@ import prisma from "../lib/prisma"; import { Course, CoursePlan } from "@prisma/client"; import { getPlanCookie } from "../app/actions"; +async function getCourses() { + const courses = await prisma.course.findMany(); + let output: any = []; + + for (let i = 0; i < courses.length; i++) { + if (!output.includes(courses[i].year)) { + output.push(courses[i].year); + } + } + return output; +} + export default async function Page(props: { searchParams?: Promise<{ query?: string; @@ -45,13 +57,15 @@ export default async function Page(props: { return ; // return with no events } async function Home(props: any) { + const terms = await getCourses(); + return ( <>
- +
{props.fullCourseList} diff --git a/components/Search.tsx b/components/Search.tsx index 45d61b9..a2c4dac 100644 --- a/components/Search.tsx +++ b/components/Search.tsx @@ -7,6 +7,7 @@ import { Select, SelectItem } from "@nextui-org/react"; import { useState } from "react"; export default function Search(props: any) { + let router = useRouter(); const searchParams = useSearchParams(); const [selectedTerm, setSelectedTerm]: any = useState(["S2025"]); @@ -28,11 +29,40 @@ export default function Search(props: any) { const handleSelectionChange = (e: any) => { console.log(e.target.value); setSelectedTerm([e.target.value]); + const params = new URLSearchParams(searchParams); + if (e.target.value) { + params.set("term", e.target.value); + } else { + params.delete("term"); + } + replace(`${pathname}?${params.toString()}`); + //handleSearch(); //cookies.set("plan", e.target.value); //setPlanCookie(e.target.value); }; + const RenderSelectOptions = () => { + let output = []; + + for (let i = 0; i < props.terms?.length; i++) { + let sem = props.terms[i].substring(0, 1); + let year = props.terms[i].substring(1); + if (sem.toLowerCase() == "s") { + output.push({ key: props.terms[i], title: "Spring " + year }); + } else if (sem.toLowerCase() == "f") { + output.push({ key: props.terms[i], title: "Fall " + year }); + } + } + + return output + .sort(function (a: any, b: any) { + return b.key - a.key; + }) + .map((term: any) => {term.title}); + }; + console.log(props.terms); + return (
- Fall 2024 - Spring 2025 + {RenderSelectOptions()}
);