-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from swat-sccs/dcrepublic-dev
Merge: Dcrepublic dev
- Loading branch information
Showing
13 changed files
with
406 additions
and
153 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,97 @@ | ||
import { title } from "@/components/primitives"; | ||
import FullCalendar from "@fullcalendar/react"; | ||
import timeGridPlugin from "@fullcalendar/timegrid"; // a plugin! | ||
import CreatePlan from "@/components/CreatePlan"; | ||
import moment from "moment"; | ||
import Calendar from "@/components/Calendar"; | ||
import prisma from "@/lib/prisma"; | ||
import { auth } from "@/lib/auth"; | ||
import { getPlanCookie } from "@/app/actions"; | ||
import { BorderColor } from "@mui/icons-material"; | ||
import { courseColors } from "@/components/primitives"; | ||
|
||
export default function DocsPage() { | ||
export default async function CalendarPage() { | ||
async function getEvents() { | ||
let output: any = []; | ||
let planCookie: any = await getPlanCookie(); | ||
|
||
function generateColorFromName(name: string) { | ||
let hash = 0; | ||
|
||
for (let i = 0; i < name.length; i++) { | ||
hash += name.charCodeAt(i); | ||
} | ||
|
||
return courseColors[hash % courseColors.length]; | ||
} | ||
|
||
let courses; | ||
if (planCookie) { | ||
let plan = await prisma.coursePlan.findUnique({ | ||
where: { | ||
id: parseInt(planCookie), | ||
}, | ||
include: { | ||
courses: true, | ||
}, | ||
}); | ||
|
||
courses = plan?.courses; | ||
} | ||
|
||
if (courses) { | ||
for (let i = 0; i < courses.length; i++) { | ||
let color = generateColorFromName(courses[i].subject); | ||
|
||
let num: string = courses[i].courseReferenceNumber; | ||
let meetingTimes = await prisma.meetingTime.findFirst({ | ||
where: { | ||
courseReferenceNumber: num, | ||
}, | ||
}); | ||
output.push({ | ||
classNames: "font-sans", | ||
textColor: "white", | ||
title: courses[i]?.courseTitle, | ||
daColor: color, | ||
subject: courses[i]?.subject, | ||
color: "rgba(0,0,0,0)", | ||
|
||
borderWidth: "0px", | ||
daysOfWeek: [ | ||
meetingTimes?.sunday && "0", | ||
meetingTimes?.monday && "1", | ||
meetingTimes?.tuesday && "2", | ||
meetingTimes?.wednesday && "3", | ||
meetingTimes?.thursday && "4", | ||
meetingTimes?.friday && "5", | ||
meetingTimes?.saturday && "6", | ||
], | ||
|
||
startTime: | ||
meetingTimes?.beginTime.slice(0, 2) + | ||
":" + | ||
meetingTimes?.beginTime.slice(2), | ||
endTime: | ||
meetingTimes?.endTime.slice(0, 2) + | ||
":" + | ||
meetingTimes?.endTime.slice(2), | ||
}); | ||
} | ||
} | ||
|
||
return output; | ||
} | ||
|
||
let events = await getEvents(); | ||
return ( | ||
<div> | ||
<h1 className={title()}>Calendar</h1> | ||
<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} /> | ||
</div> | ||
<div className="col-start-3 h-[62vh] "> | ||
<CreatePlan /> | ||
</div> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
"use client"; | ||
|
||
import FullCalendar from "@fullcalendar/react"; | ||
import timeGridPlugin from "@fullcalendar/timegrid"; // a plugin! | ||
import { Card } from "@nextui-org/react"; | ||
import moment from "moment"; | ||
import { generateColorFromName } from "./primitives"; | ||
|
||
export default function Calendar(props: any) { | ||
function dayHeaderContent(args: any) { | ||
return moment(args.date).format("ddd"); | ||
} | ||
|
||
function renderEventContent(eventInfo: any) { | ||
console.log(eventInfo); | ||
return ( | ||
<Card | ||
className=" fc-event-main-frame w-[100%] rounded-md hover:h-[20vh] hover:transition-all duration-700" | ||
style={{ backgroundColor: eventInfo.event.extendedProps.daColor }} | ||
> | ||
{/* | ||
<div | ||
className={`absolute top-0 left-0 h-full w-2 rounded-full`} | ||
style={{ | ||
backgroundColor: generateColorFromName( | ||
eventInfo.event.extendedProps.subject | ||
), | ||
}} | ||
/> | ||
*/} | ||
|
||
<b className="font-sans p-2"> {eventInfo.timeText}</b> | ||
<div className="font-sans p-2">{eventInfo.event.title}</div> | ||
</Card> | ||
); | ||
} | ||
|
||
return ( | ||
<FullCalendar | ||
height="100%" | ||
plugins={[timeGridPlugin]} | ||
initialView="timeGridWeek" | ||
allDaySlot={false} | ||
expandRows | ||
slotDuration="01:00:00" | ||
slotMinTime="08:00:00" | ||
slotMaxTime="22:00:00" | ||
dayHeaderFormat={dayHeaderContent} | ||
events={props.events} | ||
headerToolbar={false} | ||
eventContent={renderEventContent} | ||
/> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.