From 286fa4d6b63490748b84c972e7ea947c69fea6ba Mon Sep 17 00:00:00 2001
From: Damian <37555910+DCRepublic@users.noreply.github.com>
Date: Mon, 4 Nov 2024 11:16:08 -0500
Subject: [PATCH] Search: Add term filter
---
app/page.tsx | 4 +++-
components/CourseCard.tsx | 4 +++-
components/FullCourseList.tsx | 13 ++++++++++---
components/Search.tsx | 30 ++++++++++++++++++++++++++++--
swatscraper | 2 +-
5 files changed, 45 insertions(+), 8 deletions(-)
diff --git a/app/page.tsx b/app/page.tsx
index 8292cca..4ef48f6 100644
--- a/app/page.tsx
+++ b/app/page.tsx
@@ -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"] = (
@@ -26,7 +28,7 @@ export default async function Page(props: {
}
>
-
+
);
diff --git a/components/CourseCard.tsx b/components/CourseCard.tsx
index 525a7c8..df414ff 100644
--- a/components/CourseCard.tsx
+++ b/components/CourseCard.tsx
@@ -68,7 +68,9 @@ export default function CourseCard(props: any) {
props.course.courseTitle +
" (" +
props.course.facultyMeet.category +
- ")"}
+ ")" +
+ " " +
+ props.course.year}
diff --git a/components/FullCourseList.tsx b/components/FullCourseList.tsx
index 6d21b34..c58d44d 100644
--- a/components/FullCourseList.tsx
+++ b/components/FullCourseList.tsx
@@ -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,
@@ -20,6 +20,7 @@ async function getCourses(query: string) {
where: {
...(query
? {
+ year: term,
OR: [
{
courseTitle: {
@@ -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 (
<>
diff --git a/components/Search.tsx b/components/Search.tsx
index 64b388e..45d61b9 100644
--- a/components/Search.tsx
+++ b/components/Search.tsx
@@ -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();
@@ -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 (
- <>
+
- >
+
+
+
);
}
diff --git a/swatscraper b/swatscraper
index ef2320d..bffb3e2 160000
--- a/swatscraper
+++ b/swatscraper
@@ -1 +1 @@
-Subproject commit ef2320da38fbcc30e131be8c023d70ed26cd5556
+Subproject commit bffb3e2274fe165291fc0e3a20bc674c8287d53e