Skip to content

Commit

Permalink
Search: Add term filter
Browse files Browse the repository at this point in the history
  • Loading branch information
DCRepublic committed Nov 4, 2024
1 parent 9de686c commit 286fa4d
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 8 deletions.
4 changes: 3 additions & 1 deletion app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ export default async function Page(props: {
searchParams?: Promise<{
query?: string;
page?: string;
term?: string;
}>;
}) {
const searchParams = await props.searchParams;
const query = searchParams?.query || "";
const term = searchParams?.term || "";
var homePageProps: any = {};

homePageProps["fullCourseList"] = (
Expand All @@ -26,7 +28,7 @@ export default async function Page(props: {
<Skeleton className="rounded-lg w-8/12 h-full align-top justify-start" />
}
>
<FullCourseList query={query} />
<FullCourseList query={query} term={term} />
</Suspense>
);

Expand Down
4 changes: 3 additions & 1 deletion components/CourseCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ export default function CourseCard(props: any) {
props.course.courseTitle +
" (" +
props.course.facultyMeet.category +
")"}
")" +
" " +
props.course.year}
</p>
</div>
<div className="row-start-1 row-span-3 col-start-6 mb-5">
Expand Down
13 changes: 10 additions & 3 deletions components/FullCourseList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Course } from "@prisma/client";
import prisma from "../lib/prisma";
import CourseCard from "./CourseCard";
import { getPlanCookie } from "../app/actions";
async function getCourses(query: string) {
async function getCourses(query: string, term: string) {
return await prisma.course.findMany({
include: {
sectionAttributes: true,
Expand All @@ -20,6 +20,7 @@ async function getCourses(query: string) {
where: {
...(query
? {
year: term,
OR: [
{
courseTitle: {
Expand Down Expand Up @@ -50,8 +51,14 @@ async function getCourses(query: string) {
});
}

export async function FullCourseList({ query }: { query: string }) {
const courseList: Course[] = await getCourses(query);
export async function FullCourseList({
query,
term,
}: {
query: string;
term: string;
}) {
const courseList: Course[] = await getCourses(query, term);

return (
<>
Expand Down
30 changes: 28 additions & 2 deletions components/Search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@
import { Input } from "@nextui-org/input";
import { useSearchParams, usePathname, useRouter } from "next/navigation";
import { useDebouncedCallback } from "use-debounce";
import { Select, SelectItem } from "@nextui-org/react";
import { useState } from "react";

export default function Search(props: any) {
const searchParams = useSearchParams();
const [selectedTerm, setSelectedTerm]: any = useState(["S2025"]);

const pathname = usePathname();
const { replace } = useRouter();
Expand All @@ -13,14 +17,24 @@ export default function Search(props: any) {
const params = new URLSearchParams(searchParams);
if (term) {
params.set("query", term);
params.set("term", selectedTerm[0]);
} else {
params.delete("query");
params.delete("term");
}
replace(`${pathname}?${params.toString()}`);
});

const handleSelectionChange = (e: any) => {
console.log(e.target.value);
setSelectedTerm([e.target.value]);
//handleSearch();
//cookies.set("plan", e.target.value);
//setPlanCookie(e.target.value);
};

return (
<>
<div className="grid grid-cols-2">
<Input
isClearable
className="max-w-xs"
Expand All @@ -32,6 +46,18 @@ export default function Search(props: any) {
handleSearch(e.target.value);
}}
/>
</>

<Select
label="Select Term"
className="w-48"
selectedKeys={selectedTerm}
defaultSelectedKeys={searchParams.get("term")?.toString()}
selectionMode={"single"}
onChange={handleSelectionChange}
>
<SelectItem key={"F2024"}>Fall 2024</SelectItem>
<SelectItem key={"S2025"}>Spring 2025</SelectItem>
</Select>
</div>
);
}
2 changes: 1 addition & 1 deletion swatscraper
Submodule swatscraper updated 1 files
+15 −11 main.go

0 comments on commit 286fa4d

Please sign in to comment.