-
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 #53 from maingockien01/calendar
Calendar added
- Loading branch information
Showing
6 changed files
with
145 additions
and
39 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
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,28 +1,97 @@ | ||
import React, { useState } from "react"; | ||
import React, { useEffect, useRef, useState } from "react"; | ||
import Container from '@mui/material/Container'; | ||
// eslint-disable-next-line | ||
// @ts-ignore | ||
import { DayPilotCalendar } from "@daypilot/daypilot-lite-react"; | ||
import Timetable from 'react-timetable-events'; | ||
import { getCurrentUserID } from "../Utils/getCurrentUserID"; | ||
import { SectionDTO } from '@team8/types/dtos/section/section.dto' | ||
|
||
interface Class { | ||
id: number, | ||
name: string, | ||
startTime: Date, | ||
endTime: Date | ||
} | ||
const dayMappings: { | ||
[key: string]: string; | ||
} = { | ||
M: "monday", | ||
T: "tuesday", | ||
W: "wednesday", | ||
R: "thursday", | ||
F: "friday" | ||
}; | ||
|
||
let weeklySchedule: { | ||
[K: string]: | ||
any | ||
} = { | ||
monday: [], | ||
tuesday: [], | ||
wednesday: [], | ||
thursday: [], | ||
friday: [] | ||
} | ||
|
||
const Calendar = () => { | ||
const [config, setConfig] = useState({ | ||
viewType: "WorkWeek", | ||
headerDateFormat: "dddd", | ||
businessBeginsHour: 8, | ||
businessEndsHour: 17, | ||
timeRangeSelectedHandling: "Disabled", | ||
eventMoveHandling: "Disabled", | ||
eventResizeHandling: "Disabled", | ||
eventClickHandling: "Disabled", | ||
}); | ||
const [courses, setCourses] = useState<any>(null); | ||
const [timetable, setTimetable] = useState({ | ||
monday: [], // "M" | ||
tuesday: [], | ||
wednesday: [], | ||
thursday: [], | ||
friday: [], | ||
}) | ||
|
||
useEffect(() => { | ||
let uid = getCurrentUserID(); | ||
fetch('/rest-api/term/searchCurrent') | ||
.then((res) => res.json()) | ||
.then((tid) => { | ||
return fetch(`/rest-api/user/searchActive?uid=1&tid=${tid}`); | ||
}) | ||
.then((res) => res.json()) | ||
.then((res) => { | ||
for (let i = 0; i < res.length; i++) { | ||
console.log(res[i]) | ||
const events = res[i].time.split(','); | ||
let day = []; | ||
for(const e of events){ | ||
let dayAbbr = e.charAt(0); | ||
let dayName = dayMappings[dayAbbr]; | ||
let [st, et] = e.substring(1).split('-'); | ||
|
||
// Construct the date strings | ||
let startDateStr = `2020-12-12T${st}:00`; | ||
let endDateStr = `2020-12-12T${et}:00`; | ||
// Create the date objects | ||
let startTime = new Date(startDateStr); | ||
let endTime = new Date(endDateStr); | ||
|
||
return( | ||
setTimetable(weeklySchedule[dayName].push({ | ||
id: 1, | ||
name: res[i].courseName + ' [' + res[i].location +']', | ||
startTime: startTime, | ||
endTime: endTime | ||
})) | ||
} | ||
} | ||
}) | ||
.catch((error) => { | ||
console.error('Error fetching data:', error); | ||
}); | ||
}, []); | ||
|
||
return( | ||
<Container maxWidth = "lg"> | ||
<h2> | ||
Weekly Schedule | ||
</h2> | ||
<DayPilotCalendar {...config} /> | ||
<Timetable | ||
events={ weeklySchedule } | ||
style={{ height: '500px'}} | ||
/> | ||
</Container> | ||
); | ||
|
||
} | ||
|
||
export default Calendar; |
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,16 @@ | ||
export function getCurrentUserID() { | ||
let uidHeader = "uid="; | ||
let cookie = decodeURIComponent(document.cookie); | ||
let cookieItems = cookie.split(';'); | ||
|
||
for(let i = 0; i < cookieItems.length; i++){ | ||
let currItem = cookieItems[i]; | ||
while(currItem.charAt(0) == ' '){ | ||
currItem = currItem.substring(1); | ||
} | ||
if(currItem.indexOf(uidHeader) == 0){ | ||
return currItem.substring(uidHeader.length, currItem.length); | ||
} | ||
} | ||
return ""; | ||
} |
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