From da935c0836f0d55b75d0be56d60ff90d85274587 Mon Sep 17 00:00:00 2001 From: Tom Hacohen Date: Wed, 13 Dec 2017 14:09:24 +0000 Subject: [PATCH] Fix editing events of a journal other than the default. --- src/ContactEdit.tsx | 13 +++++++++---- src/EventEdit.tsx | 14 ++++++++++---- src/Pim.tsx | 2 ++ src/journal-processors.tsx | 6 ++++++ 4 files changed, 27 insertions(+), 8 deletions(-) diff --git a/src/ContactEdit.tsx b/src/ContactEdit.tsx index 3f14862..3a4ecc2 100644 --- a/src/ContactEdit.tsx +++ b/src/ContactEdit.tsx @@ -150,7 +150,9 @@ class ContactEdit extends React.Component { this.state.uid = uuid.v4(); } - if (props.collections[0]) { + if (props.initialCollection) { + this.state.journalUid = props.initialCollection; + } else if (props.collections[0]) { this.state.journalUid = props.collections[0].uid; } this.onSubmit = this.onSubmit.bind(this); @@ -162,9 +164,12 @@ class ContactEdit extends React.Component { } componentWillReceiveProps(nextProps: any) { - if (this.props.collections !== nextProps.collections) { - if (nextProps.collections[0]) { - this.setState({journalUid: nextProps.collections[0].uid}); + if ((this.props.collections !== nextProps.collections) || + (this.props.initialCollection !== nextProps.initialCollection)) { + if (nextProps.initialCollection) { + this.state.journalUid = nextProps.initialCollection; + } else if (nextProps.collections[0]) { + this.state.journalUid = nextProps.collections[0].uid; } } } diff --git a/src/EventEdit.tsx b/src/EventEdit.tsx index c01a907..e066e18 100644 --- a/src/EventEdit.tsx +++ b/src/EventEdit.tsx @@ -59,9 +59,12 @@ class EventEdit extends React.Component { this.state.uid = uuid.v4(); } - if (this.props.collections[0]) { + if (props.initialCollection) { + this.state.journalUid = props.initialCollection; + } else if (props.collections[0]) { this.state.journalUid = props.collections[0].uid; } + this.onSubmit = this.onSubmit.bind(this); this.handleChange = this.handleChange.bind(this); this.handleInputChange = this.handleInputChange.bind(this); @@ -69,9 +72,12 @@ class EventEdit extends React.Component { } componentWillReceiveProps(nextProps: any) { - if (this.props.collections !== nextProps.collections) { - if (nextProps.collections[0]) { - this.setState({journalUid: nextProps.collections[0].uid}); + if ((this.props.collections !== nextProps.collections) || + (this.props.initialCollection !== nextProps.initialCollection)) { + if (nextProps.initialCollection) { + this.state.journalUid = nextProps.initialCollection; + } else if (nextProps.collections[0]) { + this.state.journalUid = nextProps.collections[0].uid; } } } diff --git a/src/Pim.tsx b/src/Pim.tsx index 0dcf15a..bae59af 100644 --- a/src/Pim.tsx +++ b/src/Pim.tsx @@ -156,6 +156,7 @@ class Pim extends React.Component { render={({match}) => ( (