You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
105 lines
2.2 KiB
TypeScript
105 lines
2.2 KiB
TypeScript
7 years ago
|
import * as React from 'react';
|
||
7 years ago
|
import BigCalendar from 'react-big-calendar';
|
||
|
import 'react-big-calendar/lib/css/react-big-calendar.css';
|
||
|
import * as moment from 'moment';
|
||
7 years ago
|
|
||
|
import * as ICAL from 'ical.js';
|
||
|
|
||
|
import * as EteSync from './api/EteSync';
|
||
|
|
||
7 years ago
|
BigCalendar.momentLocalizer(moment);
|
||
|
|
||
|
class EventWrapper {
|
||
|
event: ICAL.Event;
|
||
|
|
||
|
constructor(event: ICAL.Event) {
|
||
|
this.event = event;
|
||
|
}
|
||
|
|
||
|
get summary() {
|
||
|
return this.event.summary;
|
||
|
}
|
||
|
|
||
|
get title() {
|
||
|
return this.summary;
|
||
|
}
|
||
|
|
||
|
get start() {
|
||
|
return this.event.startDate.toJSDate();
|
||
|
}
|
||
|
|
||
|
get end() {
|
||
|
return this.event.endDate.toJSDate();
|
||
|
}
|
||
|
}
|
||
|
|
||
7 years ago
|
class JournalCalendar extends React.Component {
|
||
7 years ago
|
static defaultProps = {
|
||
|
prevUid: null,
|
||
|
};
|
||
|
|
||
7 years ago
|
state: {
|
||
|
currentDate?: Date;
|
||
|
};
|
||
|
|
||
7 years ago
|
props: {
|
||
|
journal: EteSync.Journal,
|
||
|
entries: Array<EteSync.SyncEntry>,
|
||
|
};
|
||
|
|
||
7 years ago
|
constructor(props: any) {
|
||
|
super(props);
|
||
|
this.state = {};
|
||
|
}
|
||
|
|
||
7 years ago
|
render() {
|
||
|
if (this.props.journal === undefined) {
|
||
|
return (<div>Loading</div>);
|
||
|
}
|
||
|
|
||
7 years ago
|
let items: Map<string, ICAL.Component> = new Map();
|
||
7 years ago
|
|
||
|
for (const syncEntry of this.props.entries) {
|
||
|
let comp = new ICAL.Component(ICAL.parse(syncEntry.content)).getFirstSubcomponent('vevent');
|
||
|
|
||
7 years ago
|
if (comp === null) {
|
||
|
continue;
|
||
|
}
|
||
|
|
||
7 years ago
|
const uid = comp.getFirstPropertyValue('uid');
|
||
|
|
||
|
if ((syncEntry.action === EteSync.SyncEntryAction.Add) ||
|
||
|
(syncEntry.action === EteSync.SyncEntryAction.Change)) {
|
||
|
items.set(uid, comp);
|
||
|
} else if (syncEntry.action === EteSync.SyncEntryAction.Delete) {
|
||
|
items.delete(uid);
|
||
|
}
|
||
|
}
|
||
|
|
||
7 years ago
|
let entries = Array.from(items.values()).map((value) => (
|
||
7 years ago
|
new EventWrapper(new ICAL.Event(value))
|
||
7 years ago
|
)).sort((a, b) => {
|
||
7 years ago
|
if (a.summary < b.summary) {
|
||
|
return -1;
|
||
|
} else if (a.summary > b.summary) {
|
||
|
return 1;
|
||
|
} else {
|
||
|
return 0;
|
||
|
}
|
||
|
});
|
||
|
|
||
|
return (
|
||
7 years ago
|
<div style={{width: '100%', height: 500}}>
|
||
|
<BigCalendar
|
||
|
events={entries}
|
||
|
{...{culture: 'en-GB'}}
|
||
|
date={this.state.currentDate}
|
||
|
onNavigate={(currentDate: Date) => { this.setState({currentDate}); }}
|
||
|
/>
|
||
7 years ago
|
</div>
|
||
|
);
|
||
|
}
|
||
|
}
|
||
7 years ago
|
|
||
7 years ago
|
export default JournalCalendar;
|