Skip to content

Commit

Permalink
Search: start filters
Browse files Browse the repository at this point in the history
  • Loading branch information
DCRepublic committed Nov 5, 2024
1 parent 62aa8d3 commit eceb766
Show file tree
Hide file tree
Showing 7 changed files with 297 additions and 37 deletions.
4 changes: 3 additions & 1 deletion app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@ export default async function Page(props: {
query?: string;
page?: string;
term?: string;
dotw?: Array<String>;
}>;
}) {
const searchParams = await props.searchParams;
const query = searchParams?.query || "";
const term = searchParams?.term || "";
const dotw = searchParams?.dotw || [];
var homePageProps: any = {};

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

Expand Down
30 changes: 30 additions & 0 deletions components/CourseCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,36 @@ export default function CourseCard(props: any) {
))}
</div>

{props.course.facultyMeet.meetingTimes ? (
<div>
<p className={role()}>Days</p>
<div className="text-xs mt-2">
{props.course.facultyMeet.meetingTimes.monday ? "M" : null}{" "}
{props.course.facultyMeet.meetingTimes.tuesday ? "T" : null}{" "}
{props.course.facultyMeet.meetingTimes.wednesday ? "W" : null}{" "}
{props.course.facultyMeet.meetingTimes.thursday ? "TH" : null}{" "}
{props.course.facultyMeet.meetingTimes.friday ? "F" : null}{" "}
{props.course.facultyMeet.meetingTimes.saturday ? "Sat" : null}{" "}
{props.course.facultyMeet.meetingTimes.sunday ? "Sun" : null}
</div>
</div>
) : null}
{props.course.facultyMeet.meetingTimes ? (
<div className="mt-2">
<p className={role()}>Time</p>
<div className="text-xs ">
{" "}
{props.course.facultyMeet.meetingTimes.beginTime.slice(0, 2) +
":" +
props.course.facultyMeet.meetingTimes.beginTime.slice(2)}{" "}
-{" "}
{props.course.facultyMeet.meetingTimes.endTime.slice(0, 2) +
":" +
props.course.facultyMeet.meetingTimes.endTime.slice(2)}
</div>
</div>
) : null}

{/*
<div className="flex w-11/12">
<div>
Expand Down
216 changes: 210 additions & 6 deletions components/FullCourseList.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import { Course } from "@prisma/client";
import { Course, Prisma } from "@prisma/client";
import prisma from "../lib/prisma";
import CourseCard from "./CourseCard";
import { getPlanCookie } from "../app/actions";
async function getCourses(query: string, term: string) {

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({
include: {
sectionAttributes: true,
Expand All @@ -18,9 +22,206 @@ async function getCourses(query: string, term: string) {
courseTitle: "desc",
},
where: {
...(query
year: term,

OR: [
{
facultyMeet: {
meetingTimes: {
is: {
monday: dotw.includes("monday") ? true : Prisma.skip,
tuesday: dotw.includes("tuesday") ? true : Prisma.skip,
wednesday: dotw.includes("wednesday") ? true : Prisma.skip,
thursday: dotw.includes("thursday") ? true : Prisma.skip,
friday: dotw.includes("friday") ? true : Prisma.skip,
saturday: dotw.includes("saturday") ? true : Prisma.skip,
sunday: dotw.includes("sunday") ? true : Prisma.skip,
},
},
},
},
{
courseTitle: {
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: [
{
monday: dotw.includes("monday"),
},
{
tuesday: dotw.includes("tuesday"),
},
{
wednesday: dotw.includes("wednesday"),
},
{
thursday: dotw.includes("thursday"),
},
{
friday: dotw.includes("friday"),
},
{
saturday: dotw.includes("saturday"),
},
{
sunday: dotw.includes("sunday"),
},
],
},
},
where: {
AND: [
{
OR: [
{ year: term },
{
facultyMeet: {
OR: [
{
meetingTimes: {
monday: dotw.includes("monday"),
},
},
{
meetingTimes: {
tuesday: dotw.includes("tuesday"),
},
},
{
meetingTimes: {
wednesday: dotw.includes("wednesday"),
},
},
{
meetingTimes: {
thursday: dotw.includes("thursday"),
},
},
{
meetingTimes: {
friday: dotw.includes("friday"),
},
},
{
meetingTimes: {
saturday: dotw.includes("saturday"),
},
},
{
meetingTimes: {
sunday: dotw.includes("sunday"),
},
},
],
},
}
],}
/*
times.length > 0
? {
facultyMeet: {
OR: [
{
meetingTimes: {
monday: dotw.includes("monday"),
},
},
{
meetingTimes: {
tuesday: dotw.includes("tuesday"),
},
},
{
meetingTimes: {
wednesday: dotw.includes("wednesday"),
},
},
{
meetingTimes: {
thursday: dotw.includes("thursday"),
},
},
{
meetingTimes: {
friday: dotw.includes("friday"),
},
},
{
meetingTimes: {
saturday: dotw.includes("saturday"),
},
},
{
meetingTimes: {
sunday: dotw.includes("sunday"),
},
},
],
},
}
: {},
{
OR: [
{
courseTitle: {
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, "_"),
},
},
},
],
},
],
},
*/
/* Old where
where: {
...(query || term
? {
year: term,
OR: [
{
courseTitle: {
Expand All @@ -47,18 +248,21 @@ async function getCourses(query: string, term: string) {
],
}
: {}),
},
},*/
});
}

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

return (
<>
Expand Down
Loading

0 comments on commit eceb766

Please sign in to comment.