Add a way to create new events.

master
Tom Hacohen 7 years ago
parent e22b520b5a
commit 81c3f4d27e

@ -59,9 +59,7 @@ class EventEdit extends React.Component {
this.state.uid = uuid.v4();
}
if (props.journalUid) {
this.state.journalUid = props.journalUid;
} else {
if (this.props.collections[0]) {
this.state.journalUid = props.collections[0].uid;
}
this.onSubmit = this.onSubmit.bind(this);
@ -70,6 +68,14 @@ class EventEdit extends React.Component {
this.toggleAllDay = this.toggleAllDay.bind(this);
}
componentWillReceiveProps(nextProps: any) {
if (this.props.collections !== nextProps.collections) {
if (nextProps.collections[0]) {
this.setState({journalUid: nextProps.collections[0].uid});
}
}
}
handleChange(name: string, value: string) {
this.setState({
[name]: value

@ -3,15 +3,20 @@ import { Route, Switch } from 'react-router';
import * as EteSync from './api/EteSync';
import { EventType } from './pim-types';
import Container from './Container';
import Contact from './Contact';
import EventEdit from './EventEdit';
import Event from './Event';
import PimMain from './PimMain';
import { routeResolver } from './App';
import { JournalsData, EntriesType, CredentialsData } from './store';
import { store, JournalsData, EntriesType, CredentialsData } from './store';
import { createJournalEntry } from './etesync-helpers';
import { syncEntriesToItemMap, syncEntriesToCalendarItemMap } from './journal-processors';
@ -29,11 +34,29 @@ class Pim extends React.Component {
constructor(props: any) {
super(props);
this.onEventSave = this.onEventSave.bind(this);
}
onEventSave(event: EventType, journalUid: string) {
const journal = this.props.journals.find((x) => (x.uid === journalUid));
if (journal === undefined) {
return;
}
const entries = this.props.entries[journal.uid];
if (entries.value === null) {
return;
}
store.dispatch(createJournalEntry(this.props.etesync, journal, entries.value, event.toIcal()));
}
render() {
const derived = this.props.etesync.encryptionKey;
let collectionsCalendar: Array<EteSync.CollectionInfo> = [];
let syncEntriesCalendar = [];
let syncEntriesAddressBook = [];
for (const journal of this.props.journals) {
@ -64,6 +87,7 @@ class Pim extends React.Component {
syncEntriesAddressBook.push(syncEntriesToItemMap(collectionInfo, syncEntries));
} else if (collectionInfo.type === 'CALENDAR') {
syncEntriesCalendar.push(syncEntriesToCalendarItemMap(collectionInfo, syncEntries));
collectionsCalendar.push(collectionInfo);
}
}
@ -93,6 +117,15 @@ class Pim extends React.Component {
</Container>
)}
/>
<Route
path={routeResolver.getRoute('pim.events.new')}
exact={true}
render={({match}) => (
<Container style={{maxWidth: 400}}>
<EventEdit collections={collectionsCalendar} onSave={this.onEventSave} />
</Container>
)}
/>
<Route
path={routeResolver.getRoute('pim.events._id')}
exact={true}

@ -0,0 +1,29 @@
import * as EteSync from './api/EteSync';
import { CredentialsData, createEntries } from './store';
export function createJournalEntry(
etesync: CredentialsData,
journal: EteSync.Journal,
existingEntries: Array<EteSync.Entry>,
content: string) {
let syncEntry = new EteSync.SyncEntry();
syncEntry.action = EteSync.SyncEntryAction.Add;
syncEntry.content = content;
const derived = etesync.encryptionKey;
let prevUid: string | null = null;
const entries = existingEntries;
if (entries.length > 0) {
prevUid = entries[entries.length - 1].uid;
}
const cryptoManager = new EteSync.CryptoManager(derived, journal.uid, journal.version);
let entry = new EteSync.Entry();
entry.setSyncEntry(cryptoManager, syncEntry, prevUid);
return createEntries(etesync, journal.uid, [entry], prevUid);
}
Loading…
Cancel
Save