Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

merge: Dcrepublic dev into main #15

Merged
merged 3 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 34 additions & 5 deletions app/calendar/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,25 +58,54 @@ export default async function CalendarPage() {
],

startTime:
meetingTimes?.beginTime.slice(0, 2) +
meetingTimes?.beginTime?.slice(0, 2) +
":" +
meetingTimes?.beginTime.slice(2),
meetingTimes?.beginTime?.slice(2),
endTime:
meetingTimes?.endTime.slice(0, 2) +
meetingTimes?.endTime?.slice(0, 2) +
":" +
meetingTimes?.endTime.slice(2),
meetingTimes?.endTime?.slice(2),
});
}
}

return output;
}

async function getUniqueStartEndTimes() {
const maxstart = await prisma.meetingTime.findFirst({
where: {
beginTime: { not: "" },
},
orderBy: {
beginTime: "desc",
},
});
const maxend = await prisma.meetingTime.findFirst({
where: {
endTime: { not: "" },
},
orderBy: {
beginTime: "desc",
},
});

let times = {
minTime:
maxstart?.beginTime.slice(0, 2) + ":" + maxstart?.beginTime.slice(2),
maxTime:
maxstart?.endTime.slice(0, 2) + ":" + maxstart?.beginTime.slice(2),
};
console.log(times);
return times;
}

let events = await getEvents();
let times = await getUniqueStartEndTimes();
return (
<div className="grid grid-cols-3 p-4 -mt-20 w-screen absolute start-0 px-32 gap-20">
<div className=" col-start-1 h-[70vh] w-[57vw] col-span-2 font-sans font-normal">
<Calendar events={events} />
<Calendar events={events} times={times} />
</div>
<div className="col-start-3 h-[62vh] ">
<CreatePlan />
Expand Down
35 changes: 33 additions & 2 deletions app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { auth } from "../lib/auth";
import prisma from "../lib/prisma";
import { Course, CoursePlan } from "@prisma/client";
import { getPlanCookie } from "../app/actions";
import { PlanCardList } from "../components/PlanCardList";

async function getCourses() {
const courses = await prisma.course.findMany();
Expand All @@ -22,16 +23,45 @@ async function getCourses() {
return output;
}

async function getUniqueStartEndTimes() {
const meetingTimes = await prisma.meetingTime.findMany({
where: {
beginTime: { not: "" },
},
orderBy: {
beginTime: "asc",
},
});
let startTimes: any = [];
let endTimes: any = [];

for (let i = 0; i < meetingTimes.length; i++) {
if (!startTimes.includes(meetingTimes[i].beginTime)) {
startTimes.push(meetingTimes[i].beginTime);
}
if (!endTimes.includes(meetingTimes[i].endTime)) {
endTimes.push(meetingTimes[i].endTime);
}
}

let times = { startTimes: startTimes, endTimes: endTimes };
return times;
}

export default async function Page(props: {
searchParams?: Promise<{
query?: string;
page?: string;
term?: string;
dotw?: Array<String>;
stime?: Array<string>;
}>;
}) {
const searchParams = await props.searchParams;
const query = searchParams?.query || "";
const term = searchParams?.term || "";
const dotw = searchParams?.dotw || [];
const stime = searchParams?.stime || [];
var homePageProps: any = {};

homePageProps["fullCourseList"] = (
Expand All @@ -40,7 +70,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} stime={stime} />
</Suspense>
);

Expand All @@ -58,14 +88,15 @@ export default async function Page(props: {
}
async function Home(props: any) {
const terms = await getCourses();
const uniqueTimes = await getUniqueStartEndTimes();

return (
<>
<div className="grid grid-cols-3 p-4 -mt-10 ">
<div className="col-span-2 col-start-1">
<div className="grid grid-rows-subgrid grid-cols-1 gap-5 ">
<div className="row-start-1">
<Search terms={terms} />
<Search terms={terms} times={uniqueTimes} />
</div>
<div className="row-start-2 h-[62vh] overflow-y-scroll overflow-x-clip">
{props.fullCourseList}
Expand Down
4 changes: 3 additions & 1 deletion components/Calendar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,13 @@ export default function Calendar(props: any) {
expandRows
slotDuration="01:00:00"
slotMinTime="08:00:00"
slotMaxTime="22:00:00"
slotMaxTime="23:00:00"
weekends={false}
dayHeaderFormat={dayHeaderContent}
events={props.events}
headerToolbar={false}
eventContent={renderEventContent}
editable={false}
/>
);
}
32 changes: 31 additions & 1 deletion components/CourseCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import AddIcon from "@mui/icons-material/Add";
import axios from "axios";
export const card = tv({
slots: {
base: "bg-light_foreground min-h-32 max-h-32 w-[98%] rounded-sm scroll-none drop-shadow-lg transition-colors",
base: "bg-light_foreground min-h-48 max-h-48 w-[98%] rounded-sm scroll-none drop-shadow-lg transition-colors",
role: "font-bold text-primary ",
},
});
Expand Down 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
21 changes: 4 additions & 17 deletions components/CreatePlan.tsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,12 @@
"use client";
import {
Card,
CardBody,
Divider,
Link,
User,
Popover,
PopoverTrigger,
PopoverContent,
Input,
Button,
Skeleton,
CardHeader,
} from "@nextui-org/react";
import {
Dropdown,
DropdownTrigger,
DropdownMenu,
DropdownItem,
RadioGroup,
Radio,
} from "@nextui-org/react";
import ArrowDropDownIcon from "@mui/icons-material/ArrowDropDown";
import AddIcon from "@mui/icons-material/Add";
import DeleteIcon from "@mui/icons-material/Delete";
import IosShareIcon from "@mui/icons-material/IosShare";
Expand All @@ -33,11 +18,13 @@ import { useRouter } from "next/navigation";
import { InstructorCard } from "./InstructorCard";
import { usePathname } from "next/navigation";
import { useSession } from "next-auth/react";
import { useEffect, useState } from "react";
import { Suspense, useEffect, useState } from "react";
import useSWR from "swr";
import { setPlanCookie } from "../app/actions";
import { useCookies } from "next-client-cookies";
import { generateColorFromName } from "../components/primitives";
import { FullCourseList } from "./FullCourseList";
import { PlanCardList } from "./PlanCardList";
export default function CreatePlan(props: any) {
const cookies = useCookies();
const router = useRouter();
Expand All @@ -57,7 +44,7 @@ export default function CreatePlan(props: any) {
isLoading: coursePlansIsLoading,
error: coursePlansError,
} = useSWR("/api/getcourseplans", fetcher, {
refreshInterval: 1000,
refreshInterval: 2000,
});

async function createPlan() {
Expand Down
89 changes: 60 additions & 29 deletions components/FullCourseList.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
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>,
stime: Array<string>
) {
//let DOTW: Array<String> = dotw.split(",");

let startTime = stime.toString().split(",").filter(Number);

console.log(startTime);
return await prisma.course.findMany({
relationLoadStrategy: "join", // or 'query'

include: {
sectionAttributes: true,
facultyMeet: {
Expand All @@ -14,51 +27,69 @@ async function getCourses(query: string, term: string) {
instructor: true,
},

orderBy: {
courseTitle: "desc",
},
orderBy: [
{
_relevance: {
fields: ["courseTitle", "subject", "courseNumber"],
search: query.replace(/[\s\n\t]/g, "_"),
sort: "desc",
},
},
{},
],
where: {
...(query
...(term
? {
year: term,
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, "_"),
},
}
: {}),
//year: term,

...(startTime.length > 0
? {
facultyMeet: {
meetingTimes: {
beginTime: {
in: startTime,
},
},
],
},
}
: {}),

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,
},
},
},
},
],
},
});
}

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

return (
<>
Expand Down
Loading
Loading