mirror of
https://github.com/LBRYFoundation/lbry-desktop.git
synced 2025-08-29 00:11:28 +00:00
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 * as React from 'react';
|
||||||
import remark from 'remark';
|
import remark from 'remark';
|
||||||
import reactRenderer from 'remark-react';
|
import reactRenderer from 'remark-react';
|
||||||
import Button from 'component/button';
|
import ExternalLink from 'component/externalLink';
|
||||||
|
|
||||||
type Props = {
|
type MarkdownProps = { content: string };
|
||||||
children: React.Node,
|
type TitleProps = { children: React.Node };
|
||||||
};
|
|
||||||
|
|
||||||
const TitleMarkdown = (props: Props) => {
|
const MarkdownTitle = (props: TitleProps) => {
|
||||||
const { children } = props;
|
const { children } = props;
|
||||||
return <div className="markdown-preview__title">{children}</div>;
|
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 MarkdownPreview = (props: MarkdownProps) => {
|
||||||
const { content } = props;
|
const { content } = props;
|
||||||
const remarkOptions = {
|
const remarkOptions = {
|
||||||
sanatize: true,
|
sanatize: true,
|
||||||
remarkReactComponents: {
|
remarkReactComponents: {
|
||||||
a: LinkMarkDown,
|
a: ExternalLink,
|
||||||
h1: TitleMarkdown,
|
h1: MarkdownTitle,
|
||||||
h2: TitleMarkdown,
|
h2: MarkdownTitle,
|
||||||
h3: TitleMarkdown,
|
h3: MarkdownTitle,
|
||||||
h4: TitleMarkdown,
|
h4: MarkdownTitle,
|
||||||
h5: TitleMarkdown,
|
h5: MarkdownTitle,
|
||||||
h6: TitleMarkdown,
|
h6: MarkdownTitle,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
return (
|
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 ModalSendTip from '../modalSendTip';
|
||||||
import ModalPublish from '../modalPublish';
|
import ModalPublish from '../modalPublish';
|
||||||
import ModalSearch from '../modalSearch';
|
import ModalSearch from '../modalSearch';
|
||||||
|
import ModalOpenExternalLink from '../modalOpenExternalLink';
|
||||||
|
|
||||||
class ModalRouter extends React.PureComponent {
|
class ModalRouter extends React.PureComponent {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
|
@ -155,6 +156,8 @@ class ModalRouter extends React.PureComponent {
|
||||||
return <ModalPublish {...notificationProps} />;
|
return <ModalPublish {...notificationProps} />;
|
||||||
case MODALS.SEARCH:
|
case MODALS.SEARCH:
|
||||||
return <ModalSearch {...notificationProps} />;
|
return <ModalSearch {...notificationProps} />;
|
||||||
|
case MODALS.CONFIRM_EXTERNAL_LINK:
|
||||||
|
return <ModalOpenExternalLink {...notificationProps} />;
|
||||||
default:
|
default:
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue