-
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.
implemented add and remove event from CMUCal frontend
- Loading branch information
Showing
9 changed files
with
197 additions
and
42 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
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,32 +1,56 @@ | ||
import React, { useState } from "react"; | ||
import React, { useRef, useState } from "react"; | ||
import { SecondNav, Search, Footer } from "../components"; | ||
import Calendar from "../components/calendar/Calendar"; | ||
import { AddFCEventProps } from "../types"; | ||
import FullCalendar from "@fullcalendar/react"; | ||
|
||
|
||
|
||
const Home: React.FC = () => { | ||
const [showSearchBar, setShowSearchBar] = useState(true); | ||
const [page, setPage] = useState("academics"); | ||
const handleSearchBarClick = () => { | ||
setShowSearchBar(prev => !prev); | ||
} | ||
return ( | ||
<div> | ||
<div className="relative"> | ||
<div className="justify-between z-0"> | ||
<SecondNav page={page} setPage={setPage}/> | ||
const [showSearchBar, setShowSearchBar] = useState(true); | ||
const [page, setPage] = useState("academics"); | ||
// calendar events | ||
const [events, setEvents] = useState<any[]>([]); | ||
const [eventIdCount, setEventIdCount] = useState(0); | ||
|
||
const calendarRef = useRef<FullCalendar>(null); | ||
|
||
const handleSearchBarClick = () => { | ||
setShowSearchBar(prev => !prev); | ||
} | ||
|
||
|
||
const handleAddFCEvent = ({id, title, start, end, allDay}: AddFCEventProps) => { | ||
setEvents([...events, { | ||
id: id, | ||
title: title, | ||
start: start, | ||
end: end, | ||
allDay: allDay | ||
}]) | ||
} | ||
|
||
return ( | ||
<div> | ||
<div className="relative"> | ||
<div className="justify-between z-0"> | ||
<SecondNav page={page} setPage={setPage}/> | ||
</div> | ||
<div className="flex justify-between z-10 mt-2"> | ||
<div className={`${showSearchBar? 'w-2/5': 'w-1/12'}`}> | ||
<Search page={page} showSearchBar={showSearchBar} handleAddFCEvent={handleAddFCEvent} | ||
handleSearchBarClick={handleSearchBarClick} eventId={eventIdCount} | ||
setEventId={setEventIdCount} calendarRef={calendarRef} setEvents={setEvents}/> | ||
</div> | ||
|
||
<div className={`${showSearchBar? 'Calendar': 'CalendarFull'}`}> | ||
<Calendar showSearchBar={showSearchBar} events={events} calendarRef={calendarRef}/> | ||
</div> | ||
</div> | ||
</div> | ||
<div className="flex justify-between z-10 mt-2"> | ||
<div className={`${showSearchBar? 'w-2/5': 'w-1/12'}`}> | ||
<Search page={page} showSearchBar={showSearchBar} handleSearchBarClick={handleSearchBarClick}/> | ||
</div> | ||
|
||
<div className={`${showSearchBar? 'Calendar': 'CalendarFull'}`}> | ||
<Calendar showSearchBar={showSearchBar} /> | ||
</div> | ||
<Footer/> | ||
</div> | ||
</div> | ||
<Footer/> | ||
</div> | ||
); | ||
); | ||
}; | ||
|
||
export { Home }; |
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,24 @@ | ||
import React from "react"; | ||
|
||
export const getDateString = (date: string) => { | ||
// return: 2024-08-02 | ||
return new Date(date).toISOString().slice(0, 10); | ||
} | ||
|
||
export const get24Hour = (time: string) => { | ||
// time: 07:00PM | ||
const suffix = time.slice(5); //default end is the lenght of string | ||
if (suffix == 'PM') { | ||
let hour = Number(time.slice(0,2)); | ||
hour = hour + 12; | ||
const newH = `${hour}`; | ||
return newH+time.slice(2,5); | ||
} | ||
return time.slice(0,5); | ||
} | ||
|
||
export const getFormattedDateStr = (date:string, time:string) => { | ||
const formattedDate = getDateString(date); | ||
const formattedTime = get24Hour(time); | ||
return formattedDate + 'T' + formattedTime; | ||
} |
Oops, something went wrong.