From a83e06d6228c5286f013a84d1e5965c9594c391f Mon Sep 17 00:00:00 2001 From: zxawry Date: Sun, 12 May 2019 15:51:22 +0100 Subject: [PATCH] rename link to resource --- .../modal/modalOpenExternalResource/index.js | 12 +++ .../modal/modalOpenExternalResource/view.jsx | 74 +++++++++++++++++++ 2 files changed, 86 insertions(+) create mode 100644 src/ui/modal/modalOpenExternalResource/index.js create mode 100644 src/ui/modal/modalOpenExternalResource/view.jsx diff --git a/src/ui/modal/modalOpenExternalResource/index.js b/src/ui/modal/modalOpenExternalResource/index.js new file mode 100644 index 000000000..b72a7a7ce --- /dev/null +++ b/src/ui/modal/modalOpenExternalResource/index.js @@ -0,0 +1,12 @@ +import { connect } from 'react-redux'; +import { doHideModal } from 'redux/actions/app'; +import ModalOpenExternalResource from './view'; + +const perform = dispatch => ({ + closeModal: () => dispatch(doHideModal()), +}); + +export default connect( + null, + perform +)(ModalOpenExternalResource); diff --git a/src/ui/modal/modalOpenExternalResource/view.jsx b/src/ui/modal/modalOpenExternalResource/view.jsx new file mode 100644 index 000000000..9f3c52bc1 --- /dev/null +++ b/src/ui/modal/modalOpenExternalResource/view.jsx @@ -0,0 +1,74 @@ +// @flow +import React from 'react'; +import { Modal } from 'modal/modal'; +import { formatLbryUriForWeb } from 'util/uri'; +// @if TARGET='app' +import { shell } from 'electron'; +// @endif + +type Props = { + uri: string, + path: string, + closeModal: () => void, +}; + +class ModalOpenExternalResource extends React.PureComponent { + openExternalResource() { + const { uri, path, closeModal } = this.props; + // @if TARGET='app' + const { openExternal, openItem, showItemInFolder } = shell; + if (uri) { + openExternal(uri); + } else if(path) { + const success = openItem(path); + if (!success) { + showItemInFolder(path); + } + } + // @endif + // @if TARGET='web' + if (uri) { + window.open(uri); + } else if (path) { + // Converintg path into uri, like "file://path/to/file" + let _uri = path.replace(/\\/g, '/'); + // Windows drive letter must be prefixed with a slash + if (_uri[0] !== '/') { + _uri = `/${_uri}`; + } + _uri = encodeURI(`file://${_uri}`).replace(/[?#]/g, encodeURIComponent); + window.open(_uri); + } + // @endif + + closeModal(); + } + + render() { + const { uri, path, closeModal } = this.props; + return ( + this.openExternalResource()} + onAborted={closeModal} + > +
+

+ { + (uri && __('This link leads to an external website.')) || + (path && __('This file has been shared with you by other people.')) + } +

+
{uri || path}
+

{__('LBRY Inc is not responsible for its content, click continue to proceed at your own risk.')}

+
+
+ ); + } +} + +export default ModalOpenExternalResource;