Show raw journal items when clicked.

master
Tom Hacohen 7 years ago
parent 00d8b43cc5
commit fe6490a098

@ -1,5 +1,7 @@
import * as React from 'react'; import * as React from 'react';
import { List, ListItem } from 'material-ui/List'; import { List, ListItem } from 'material-ui/List';
import Dialog from 'material-ui/Dialog';
import FlatButton from 'material-ui/FlatButton';
import IconAdd from 'material-ui/svg-icons/content/add'; import IconAdd from 'material-ui/svg-icons/content/add';
import IconDelete from 'material-ui/svg-icons/action/delete'; import IconDelete from 'material-ui/svg-icons/action/delete';
import IconEdit from 'material-ui/svg-icons/editor/mode-edit'; import IconEdit from 'material-ui/svg-icons/editor/mode-edit';
@ -13,11 +15,20 @@ export class JournalViewEntries extends React.Component {
prevUid: null, prevUid: null,
}; };
state: {
dialog?: string;
};
props: { props: {
journal: EteSync.Journal, journal: EteSync.Journal,
entries: Array<EteSync.SyncEntry>, entries: Array<EteSync.SyncEntry>,
}; };
constructor(props: any) {
super(props);
this.state = {};
}
render() { render() {
if (this.props.journal === undefined) { if (this.props.journal === undefined) {
return (<div>Loading</div>); return (<div>Loading</div>);
@ -35,41 +46,59 @@ export class JournalViewEntries extends React.Component {
icon = (<IconDelete color="#F20C0C" />); icon = (<IconDelete color="#F20C0C" />);
} }
let name;
let uid;
if (comp.name === 'vcalendar') { if (comp.name === 'vcalendar') {
const vevent = new ICAL.Event(comp.getFirstSubcomponent('vevent')); const vevent = new ICAL.Event(comp.getFirstSubcomponent('vevent'));
return ( name = vevent.summary;
<ListItem uid = vevent.uid;
key={idx}
leftIcon={icon}
primaryText={vevent.summary}
secondaryText={vevent.uid}
/>
);
} else if (comp.name === 'vcard') { } else if (comp.name === 'vcard') {
const vcard = comp; const vcard = comp;
const name = vcard.getFirstPropertyValue('fn'); name = vcard.getFirstPropertyValue('fn');
const uid = vcard.getFirstPropertyValue('uid'); uid = vcard.getFirstPropertyValue('uid');
} else {
name = 'Error processing entry';
uid = '';
}
return ( return (
<ListItem <ListItem
key={idx} key={idx}
leftIcon={icon} leftIcon={icon}
primaryText={name} primaryText={name}
secondaryText={uid} secondaryText={uid}
onClick={() => {
this.setState({
dialog: syncEntry.content
});
}}
/> />
); );
} else {
return (
<ListItem
key={idx}
leftIcon={icon}
primaryText="Error processing entry"
/>
);
}
}).reverse(); }).reverse();
const actions = [(
<FlatButton
label="Close"
primary={true}
onClick={() => {
this.setState({dialog: undefined});
}}
/>
),
];
return ( return (
<div> <div>
<Dialog
title="Raw Content"
actions={actions}
modal={false}
autoScrollBodyContent={true}
open={this.state.dialog !== undefined}
onRequestClose={() => {
this.setState({dialog: undefined});
}}
>
<pre>{this.state.dialog}</pre>
</Dialog>
<List> <List>
{entries} {entries}
</List> </List>

@ -170,11 +170,13 @@ export enum SyncEntryAction {
} }
export class SyncEntry { export class SyncEntry {
uid?: string;
action: SyncEntryAction; action: SyncEntryAction;
content: string; content: string;
constructor(json?: any) { constructor(json?: any, uid?: string) {
CastJson(json, this); CastJson(json, this);
this.uid = uid;
} }
} }
@ -195,7 +197,7 @@ export class Entry extends BaseJournal<EntryJson> {
this._content = JSON.parse(cryptoManager.decrypt(this._encrypted)); this._content = JSON.parse(cryptoManager.decrypt(this._encrypted));
} }
return new SyncEntry(this._content); return new SyncEntry(this._content, this.uid);
} }
verify(cryptoManager: CryptoManager, prevUid: string | null) { verify(cryptoManager: CryptoManager, prevUid: string | null) {

Loading…
Cancel
Save