Skip to content

Commit

Permalink
Search: main search, term and dotw filters
Browse files Browse the repository at this point in the history
  • Loading branch information
DCRepublic committed Nov 6, 2024
1 parent eceb766 commit b54d862
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 33 deletions.
47 changes: 27 additions & 20 deletions components/FullCourseList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ import { getPlanCookie } from "../app/actions";
async function getCourses(query: string, term: string, dotw: Array<String>) {
//let DOTW: Array<String> = dotw.split(",");
let times = ["0955"];
console.log(dotw);

return await prisma.course.findMany({
relationLoadStrategy: "join", // or 'query'

include: {
sectionAttributes: true,
facultyMeet: {
Expand All @@ -19,7 +21,11 @@ async function getCourses(query: string, term: string, dotw: Array<String>) {
},

orderBy: {
courseTitle: "desc",
_relevance: {
fields: ["courseTitle", "subject", "courseNumber"],
search: query.replace(/[\s\n\t]/g, "_"),
sort: "desc",
},
},
where: {
year: term,
Expand All @@ -40,30 +46,31 @@ async function getCourses(query: string, term: string, dotw: Array<String>) {
},
},
},
{
courseTitle: {
search: query.replace(/[\s\n\t]/g, "_"),
},
],
},

subject: {
search: query.replace(/[\s\n\t]/g, "_"),
},
/*
courseNumber: {
search: query.replace(/[\s\n\t]/g, "_"),
},
{
courseTitle: {
search: query.replace(/[\s\n\t]/g, "_"),
},
instructor: {
displayName: {
search: query.replace(/[\s\n\t]/g, "_"),
},
},
subject: {
search: query.replace(/[\s\n\t]/g, "_"),
},
courseNumber: {
search: query.replace(/[\s\n\t]/g, "_"),
},
instructor: {
displayName: {
search: query.replace(/[\s\n\t]/g, "_"),
},
],
},
},
/*
facultyMeet: {
meetingTimes: {
OR: [
Expand Down
42 changes: 29 additions & 13 deletions components/Search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@ 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";
import { useEffect, useState } from "react";

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

const pathname = usePathname();
const { replace } = useRouter();

Expand Down Expand Up @@ -40,9 +39,12 @@ export default function Search(props: any) {
//setPlanCookie(e.target.value);
};

const handleDOTWChange = (e: any) => {
//console.log(Array.from(e).join(", "));
useEffect(() => {
// Update the document title using the browser API
setSelectedDOTW(searchParams.get("dotw")?.toString().split(","));
}, [searchParams.get("term")?.toString()]);

const handleDOTWChange = (e: any) => {
setSelectedDOTW(...[e]);
const params = new URLSearchParams(searchParams);
if (e.size > 0) {
Expand Down Expand Up @@ -102,17 +104,31 @@ export default function Search(props: any) {
label="Day of the Week"
className="max-w-xs"
selectedKeys={selectedDOTW}
selectionMode="multiple"
defaultSelectedKeys={searchParams.get("dotw")?.toString()}
selectionMode={"multiple"}
//defaultSelectedKeys={searchParams.get("dotw")?.toString()}
onSelectionChange={handleDOTWChange}
>
<SelectItem key={"sunday"}>Sunday</SelectItem>
<SelectItem key={"monday"}>Monday</SelectItem>
<SelectItem key={"tuesday"}>Tuesday</SelectItem>
<SelectItem key={"wednesday"}>Wednesday</SelectItem>
<SelectItem key={"thursday"}>Thursday</SelectItem>
<SelectItem key={"friday"}>Friday</SelectItem>
<SelectItem key={"saturday"}>Saturday</SelectItem>
<SelectItem key={"sunday"} value="sunday">
Sunday
</SelectItem>
<SelectItem key={"monday"} value={"monday"}>
Monday
</SelectItem>
<SelectItem key={"tuesday"} value={"tuesday"}>
Tuesday
</SelectItem>
<SelectItem key={"wednesday"} value={"wednesday"}>
Wednesday
</SelectItem>
<SelectItem key={"thursday"} value={"thursday"}>
Thursday
</SelectItem>
<SelectItem key={"friday"} value={"monfridayday"}>
Friday
</SelectItem>
<SelectItem key={"saturday"} value={"saturday"}>
Saturday
</SelectItem>
</Select>
</div>
);
Expand Down

0 comments on commit b54d862

Please sign in to comment.