diff --git a/src/AddressBook.tsx b/src/AddressBook.tsx new file mode 100644 index 0000000..35dc2aa --- /dev/null +++ b/src/AddressBook.tsx @@ -0,0 +1,42 @@ +import * as React from 'react'; +import { List, ListItem } from 'material-ui/List'; + +import * as ICAL from 'ical.js'; + +class AddressBook extends React.Component { + props: { + entries: Map, + onItemClick: (contact: ICAL.Component) => void, + }; + + render() { + let entries = Array.from(this.props.entries.values()).sort((_a, _b) => { + const a = _a.getFirstPropertyValue('fn'); + const b = _b.getFirstPropertyValue('fn'); + + if (a < b) { + return -1; + } else if (a > b) { + return 1; + } else { + return 0; + } + }); + + let itemList = entries.map((entry) => { + const uid = entry.getFirstPropertyValue('uid'); + const name = entry.getFirstPropertyValue('fn'); + return ( + (this.props.onItemClick(entry))} /> + ); + }); + + return ( + + {itemList} + + ); + } +} + +export default AddressBook; diff --git a/src/JournalAddressBook.tsx b/src/JournalAddressBook.tsx index 9e2587b..32df51d 100644 --- a/src/JournalAddressBook.tsx +++ b/src/JournalAddressBook.tsx @@ -1,25 +1,34 @@ import * as React from 'react'; -import { Route, Switch } from 'react-router'; -import { List, ListItem } from 'material-ui/List'; -import { Link } from 'react-router-dom'; +import { Route, Switch, withRouter } from 'react-router'; import * as ICAL from 'ical.js'; import * as EteSync from './api/EteSync'; import { routeResolver } from './App'; + +import AddressBook from './AddressBook'; import Contact from './Contact'; class JournalAddressBook extends React.Component { - static defaultProps = { - prevUid: null, - }; - props: { journal: EteSync.Journal, entries: Array, + history?: any, }; + constructor(props: any) { + super(props); + this.contactClicked = this.contactClicked.bind(this); + } + + contactClicked(contact: ICAL.Component) { + const uid = contact.getFirstPropertyValue('uid'); + + this.props.history.push( + routeResolver.getRoute('journals._id.items._id', { journalUid: this.props.journal.uid, itemUid: uid })); + } + render() { if (this.props.journal === undefined) { return (
Loading
); @@ -40,32 +49,6 @@ class JournalAddressBook extends React.Component { } } - let entries = Array.from(items.values()).sort((_a, _b) => { - const a = _a.getFirstPropertyValue('fn'); - const b = _b.getFirstPropertyValue('fn'); - - if (a < b) { - return -1; - } else if (a > b) { - return 1; - } else { - return 0; - } - }); - - let itemList = entries.map((entry) => { - const uid = entry.getFirstPropertyValue('uid'); - const name = entry.getFirstPropertyValue('fn'); - return ( - - - - ); - }); - return (
@@ -73,9 +56,7 @@ class JournalAddressBook extends React.Component { path={routeResolver.getRoute('journals._id')} exact={true} render={() => ( - - {itemList} - + ) } /> @@ -95,4 +76,4 @@ class JournalAddressBook extends React.Component { } } -export default JournalAddressBook; +export default withRouter(JournalAddressBook);