2018-10-01 09:29:36 -07:00
|
|
|
import React from 'react';
|
|
|
|
import './SocialShare.less';
|
2019-02-17 13:57:57 -08:00
|
|
|
import { Modal } from 'antd';
|
|
|
|
import CopyInput from 'components/CopyInput';
|
2018-10-01 09:29:36 -07:00
|
|
|
|
|
|
|
interface TypeOptions {
|
|
|
|
className: string;
|
2019-02-17 13:57:57 -08:00
|
|
|
humanName: string;
|
2018-10-01 09:29:36 -07:00
|
|
|
url: (url: string, title: string, text: string) => string;
|
|
|
|
}
|
|
|
|
|
|
|
|
const types: { [index: string]: TypeOptions } = {
|
|
|
|
twitter: {
|
2019-02-17 13:57:57 -08:00
|
|
|
humanName: 'Twitter',
|
|
|
|
className: 'fab fa-twitter',
|
2018-10-01 09:29:36 -07:00
|
|
|
url: (url: string, _: string, text: string) =>
|
|
|
|
`https://twitter.com/intent/tweet?url=${url}&text=${text}`,
|
|
|
|
},
|
|
|
|
reddit: {
|
2019-02-17 13:57:57 -08:00
|
|
|
humanName: 'Reddit',
|
|
|
|
className: 'fab fa-reddit',
|
2018-10-01 09:29:36 -07:00
|
|
|
url: (url: string, title: string) =>
|
|
|
|
`https://reddit.com/submit?url=${url}&title=${title}`,
|
|
|
|
},
|
|
|
|
facebook: {
|
2019-02-17 13:57:57 -08:00
|
|
|
humanName: 'Facebook',
|
|
|
|
className: 'fab fa-facebook',
|
2018-10-01 09:29:36 -07:00
|
|
|
url: (url: string) => `http://www.facebook.com/sharer.php?u=${url}`,
|
|
|
|
},
|
|
|
|
linkedin: {
|
2019-02-17 13:57:57 -08:00
|
|
|
humanName: 'LinkedIn',
|
|
|
|
className: 'fab fa-linkedin',
|
2018-10-01 09:29:36 -07:00
|
|
|
url: (url: string, title: string, text: string) =>
|
|
|
|
`https://www.linkedin.com/shareArticle?mini=true&url=${url}&title=${title}&summary=${text}`,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
interface OwnProps {
|
|
|
|
url: string;
|
|
|
|
text: string;
|
|
|
|
title: string;
|
|
|
|
}
|
|
|
|
|
2019-02-17 13:57:57 -08:00
|
|
|
interface State {
|
|
|
|
openModal: boolean;
|
|
|
|
socialKey: string;
|
|
|
|
}
|
|
|
|
|
2018-10-01 09:29:36 -07:00
|
|
|
type Props = OwnProps;
|
|
|
|
|
2019-02-17 13:57:57 -08:00
|
|
|
export default class SocialShare extends React.Component<Props, State> {
|
|
|
|
constructor(props: Props) {
|
|
|
|
super(props);
|
|
|
|
this.state = {
|
|
|
|
openModal: false,
|
|
|
|
socialKey: 'twitter',
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-10-01 09:29:36 -07:00
|
|
|
render() {
|
|
|
|
let { url, title, text } = this.props;
|
2019-02-17 13:57:57 -08:00
|
|
|
const { openModal, socialKey } = this.state;
|
2019-01-22 10:40:20 -08:00
|
|
|
url = url.replace(`localhost:${process.env.PORT}`, 'grants.zfnd.org');
|
2018-10-01 09:29:36 -07:00
|
|
|
url = encodeURIComponent(url);
|
|
|
|
title = encodeURIComponent(title);
|
|
|
|
text = encodeURIComponent(text);
|
|
|
|
return (
|
|
|
|
<div className="SocialShare">
|
2019-02-17 13:57:57 -08:00
|
|
|
<Modal
|
|
|
|
title={
|
|
|
|
<a className={`SocialShare-icon is-${socialKey}`}>
|
|
|
|
<i className={types[socialKey].className} />
|
|
|
|
{' ' + types[socialKey].humanName}
|
|
|
|
</a>
|
|
|
|
}
|
|
|
|
visible={openModal}
|
|
|
|
footer={null}
|
|
|
|
onCancel={() => this.setState({ openModal: false })}
|
|
|
|
>
|
|
|
|
<CopyInput label={''} value={types[socialKey].url(url, title, text)} />
|
|
|
|
</Modal>
|
2018-10-01 09:29:36 -07:00
|
|
|
{Object.keys(types).map(key => {
|
|
|
|
const opts = types[key];
|
|
|
|
return (
|
|
|
|
<a
|
2019-02-17 13:57:57 -08:00
|
|
|
onClick={() =>
|
|
|
|
this.setState({
|
|
|
|
openModal: true,
|
|
|
|
socialKey: key,
|
|
|
|
})
|
|
|
|
}
|
2018-10-01 09:29:36 -07:00
|
|
|
key={key}
|
|
|
|
className={`SocialShare-button is-${key}`}
|
|
|
|
>
|
2019-02-17 13:57:57 -08:00
|
|
|
<i className={opts.className + '-square'} />
|
2018-10-01 09:29:36 -07:00
|
|
|
</a>
|
|
|
|
);
|
|
|
|
})}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|