Merge JournalAddressbook and JournalCalendar.

master
Tom Hacohen 7 years ago
parent dd0b214702
commit f74ec6f05a

@ -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 (
<Switch>
<Route
path={routeResolver.getRoute('journals._id')}
exact={true}
render={() => (
<AddressBook entries={objValues(items)} onItemClick={this.contactClicked} />
)
}
/>
<Route
path={routeResolver.getRoute('journals._id.items._id')}
exact={true}
render={({match}) => {
return (
<Contact contact={items[match.params.itemUid]} />
);
}}
/>
</Switch>
);
}
}
export default withRouter(JournalAddressBook);

@ -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 (
<Switch>
<Route
path={routeResolver.getRoute('journals._id')}
exact={true}
render={() => (
<PersistCalendar entries={objValues(items)} onItemClick={this.eventClicked} />
)
}
/>
<Route
path={routeResolver.getRoute('journals._id.items._id')}
exact={true}
render={({match}) => (
<Event event={items[match.params.itemUid]} />
)}
/>
</Switch>
);
}
}
export default withRouter(JournalCalendar);

@ -1,13 +1,17 @@
import * as React from 'react'; import * as React from 'react';
import { Tabs, Tab } from 'material-ui/Tabs'; 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 Container from '../widgets/Container';
import SecondaryHeader from '../components/SecondaryHeader'; import SecondaryHeader from '../components/SecondaryHeader';
import JournalEntries from '../components/JournalEntries'; import JournalEntries from '../components/JournalEntries';
import JournalAddressBook from './JournalAddressBook'; import journalView from './journalView';
import JournalCalendar from './JournalCalendar';
import { syncEntriesToItemMap, syncEntriesToCalendarItemMap } from '../journal-processors'; import { syncEntriesToItemMap, syncEntriesToCalendarItemMap } from '../journal-processors';
@ -15,6 +19,8 @@ import { SyncInfo } from '../SyncGate';
import { match } from 'react-router'; import { match } from 'react-router';
import { historyPersistor } from '../persist-state-history';
interface PropsType { interface PropsType {
syncInfo: SyncInfo; syncInfo: SyncInfo;
match: match<any>; match: match<any>;
@ -23,6 +29,10 @@ interface PropsType {
interface PropsTypeInner extends 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 { class Journal extends React.PureComponent {
static defaultProps = { static defaultProps = {
prevUid: null, prevUid: null,

@ -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 (
<Switch>
<Route
path={routeResolver.getRoute('journals._id')}
exact={true}
render={() => (
<JournalList entries={objValues(items)} onItemClick={this.itemClicked} />
)
}
/>
<Route
path={routeResolver.getRoute('journals._id.items._id')}
exact={true}
render={({match}) => {
return (
<JournalItem item={items[match.params.itemUid]} />
);
}}
/>
</Switch>
);
}
});
}
export default journalView;

@ -168,7 +168,7 @@ class Pim extends React.PureComponent {
} }
/> />
</div> </div>
<Contact contact={addressBookItems[match.params.contactUid]} /> <Contact item={addressBookItems[match.params.contactUid]} />
</Container> </Container>
)} )}
/> />
@ -212,7 +212,7 @@ class Pim extends React.PureComponent {
} }
/> />
</div> </div>
<Event event={calendarItems[match.params.eventUid]} /> <Event item={calendarItems[match.params.eventUid]} />
</Container> </Container>
)} )}
/> />

@ -15,15 +15,15 @@ import { ContactType } from '../pim-types';
class Contact extends React.PureComponent { class Contact extends React.PureComponent {
props: { props: {
contact?: ContactType, item?: ContactType,
}; };
render() { render() {
if (this.props.contact === undefined) { if (this.props.item === undefined) {
throw Error('Contact should be defined!'); throw Error('Contact should be defined!');
} }
const contact = this.props.contact; const contact = this.props.item;
const name = contact.fn; const name = contact.fn;
const revProp = contact.comp.getFirstProperty('rev'); const revProp = contact.comp.getFirstProperty('rev');

@ -37,11 +37,11 @@ function formatDateRange(start: ICAL.Time, end: ICAL.Time) {
class Event extends React.PureComponent { class Event extends React.PureComponent {
props: { props: {
event?: EventType, item?: EventType,
}; };
render() { render() {
if (this.props.event === undefined) { if (this.props.item === undefined) {
throw Error('Event should be defined!'); throw Error('Event should be defined!');
} }
@ -53,15 +53,15 @@ class Event extends React.PureComponent {
return ( return (
<React.Fragment> <React.Fragment>
<PimItemHeader text={this.props.event.summary} backgroundColor={this.props.event.color}> <PimItemHeader text={this.props.item.summary} backgroundColor={this.props.item.color}>
<div>{formatDateRange(this.props.event.startDate, this.props.event.endDate)}</div> <div>{formatDateRange(this.props.item.startDate, this.props.item.endDate)}</div>
<br/> <br/>
<div><u>{this.props.event.location}</u></div> <div><u>{this.props.item.location}</u></div>
</PimItemHeader> </PimItemHeader>
<div style={style.content}> <div style={style.content}>
<div>{this.props.event.description}</div> <div>{this.props.item.description}</div>
{(this.props.event.attendees.length > 0) && ( {(this.props.item.attendees.length > 0) && (
<div>Attendees: {this.props.event.attendees.map((x) => (x.getFirstValue())).join(', ')}</div>)} <div>Attendees: {this.props.item.attendees.map((x) => (x.getFirstValue())).join(', ')}</div>)}
</div> </div>
</React.Fragment> </React.Fragment>
); );

Loading…
Cancel
Save