import * as React from 'react'; import { Route, Redirect } from 'react-router'; import * as ICAL from 'ical.js'; import { EteSyncContextType } from './EteSyncContext'; import * as EteSync from './api/EteSync'; import { routeResolver } from './App'; export class JournalView extends React.Component { static defaultProps = { prevUid: null, }; state: { journal?: EteSync.Journal, entries: Array, }; props: { etesync: EteSyncContextType match: any, prevUid?: string | null, }; constructor(props: any) { super(props); this.state = { entries: [], }; } componentDidMount() { const credentials = this.props.etesync.credentials; const apiBase = this.props.etesync.serviceApiUrl; const journal = this.props.match.params.journalUid; let journalManager = new EteSync.JournalManager(credentials, apiBase); journalManager.fetch(journal).then((journalInstance) => { this.setState(Object.assign({}, this.state, { journal: journalInstance })); }); let entryManager = new EteSync.EntryManager(credentials, apiBase, journal); entryManager.list(this.props.prevUid || null).then((entries) => { this.setState(Object.assign({}, this.state, { entries })); }); } render() { if (this.state.journal === undefined) { return (
Loading
); } const derived = this.props.etesync.encryptionKey; const journal = this.state.journal; let prevUid = this.props.prevUid || null; const journals = this.state.entries.map((entry) => { let cryptoManager = new EteSync.CryptoManager(derived, journal.uid, journal.version); let syncEntry = entry.getSyncEntry(cryptoManager, prevUid); prevUid = entry.uid; const comp = new ICAL.Component(ICAL.parse(syncEntry.content)); if (comp.name === 'vcalendar') { const vevent = new ICAL.Event(comp.getFirstSubcomponent('vevent')); return (
  • {syncEntry.action}: {vevent.summary} ({vevent.uid})
  • ); } else if (comp.name === 'vcard') { const vcard = comp; const name = vcard.getFirstPropertyValue('fn'); const uid = vcard.getFirstPropertyValue('uid'); return (
  • {syncEntry.action}: {name} ({uid})
  • ); } else { return (
  • {syncEntry.action}: {syncEntry.content}
  • ); } }).reverse(); return (
    } />

    Welcome to Journal!

      {journals}
    } />
    ); } }