From 81c3f4d27eeea61b5756e1ffe008353537474e9f Mon Sep 17 00:00:00 2001 From: Tom Hacohen Date: Tue, 12 Dec 2017 18:55:09 +0000 Subject: [PATCH] Add a way to create new events. --- src/EventEdit.tsx | 12 +++++++++--- src/Pim.tsx | 35 ++++++++++++++++++++++++++++++++++- src/etesync-helpers.tsx | 29 +++++++++++++++++++++++++++++ 3 files changed, 72 insertions(+), 4 deletions(-) create mode 100644 src/etesync-helpers.tsx diff --git a/src/EventEdit.tsx b/src/EventEdit.tsx index 53ad48b..1e9acdb 100644 --- a/src/EventEdit.tsx +++ b/src/EventEdit.tsx @@ -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 diff --git a/src/Pim.tsx b/src/Pim.tsx index 90c11c1..314c718 100644 --- a/src/Pim.tsx +++ b/src/Pim.tsx @@ -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 = []; 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 { )} /> + ( + + + + )} + /> , + 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); +}