Skip to content

Commit

Permalink
search, filters, calendar
Browse files Browse the repository at this point in the history
  • Loading branch information
DCRepublic committed Nov 6, 2024
1 parent b54d862 commit 8ddb24f
Show file tree
Hide file tree
Showing 13 changed files with 248 additions and 252 deletions.
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
33 changes: 31 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,18 +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 @@ -42,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} dotw={dotw} />
<FullCourseList query={query} term={term} dotw={dotw} stime={stime} />
</Suspense>
);

Expand All @@ -60,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}
/>
);
}
2 changes: 1 addition & 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
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
Loading

0 comments on commit 8ddb24f

Please sign in to comment.