From 62046b3acde01f9f66e1d5d52e03fea4c5bbfc8d Mon Sep 17 00:00:00 2001 From: Daniel Weipert Date: Fri, 18 Dec 2020 00:56:32 +0100 Subject: Initial commit --- components/Calendar/index.js | 54 ++++++++++++++++++++++++++++++++++++++++++++ components/index.js | 10 ++++++++ 2 files changed, 64 insertions(+) create mode 100644 components/Calendar/index.js create mode 100644 components/index.js (limited to 'components') diff --git a/components/Calendar/index.js b/components/Calendar/index.js new file mode 100644 index 0000000..bc00831 --- /dev/null +++ b/components/Calendar/index.js @@ -0,0 +1,54 @@ +import React from 'react' +import FullCalendar from '@fullcalendar/react' +import dayGridPlugin from '@fullcalendar/daygrid' + +export default class Calendar extends React.Component { + constructor(props) { + super(props); + this.state = { + events: [ + { title: 'Geburtstag', date: '2020-12-19' }, + { title: 'Weihnachten', date: '2020-12-24' }, + ], + }; + } + + fetchEvents({start, end}, successCallback, failureCallback) { + const calendarEvents = new wp.api.collections.CalendarEvent(); + calendarEvents.fetch({ + data: { + before: start.toISOString(), + after: end.toISOString(), + } + }).then(async (events) => { + const mappedEvents = await Promise.all(events.map(async (event) => { + const category = new wp.api.models.CalendarEventCategory({ id: event['calendar-event-category'][0] }); + await category.fetch(); + return { + title: event.title.rendered, + start: event.meta.start_date, + end: event.meta.end_date, + color: category.getMeta('color'), + }; + })); + successCallback(mappedEvents); + }).catch((error) => { + failureCallback(error); + }); + } + + render() { + return ( + + ) + } +} diff --git a/components/index.js b/components/index.js new file mode 100644 index 0000000..2d8e826 --- /dev/null +++ b/components/index.js @@ -0,0 +1,10 @@ +import React from 'react'; +import { render } from 'react-dom'; +import Calendar from './Calendar'; + +document.addEventListener('DOMContentLoaded', () => { + render( + , + document.querySelector('#basic-fullcalendar'), + ); +}); -- cgit v1.2.3