add confirmation modal for external links
This commit is contained in:
parent
cd769856fa
commit
66ff07697f
6 changed files with 109 additions and 25 deletions
11
src/renderer/component/externalLink/index.js
Normal file
11
src/renderer/component/externalLink/index.js
Normal file
|
@ -0,0 +1,11 @@
|
|||
import React from 'react';
|
||||
import { connect } from 'react-redux';
|
||||
import { doNotify } from 'lbry-redux';
|
||||
import ExternalLink from './view';
|
||||
|
||||
const select = () => ({});
|
||||
const perform = dispatch => ({
|
||||
openModal: (modal, props) => dispatch(doNotify(modal, props)),
|
||||
});
|
||||
|
||||
export default connect(select, perform)(ExternalLink);
|
34
src/renderer/component/externalLink/view.jsx
Normal file
34
src/renderer/component/externalLink/view.jsx
Normal file
|
@ -0,0 +1,34 @@
|
|||
// @flow
|
||||
import React from 'react';
|
||||
import { MODALS } from 'lbry-redux';
|
||||
import Button from 'component/button';
|
||||
|
||||
type Props = {
|
||||
href?: string,
|
||||
title?: string,
|
||||
children: React.Node,
|
||||
openModal: string => void,
|
||||
};
|
||||
|
||||
class ExternalLink extends React.PureComponent<Props> {
|
||||
static defaultProps = {
|
||||
href: null,
|
||||
title: null,
|
||||
};
|
||||
render() {
|
||||
const { href, title, children, openModal } = this.props;
|
||||
return href ? (
|
||||
<Button
|
||||
button="link"
|
||||
title={title}
|
||||
onClick={() => openModal({ id: MODALS.CONFIRM_EXTERNAL_LINK }, { url: href })}
|
||||
>
|
||||
{children}
|
||||
</Button>
|
||||
) : (
|
||||
<span>children</span>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default ExternalLink;
|
|
@ -2,42 +2,28 @@
|
|||
import * as React from 'react';
|
||||
import remark from 'remark';
|
||||
import reactRenderer from 'remark-react';
|
||||
import Button from 'component/button';
|
||||
import ExternalLink from 'component/externalLink';
|
||||
|
||||
type Props = {
|
||||
children: React.Node,
|
||||
};
|
||||
type MarkdownProps = { content: string };
|
||||
type TitleProps = { children: React.Node };
|
||||
|
||||
const TitleMarkdown = (props: Props) => {
|
||||
const MarkdownTitle = (props: TitleProps) => {
|
||||
const { children } = props;
|
||||
return <div className="markdown-preview__title">{children}</div>;
|
||||
};
|
||||
|
||||
const LinkMarkDown = (props: Props) => {
|
||||
const { children } = props;
|
||||
return (
|
||||
<Button button="link" {...props}>
|
||||
{children}
|
||||
</Button>
|
||||
);
|
||||
};
|
||||
|
||||
type MarkdownProps = {
|
||||
content: string,
|
||||
};
|
||||
|
||||
const MarkdownPreview = (props: MarkdownProps) => {
|
||||
const { content } = props;
|
||||
const remarkOptions = {
|
||||
sanatize: true,
|
||||
remarkReactComponents: {
|
||||
a: LinkMarkDown,
|
||||
h1: TitleMarkdown,
|
||||
h2: TitleMarkdown,
|
||||
h3: TitleMarkdown,
|
||||
h4: TitleMarkdown,
|
||||
h5: TitleMarkdown,
|
||||
h6: TitleMarkdown,
|
||||
a: ExternalLink,
|
||||
h1: MarkdownTitle,
|
||||
h2: MarkdownTitle,
|
||||
h3: MarkdownTitle,
|
||||
h4: MarkdownTitle,
|
||||
h5: MarkdownTitle,
|
||||
h6: MarkdownTitle,
|
||||
},
|
||||
};
|
||||
return (
|
||||
|
|
11
src/renderer/modal/modalOpenExternalLink/index.js
Normal file
11
src/renderer/modal/modalOpenExternalLink/index.js
Normal file
|
@ -0,0 +1,11 @@
|
|||
import { connect } from 'react-redux';
|
||||
import { doHideNotification } from 'lbry-redux';
|
||||
import ModalOpenExternalLink from './view';
|
||||
|
||||
const select = () => ({});
|
||||
|
||||
const perform = dispatch => ({
|
||||
closeModal: () => dispatch(doHideNotification()),
|
||||
});
|
||||
|
||||
export default connect(select, perform)(ModalOpenExternalLink);
|
39
src/renderer/modal/modalOpenExternalLink/view.jsx
Normal file
39
src/renderer/modal/modalOpenExternalLink/view.jsx
Normal file
|
@ -0,0 +1,39 @@
|
|||
// @flow
|
||||
import React from 'react';
|
||||
import { Modal } from 'modal/modal';
|
||||
import { shell } from 'electron';
|
||||
|
||||
type Props = {
|
||||
url: string,
|
||||
closeModal: () => void,
|
||||
};
|
||||
|
||||
class ModalOpenExternalLink extends React.PureComponent<Props> {
|
||||
openExternalLink() {
|
||||
const { url } = this.props;
|
||||
const { openExternal } = shell;
|
||||
openExternal(url);
|
||||
}
|
||||
|
||||
render() {
|
||||
const { url, closeModal } = this.props;
|
||||
return (
|
||||
<Modal
|
||||
isOpen
|
||||
contentLabel={__('Confirm External Link')}
|
||||
type="confirm"
|
||||
confirmButtonLabel={__('Continue')}
|
||||
onConfirmed={() => this.openExternalLink(url)}
|
||||
onAborted={closeModal}
|
||||
>
|
||||
<p>
|
||||
{__('This link leads to an external website:')}
|
||||
<cite>{url}</cite>
|
||||
{__('LBRY Inc is not responsible for its content, click OK to proceed at your own risk.')}
|
||||
</p>
|
||||
</Modal>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default ModalOpenExternalLink;
|
|
@ -21,6 +21,7 @@ import ModalFirstSubscription from 'modal/modalFirstSubscription';
|
|||
import ModalSendTip from '../modalSendTip';
|
||||
import ModalPublish from '../modalPublish';
|
||||
import ModalSearch from '../modalSearch';
|
||||
import ModalOpenExternalLink from '../modalOpenExternalLink';
|
||||
|
||||
class ModalRouter extends React.PureComponent {
|
||||
constructor(props) {
|
||||
|
@ -155,6 +156,8 @@ class ModalRouter extends React.PureComponent {
|
|||
return <ModalPublish {...notificationProps} />;
|
||||
case MODALS.SEARCH:
|
||||
return <ModalSearch {...notificationProps} />;
|
||||
case MODALS.CONFIRM_EXTERNAL_LINK:
|
||||
return <ModalOpenExternalLink {...notificationProps} />;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue