You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
99 lines
2.4 KiB
TypeScript
99 lines
2.4 KiB
TypeScript
7 years ago
|
import * as React from 'react';
|
||
7 years ago
|
import { Route, Switch } from 'react-router';
|
||
|
import { List, ListItem } from 'material-ui/List';
|
||
|
import { Link } from 'react-router-dom';
|
||
7 years ago
|
|
||
|
import * as ICAL from 'ical.js';
|
||
|
|
||
|
import * as EteSync from './api/EteSync';
|
||
|
|
||
7 years ago
|
import { routeResolver } from './App';
|
||
7 years ago
|
import Contact from './Contact';
|
||
7 years ago
|
|
||
7 years ago
|
class JournalAddressBook extends React.Component {
|
||
7 years ago
|
static defaultProps = {
|
||
|
prevUid: null,
|
||
|
};
|
||
|
|
||
|
props: {
|
||
|
journal: EteSync.Journal,
|
||
|
entries: Array<EteSync.SyncEntry>,
|
||
|
};
|
||
|
|
||
|
render() {
|
||
|
if (this.props.journal === undefined) {
|
||
|
return (<div>Loading</div>);
|
||
|
}
|
||
|
|
||
7 years ago
|
let items: Map<string, ICAL.Component> = new Map();
|
||
7 years ago
|
|
||
|
for (const syncEntry of this.props.entries) {
|
||
|
let comp = new ICAL.Component(ICAL.parse(syncEntry.content));
|
||
|
|
||
|
const uid = comp.getFirstPropertyValue('uid');
|
||
|
|
||
|
if ((syncEntry.action === EteSync.SyncEntryAction.Add) ||
|
||
|
(syncEntry.action === EteSync.SyncEntryAction.Change)) {
|
||
|
items.set(uid, comp);
|
||
|
} else if (syncEntry.action === EteSync.SyncEntryAction.Delete) {
|
||
|
items.delete(uid);
|
||
|
}
|
||
|
}
|
||
|
|
||
7 years ago
|
let entries = Array.from(items.values()).sort((_a, _b) => {
|
||
7 years ago
|
const a = _a.getFirstPropertyValue('fn');
|
||
|
const b = _b.getFirstPropertyValue('fn');
|
||
|
|
||
|
if (a < b) {
|
||
|
return -1;
|
||
|
} else if (a > b) {
|
||
|
return 1;
|
||
|
} else {
|
||
|
return 0;
|
||
|
}
|
||
|
});
|
||
|
|
||
7 years ago
|
let itemList = entries.map((entry) => {
|
||
|
const uid = entry.getFirstPropertyValue('uid');
|
||
7 years ago
|
const name = entry.getFirstPropertyValue('fn');
|
||
|
return (
|
||
7 years ago
|
<Link
|
||
|
key={uid}
|
||
|
to={routeResolver.getRoute('journals._id.items._id', { journalUid: this.props.journal.uid, itemUid: uid })}
|
||
|
>
|
||
|
<ListItem primaryText={name} />
|
||
|
</Link>
|
||
7 years ago
|
);
|
||
|
});
|
||
|
|
||
|
return (
|
||
|
<div>
|
||
7 years ago
|
<Switch>
|
||
|
<Route
|
||
7 years ago
|
path={routeResolver.getRoute('journals._id')}
|
||
7 years ago
|
exact={true}
|
||
|
render={() => (
|
||
|
<List>
|
||
|
{itemList}
|
||
|
</List>
|
||
|
)
|
||
|
}
|
||
|
/>
|
||
|
<Route
|
||
|
path={routeResolver.getRoute('journals._id.items._id')}
|
||
|
exact={true}
|
||
|
render={({match}) => {
|
||
|
|
||
|
return (
|
||
7 years ago
|
<Contact contact={items.get(match.params.itemUid)} />
|
||
7 years ago
|
);
|
||
|
}}
|
||
|
/>
|
||
|
</Switch>
|
||
7 years ago
|
</div>
|
||
|
);
|
||
|
}
|
||
|
}
|
||
7 years ago
|
|
||
7 years ago
|
export default JournalAddressBook;
|