Skip to content

Commit

Permalink
Add logic to create event
Browse files Browse the repository at this point in the history
  • Loading branch information
marvinschopf committed Mar 7, 2021
1 parent 8839f35 commit d5419e6
Showing 1 changed file with 40 additions and 3 deletions.
43 changes: 40 additions & 3 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,27 @@
*/

import React from "react";
import FullCalendar from "@fullcalendar/react";
import FullCalendar, { DateSelectArg } from "@fullcalendar/react";
import dayGridPlugin from "@fullcalendar/timegrid";
import interactionPlugin from "@fullcalendar/interaction";

function mapDateDayToRealDay(num: number): number {
return [6, 1, 2, 3, 4, 5][num] + 1;
}

function mapDayToName(num: number): string {
return [
"",
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday",
"Sunday",
][num];
}

type Props = {
value?: string;
locale?: string;
Expand All @@ -45,8 +62,28 @@ class Hours extends React.Component<Props> {
plugins={[interactionPlugin, dayGridPlugin]}
selectable={true}
selectOverlap={true}
select={(selectionInfo) => {
console.log(selectionInfo);
select={(selectionInfo: DateSelectArg) => {
console.debug(selectionInfo);
let title: string = "";
if (
selectionInfo.start.getDay() ===
selectionInfo.end.getDay()
) {
title = `${selectionInfo.start.getHours()}:${selectionInfo.start.getMinutes()} - ${selectionInfo.end.getHours()}:${selectionInfo.end.getMinutes()}`;
} else {
title = `${mapDayToName(
mapDateDayToRealDay(
selectionInfo.start.getDay()
)
)} ${selectionInfo.start.getHours()}:${selectionInfo.start.getMinutes()} - ${mapDayToName(
mapDateDayToRealDay(selectionInfo.end.getDay())
)} ${selectionInfo.end.getHours()}:${selectionInfo.end.getMinutes()}`;
}
this.calendarRef.current.getApi().addEvent({
start: selectionInfo.start,
end: selectionInfo.end,
title: title,
});
}}
locale={this.props.locale ? this.props.locale : "en"}
headerToolbar={false}
Expand Down

1 comment on commit d5419e6

@vercel
Copy link

@vercel vercel bot commented on d5419e6 Mar 7, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.