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.
83 lines
2.4 KiB
TypeScript
83 lines
2.4 KiB
TypeScript
7 years ago
|
import * as React from 'react';
|
||
6 years ago
|
import { History } from 'history';
|
||
7 years ago
|
|
||
6 years ago
|
import { List, ListItem } from '../widgets/List';
|
||
7 years ago
|
|
||
6 years ago
|
import * as EteSync from '../api/EteSync';
|
||
7 years ago
|
|
||
6 years ago
|
import { routeResolver } from '../App';
|
||
7 years ago
|
|
||
6 years ago
|
import { JournalsData, UserInfoData, CredentialsData } from '../store';
|
||
6 years ago
|
|
||
6 years ago
|
class JournalsList extends React.PureComponent {
|
||
7 years ago
|
props: {
|
||
|
etesync: CredentialsData;
|
||
|
journals: JournalsData;
|
||
7 years ago
|
userInfo: UserInfoData;
|
||
6 years ago
|
history: History;
|
||
7 years ago
|
};
|
||
|
|
||
|
constructor(props: any) {
|
||
|
super(props);
|
||
6 years ago
|
this.journalClicked = this.journalClicked.bind(this);
|
||
7 years ago
|
}
|
||
|
|
||
|
render() {
|
||
|
const derived = this.props.etesync.encryptionKey;
|
||
7 years ago
|
let asymmetricCryptoManager: EteSync.AsymmetricCryptoManager;
|
||
7 years ago
|
const journalMap = this.props.journals.reduce(
|
||
|
(ret, journal) => {
|
||
7 years ago
|
let cryptoManager: EteSync.CryptoManager;
|
||
7 years ago
|
if (journal.key) {
|
||
7 years ago
|
if (!asymmetricCryptoManager) {
|
||
|
const userInfo = this.props.userInfo;
|
||
|
const keyPair = userInfo.getKeyPair(new EteSync.CryptoManager(derived, 'userInfo', userInfo.version));
|
||
|
asymmetricCryptoManager = new EteSync.AsymmetricCryptoManager(keyPair);
|
||
|
}
|
||
|
const derivedJournalKey = asymmetricCryptoManager.decryptBytes(journal.key);
|
||
|
cryptoManager = EteSync.CryptoManager.fromDerivedKey(derivedJournalKey, journal.version);
|
||
7 years ago
|
} else {
|
||
7 years ago
|
cryptoManager = new EteSync.CryptoManager(derived, journal.uid, journal.version);
|
||
7 years ago
|
}
|
||
7 years ago
|
let info = journal.getInfo(cryptoManager);
|
||
|
ret[info.type] = ret[info.type] || [];
|
||
|
ret[info.type].push(
|
||
6 years ago
|
<ListItem key={journal.uid} onClick={() => this.journalClicked(journal.uid)}>
|
||
7 years ago
|
{info.displayName} ({journal.uid.slice(0, 5)})
|
||
|
</ListItem>
|
||
|
);
|
||
7 years ago
|
|
||
|
return ret;
|
||
|
},
|
||
|
{ CALENDAR: [],
|
||
6 years ago
|
ADDRESS_BOOK: [],
|
||
|
TASKS: []
|
||
7 years ago
|
});
|
||
7 years ago
|
|
||
|
return (
|
||
6 years ago
|
<List>
|
||
7 years ago
|
<ListItem
|
||
|
primaryText="Address Books"
|
||
|
nestedItems={journalMap.ADDRESS_BOOK}
|
||
|
/>
|
||
|
|
||
|
<ListItem
|
||
|
primaryText="Calendars"
|
||
|
nestedItems={journalMap.CALENDAR}
|
||
|
/>
|
||
6 years ago
|
|
||
|
<ListItem
|
||
|
primaryText="Tasks"
|
||
|
nestedItems={journalMap.TASKS}
|
||
|
/>
|
||
6 years ago
|
</List>
|
||
7 years ago
|
);
|
||
|
}
|
||
6 years ago
|
|
||
|
private journalClicked(journalUid: string) {
|
||
|
this.props.history.push(routeResolver.getRoute('journals._id', { journalUid: journalUid }));
|
||
|
}
|
||
7 years ago
|
}
|
||
|
|
||
6 years ago
|
export default JournalsList;
|