From a8bdc076d941a42ad3533d02af9be65117ae43d5 Mon Sep 17 00:00:00 2001 From: Tal Leibman Date: Sat, 23 Nov 2019 15:50:45 +0200 Subject: [PATCH] JournalsList: change to a functional component --- src/Journals/JournalsList.tsx | 122 ++++++++++++++++------------------ 1 file changed, 57 insertions(+), 65 deletions(-) diff --git a/src/Journals/JournalsList.tsx b/src/Journals/JournalsList.tsx index 2b25056..1587c0f 100644 --- a/src/Journals/JournalsList.tsx +++ b/src/Journals/JournalsList.tsx @@ -15,75 +15,67 @@ import { routeResolver } from '../App'; import { JournalsData, UserInfoData, CredentialsData } from '../store'; -class JournalsList extends React.PureComponent { - public props: { - etesync: CredentialsData; - journals: JournalsData; - userInfo: UserInfoData; - history: History; - }; +interface PropsType { + etesync: CredentialsData; + journals: JournalsData; + userInfo: UserInfoData; + history: History; +} - constructor(props: any) { - super(props); - this.journalClicked = this.journalClicked.bind(this); - } +export default function JournalsList(props: PropsType) { + const derived = props.etesync.encryptionKey; - public render() { - const derived = this.props.etesync.encryptionKey; - 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( - this.journalClicked(journal.uid)}> - {info.displayName} ({journal.uid.slice(0, 5)}) - - ); + function journalClicked(journalUid: string) { + props.history.push(routeResolver.getRoute('journals._id', { journalUid })); + } - return ret; - }, - { CALENDAR: [], - ADDRESS_BOOK: [], - TASKS: [], - }); + const journalMap = props.journals.reduce( + (ret, journal) => { + const userInfo = 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( + journalClicked(journal.uid)}> + {info.displayName} ({journal.uid.slice(0, 5)}) + + ); - return ( - - - - - - - - + return ret; + }, + { CALENDAR: [], + ADDRESS_BOOK: [], + TASKS: [], + }); - + return ( + + + + + + + + - - - - ); - } - - private journalClicked(journalUid: string) { - this.props.history.push(routeResolver.getRoute('journals._id', { journalUid })); - } -} + -export default JournalsList; + + + + ); +} \ No newline at end of file