From f74ec6f05a3b8e859c88b9b5d93c53cb7acc96b7 Mon Sep 17 00:00:00 2001 From: Tom Hacohen Date: Sun, 17 Dec 2017 12:02:31 +0000 Subject: [PATCH] Merge JournalAddressbook and JournalCalendar. --- src/Journal/JournalAddressBook.tsx | 66 ----------------------------- src/Journal/JournalCalendar.tsx | 67 ------------------------------ src/Journal/index.tsx | 14 ++++++- src/Journal/journalView.tsx | 63 ++++++++++++++++++++++++++++ src/Pim/index.tsx | 4 +- src/components/Contact.tsx | 6 +-- src/components/Event.tsx | 16 +++---- 7 files changed, 88 insertions(+), 148 deletions(-) delete mode 100644 src/Journal/JournalAddressBook.tsx delete mode 100644 src/Journal/JournalCalendar.tsx create mode 100644 src/Journal/journalView.tsx diff --git a/src/Journal/JournalAddressBook.tsx b/src/Journal/JournalAddressBook.tsx deleted file mode 100644 index 7a24da6..0000000 --- a/src/Journal/JournalAddressBook.tsx +++ /dev/null @@ -1,66 +0,0 @@ -import * as React from 'react'; -import { Route, Switch, withRouter } from 'react-router'; - -import * as EteSync from '../api/EteSync'; - -import { routeResolver } from '../App'; - -import { History } from 'history'; - -import AddressBook from '../components/AddressBook'; -import Contact from '../components/Contact'; - -import { ContactType } from '../pim-types'; - -function objValues(obj: any) { - return Object.keys(obj).map((x) => obj[x]); -} - -class JournalAddressBook extends React.PureComponent { - props: { - journal: EteSync.Journal, - entries: {[key: string]: ContactType}, - history?: History, - }; - - constructor(props: any) { - super(props); - this.contactClicked = this.contactClicked.bind(this); - } - - contactClicked(contact: ContactType) { - const uid = contact.uid; - - this.props.history!.push( - routeResolver.getRoute('journals._id.items._id', { journalUid: this.props.journal.uid, itemUid: uid })); - } - - render() { - let items = this.props.entries; - - return ( - - ( - - ) - } - /> - { - - return ( - - ); - }} - /> - - ); - } -} - -export default withRouter(JournalAddressBook); diff --git a/src/Journal/JournalCalendar.tsx b/src/Journal/JournalCalendar.tsx deleted file mode 100644 index eed33d9..0000000 --- a/src/Journal/JournalCalendar.tsx +++ /dev/null @@ -1,67 +0,0 @@ -import * as React from 'react'; -import { Route, Switch, withRouter } from 'react-router'; - -import { History } from 'history'; - -import { routeResolver } from '../App'; - -import { historyPersistor } from '../persist-state-history'; - -import Calendar from '../components/Calendar'; -import Event from '../components/Event'; - -import { EventType } from '../pim-types'; - -import * as EteSync from '../api/EteSync'; - -function objValues(obj: any) { - return Object.keys(obj).map((x) => obj[x]); -} - -const PersistCalendar = historyPersistor('Calendar')(Calendar); - -class JournalCalendar extends React.PureComponent { - props: { - journal: EteSync.Journal, - entries: {[key: string]: EventType}, - history?: History, - }; - - constructor(props: any) { - super(props); - this.eventClicked = this.eventClicked.bind(this); - } - - eventClicked(event: EventType) { - const uid = event.uid; - - this.props.history!.push( - routeResolver.getRoute('journals._id.items._id', { journalUid: this.props.journal.uid, itemUid: uid })); - } - - render() { - let items = this.props.entries; - - return ( - - ( - - ) - } - /> - ( - - )} - /> - - ); - } -} - -export default withRouter(JournalCalendar); diff --git a/src/Journal/index.tsx b/src/Journal/index.tsx index c5c7412..b9a92cb 100644 --- a/src/Journal/index.tsx +++ b/src/Journal/index.tsx @@ -1,13 +1,17 @@ import * as React from 'react'; import { Tabs, Tab } from 'material-ui/Tabs'; +import AddressBook from '../components/AddressBook'; +import Contact from '../components/Contact'; +import Calendar from '../components/Calendar'; +import Event from '../components/Event'; + import Container from '../widgets/Container'; import SecondaryHeader from '../components/SecondaryHeader'; import JournalEntries from '../components/JournalEntries'; -import JournalAddressBook from './JournalAddressBook'; -import JournalCalendar from './JournalCalendar'; +import journalView from './journalView'; import { syncEntriesToItemMap, syncEntriesToCalendarItemMap } from '../journal-processors'; @@ -15,6 +19,8 @@ import { SyncInfo } from '../SyncGate'; import { match } from 'react-router'; +import { historyPersistor } from '../persist-state-history'; + interface PropsType { syncInfo: SyncInfo; match: match; @@ -23,6 +29,10 @@ interface PropsType { interface PropsTypeInner extends PropsType { } +const JournalAddressBook = journalView(AddressBook, Contact); +const PersistCalendar = historyPersistor('Calendar')(Calendar); +const JournalCalendar = journalView(PersistCalendar, Event); + class Journal extends React.PureComponent { static defaultProps = { prevUid: null, diff --git a/src/Journal/journalView.tsx b/src/Journal/journalView.tsx new file mode 100644 index 0000000..4b20217 --- /dev/null +++ b/src/Journal/journalView.tsx @@ -0,0 +1,63 @@ +import * as React from 'react'; +import { Route, Switch, withRouter } from 'react-router'; + +import * as EteSync from '../api/EteSync'; + +import { routeResolver } from '../App'; + +import { History } from 'history'; + +function objValues(obj: any) { + return Object.keys(obj).map((x) => obj[x]); +} + +export function journalView(JournalList: any, JournalItem: any) { + return withRouter(class extends React.PureComponent { + props: { + journal: EteSync.Journal, + entries: {[key: string]: any}, + history?: History, + }; + + constructor(props: any) { + super(props); + this.itemClicked = this.itemClicked.bind(this); + } + + itemClicked(contact: any) { + const uid = contact.uid; + + this.props.history!.push( + routeResolver.getRoute('journals._id.items._id', { journalUid: this.props.journal.uid, itemUid: uid })); + } + + render() { + let items = this.props.entries; + + return ( + + ( + + ) + } + /> + { + + return ( + + ); + }} + /> + + ); + } + }); +} + +export default journalView; diff --git a/src/Pim/index.tsx b/src/Pim/index.tsx index fb2f98c..a7b25b9 100644 --- a/src/Pim/index.tsx +++ b/src/Pim/index.tsx @@ -168,7 +168,7 @@ class Pim extends React.PureComponent { } /> - + )} /> @@ -212,7 +212,7 @@ class Pim extends React.PureComponent { } /> - + )} /> diff --git a/src/components/Contact.tsx b/src/components/Contact.tsx index 0ffd7ad..11cf674 100644 --- a/src/components/Contact.tsx +++ b/src/components/Contact.tsx @@ -15,15 +15,15 @@ import { ContactType } from '../pim-types'; class Contact extends React.PureComponent { props: { - contact?: ContactType, + item?: ContactType, }; render() { - if (this.props.contact === undefined) { + if (this.props.item === undefined) { throw Error('Contact should be defined!'); } - const contact = this.props.contact; + const contact = this.props.item; const name = contact.fn; const revProp = contact.comp.getFirstProperty('rev'); diff --git a/src/components/Event.tsx b/src/components/Event.tsx index 440d94d..adf8908 100644 --- a/src/components/Event.tsx +++ b/src/components/Event.tsx @@ -37,11 +37,11 @@ function formatDateRange(start: ICAL.Time, end: ICAL.Time) { class Event extends React.PureComponent { props: { - event?: EventType, + item?: EventType, }; render() { - if (this.props.event === undefined) { + if (this.props.item === undefined) { throw Error('Event should be defined!'); } @@ -53,15 +53,15 @@ class Event extends React.PureComponent { return ( - -
{formatDateRange(this.props.event.startDate, this.props.event.endDate)}
+ +
{formatDateRange(this.props.item.startDate, this.props.item.endDate)}

-
{this.props.event.location}
+
{this.props.item.location}
-
{this.props.event.description}
- {(this.props.event.attendees.length > 0) && ( -
Attendees: {this.props.event.attendees.map((x) => (x.getFirstValue())).join(', ')}
)} +
{this.props.item.description}
+ {(this.props.item.attendees.length > 0) && ( +
Attendees: {this.props.item.attendees.map((x) => (x.getFirstValue())).join(', ')}
)}
);