JournalsList: change to a functional component

master
Tal Leibman 5 years ago committed by Tom Hacohen
parent 2c02ec839e
commit a8bdc076d9

@ -15,75 +15,67 @@ import { routeResolver } from '../App';
import { JournalsData, UserInfoData, CredentialsData } from '../store'; import { JournalsData, UserInfoData, CredentialsData } from '../store';
class JournalsList extends React.PureComponent { interface PropsType {
public props: { etesync: CredentialsData;
etesync: CredentialsData; journals: JournalsData;
journals: JournalsData; userInfo: UserInfoData;
userInfo: UserInfoData; history: History;
history: History; }
};
constructor(props: any) { export default function JournalsList(props: PropsType) {
super(props); const derived = props.etesync.encryptionKey;
this.journalClicked = this.journalClicked.bind(this);
}
public render() { function journalClicked(journalUid: string) {
const derived = this.props.etesync.encryptionKey; props.history.push(routeResolver.getRoute('journals._id', { journalUid }));
const journalMap = this.props.journals.reduce( }
(ret, journal) => {
const userInfo = this.props.userInfo;
const keyPair = userInfo.getKeyPair(userInfo.getCryptoManager(derived));
const cryptoManager = journal.getCryptoManager(derived, keyPair);
const info = journal.getInfo(cryptoManager);
ret[info.type] = ret[info.type] || [];
ret[info.type].push(
<ListItem key={journal.uid} onClick={() => this.journalClicked(journal.uid)}>
{info.displayName} ({journal.uid.slice(0, 5)})
</ListItem>
);
return ret; const journalMap = props.journals.reduce(
}, (ret, journal) => {
{ CALENDAR: [], const userInfo = props.userInfo;
ADDRESS_BOOK: [], const keyPair = userInfo.getKeyPair(userInfo.getCryptoManager(derived));
TASKS: [], const cryptoManager = journal.getCryptoManager(derived, keyPair);
}); const info = journal.getInfo(cryptoManager);
ret[info.type] = ret[info.type] || [];
ret[info.type].push(
<ListItem key={journal.uid} onClick={() => journalClicked(journal.uid)}>
{info.displayName} ({journal.uid.slice(0, 5)})
</ListItem>
);
return ( return ret;
<Container> },
<AppBarOverride title="Journals"> { CALENDAR: [],
<IconButton ADDRESS_BOOK: [],
component={Link} TASKS: [],
title="New" });
{...{ to: routeResolver.getRoute('journals.new') }}
>
<IconAdd />
</IconButton>
</AppBarOverride>
<List>
<ListItem
primaryText="Address Books"
nestedItems={journalMap.ADDRESS_BOOK}
/>
<ListItem return (
primaryText="Calendars" <Container>
nestedItems={journalMap.CALENDAR} <AppBarOverride title="Journals">
/> <IconButton
component={Link}
title="New"
{...{ to: routeResolver.getRoute('journals.new') }}
>
<IconAdd />
</IconButton>
</AppBarOverride>
<List>
<ListItem
primaryText="Address Books"
nestedItems={journalMap.ADDRESS_BOOK}
/>
<ListItem <ListItem
primaryText="Tasks" primaryText="Calendars"
nestedItems={journalMap.TASKS} nestedItems={journalMap.CALENDAR}
/> />
</List>
</Container>
);
}
private journalClicked(journalUid: string) {
this.props.history.push(routeResolver.getRoute('journals._id', { journalUid }));
}
}
export default JournalsList; <ListItem
primaryText="Tasks"
nestedItems={journalMap.TASKS}
/>
</List>
</Container>
);
}
Loading…
Cancel
Save