From fddf39244d49ab908b680a728522ca267bbd2e69 Mon Sep 17 00:00:00 2001 From: Tom Hacohen Date: Mon, 4 Dec 2017 19:18:13 +0000 Subject: [PATCH] Add a contact page. --- src/App.tsx | 2 +- src/JournalViewAddressBook.tsx | 41 ++++++++++++++-- src/JournalViewContact.tsx | 86 ++++++++++++++++++++++++++++++++++ src/ical.js.d.ts | 10 ++++ 4 files changed, 133 insertions(+), 6 deletions(-) create mode 100644 src/JournalViewContact.tsx diff --git a/src/App.tsx b/src/App.tsx index 747a5a6..4f36995 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -51,7 +51,7 @@ export const routeResolver = new RouteResolver({ items: { _base: 'items', _id: { - _base: ':entryUid', + _base: ':itemUid', }, }, entries: { diff --git a/src/JournalViewAddressBook.tsx b/src/JournalViewAddressBook.tsx index fd7612c..971967f 100644 --- a/src/JournalViewAddressBook.tsx +++ b/src/JournalViewAddressBook.tsx @@ -1,9 +1,15 @@ import * as React from 'react'; +import { Route, Switch } from 'react-router'; +import { List, ListItem } from 'material-ui/List'; +import { Link } from 'react-router-dom'; import * as ICAL from 'ical.js'; import * as EteSync from './api/EteSync'; +import { routeResolver } from './App'; +import { JournalViewContact } from './JournalViewContact'; + export class JournalViewAddressBook extends React.Component { static defaultProps = { prevUid: null, @@ -47,18 +53,43 @@ export class JournalViewAddressBook extends React.Component { } }); - let itemList = entries.map((entry, idx) => { + let itemList = entries.map((entry) => { + const uid = entry.getFirstPropertyValue('uid'); const name = entry.getFirstPropertyValue('fn'); return ( -
  • {name}
  • + + + ); }); return (
    -
      - {itemList} -
    + + ( + + {itemList} + + ) + } + /> + { + + return ( + + ); + }} + /> +
    ); } diff --git a/src/JournalViewContact.tsx b/src/JournalViewContact.tsx new file mode 100644 index 0000000..1885238 --- /dev/null +++ b/src/JournalViewContact.tsx @@ -0,0 +1,86 @@ +import * as React from 'react'; +import { List, ListItem } from 'material-ui/List'; +import Divider from 'material-ui/Divider'; +import CommunicationCall from 'material-ui/svg-icons/communication/call'; +import CommunicationChatBubble from 'material-ui/svg-icons/communication/chat-bubble'; +import CommunicationEmail from 'material-ui/svg-icons/communication/email'; +import { indigo500 } from 'material-ui/styles/colors'; + +import * as ICAL from 'ical.js'; + +export class JournalViewContact extends React.Component { + props: { + contact?: ICAL.Component, + }; + + render() { + if (this.props.contact === undefined) { + return (
    Loading
    ); + } + + const contact = this.props.contact; + const uid = contact.getFirstPropertyValue('uid'); + const name = contact.getFirstPropertyValue('fn'); + + const phoneNumbers = contact.getAllProperties('tel').map((prop, idx) => { + const json = prop.toJSON(); + const values = prop.getValues().map((val) => ( + } + rightIcon={} + primaryText={val} + secondaryText={json[1].type} + /> + )); + return values; + }); + + const emails = contact.getAllProperties('email').map((prop, idx) => { + const json = prop.toJSON(); + const values = prop.getValues().map((val) => ( + } + primaryText={val} + secondaryText={json[1].type} + /> + )); + return values; + }); + + const skips = ['tel', 'email', 'prodid', 'uid', 'fn', 'n', 'version', 'photo']; + const theRest = contact.getAllProperties().filter((prop) => ( + skips.indexOf(prop.name) === -1 + )).map((prop, idx) => { + const values = prop.getValues().map((_val) => { + const val = (_val instanceof String) ? _val : _val.toString(); + return ( + + ); + }); + return values; + }); + return ( +
    +

    {name} {uid}

    + + {phoneNumbers} + + + + {emails} + + + + {theRest} + +
    + ); + } +} diff --git a/src/ical.js.d.ts b/src/ical.js.d.ts index fc05263..e0f2d9d 100644 --- a/src/ical.js.d.ts +++ b/src/ical.js.d.ts @@ -8,6 +8,8 @@ declare module 'ical.js' { getFirstSubcomponent(name?: string): Component | null; getFirstPropertyValue(name?: string): string; + + getAllProperties(name?: string): Array; } class Event { @@ -17,4 +19,12 @@ declare module 'ical.js' { constructor(component?: Component | null, options?: {strictExceptions: boolean, exepctions: Array}); } + + class Property { + name: string; + type: string; + + getValues(): Array; + toJSON(): any; + } }