Contacts: Add a button to copy fields to clipboard

Fixes #39
master
Tal Leibman 5 years ago committed by Tom Hacohen
parent ea67bb4b87
commit 6d45c31f98

@ -7,10 +7,12 @@ import IconDate from '@material-ui/icons/DateRange';
import CommunicationCall from '@material-ui/icons/Call'; import CommunicationCall from '@material-ui/icons/Call';
import CommunicationChatBubble from '@material-ui/icons/ChatBubble'; import CommunicationChatBubble from '@material-ui/icons/ChatBubble';
import CommunicationEmail from '@material-ui/icons/Email'; import CommunicationEmail from '@material-ui/icons/Email';
import AssignmentIcon from '@material-ui/icons/Assignment';
import PimItemHeader from './PimItemHeader'; import PimItemHeader from './PimItemHeader';
import { ContactType } from '../pim-types'; import { ContactType } from '../pim-types';
import { IconButton } from '@material-ui/core';
class Contact extends React.PureComponent { class Contact extends React.PureComponent {
public props: { public props: {
@ -40,15 +42,30 @@ class Contact extends React.PureComponent {
return contact.comp.getAllProperties(propName).map((prop, idx) => { return contact.comp.getAllProperties(propName).map((prop, idx) => {
const type = prop.toJSON()[1].type; const type = prop.toJSON()[1].type;
const values = prop.getValues().map((val) => ( const values = prop.getValues().map((val) => {
<ListItem const primaryText = primaryTransform ? primaryTransform(val, type) : val;
key={idx} const clipboardButton = (
href={valueToHref ? valueToHref(val, type) : undefined} <IconButton
primaryText={primaryTransform ? primaryTransform(val, type) : val} onClick={(e) => {
secondaryText={secondaryTransform ? secondaryTransform(val, type) : type} e.preventDefault();
{...props} (window as any).navigator.clipboard.writeText(primaryText);
/> }}
)); >
<AssignmentIcon />
</IconButton>
);
return (
<ListItem
key={idx}
href={valueToHref ? valueToHref(val, type) : undefined}
primaryText={primaryText}
rightIcon={clipboardButton}
secondaryText={secondaryTransform ? secondaryTransform(val, type) : type}
{...props}
/>
);
});
return values; return values;
}); });
} }
@ -57,7 +74,6 @@ class Contact extends React.PureComponent {
'tel', 'tel',
{ {
leftIcon: <CommunicationCall />, leftIcon: <CommunicationCall />,
rightIcon: <CommunicationChatBubble />,
}, },
(x) => ('tel:' + x) (x) => ('tel:' + x)
)); ));
@ -111,7 +127,7 @@ class Contact extends React.PureComponent {
'prodid', 'uid', 'fn', 'n', 'version', 'photo']; 'prodid', 'uid', 'fn', 'n', 'version', 'photo'];
const theRest = contact.comp.getAllProperties().filter((prop) => ( const theRest = contact.comp.getAllProperties().filter((prop) => (
skips.indexOf(prop.name) === -1 skips.indexOf(prop.name) === -1
)).map((prop, idx) => { )).map((prop, idx) => {
const values = prop.getValues().map((_val) => { const values = prop.getValues().map((_val) => {
const val = (_val instanceof String) ? _val : _val.toString(); const val = (_val instanceof String) ? _val : _val.toString();
return ( return (
@ -147,14 +163,14 @@ class Contact extends React.PureComponent {
<div> <div>
<PimItemHeader text={name}> <PimItemHeader text={name}>
{lastModified && ( {lastModified && (
<span style={{fontSize: '90%'}}>{lastModified}</span> <span style={{ fontSize: '90%' }}>{lastModified}</span>
)} )}
</PimItemHeader> </PimItemHeader>
{lists.map((list, idx) => ( {lists.map((list, idx) => (
<React.Fragment key={idx}> <React.Fragment key={idx}>
{listIfNotEmpty(list)} {listIfNotEmpty(list)}
</React.Fragment> </React.Fragment>
))} ))}
<List> <List>
{theRest} {theRest}
</List> </List>

Loading…
Cancel
Save