From 6144b08cf9e8dd422bfb1e6fa517c613c44275ac Mon Sep 17 00:00:00 2001 From: togekk1 Date: Thu, 11 Feb 2021 16:52:43 +0800 Subject: [PATCH] Open the actual image when clicking on the image viewer --- ui/component/fileRender/index.js | 11 +++++++- ui/component/fileRender/view.jsx | 14 +++++++--- ui/component/viewers/imageViewer.jsx | 17 ++++++++++-- ui/modal/modalOpenExternalResource/view.jsx | 29 ++++++++++++++++----- ui/scss/component/_file-render.scss | 6 +++++ ui/scss/component/_modal.scss | 4 +++ 6 files changed, 68 insertions(+), 13 deletions(-) diff --git a/ui/component/fileRender/index.js b/ui/component/fileRender/index.js index b09fd76d7..fbe39d3f3 100644 --- a/ui/component/fileRender/index.js +++ b/ui/component/fileRender/index.js @@ -1,14 +1,17 @@ import { connect } from 'react-redux'; import { makeSelectClaimForUri, + makeSelectFileInfoForUri, makeSelectThumbnailForUri, makeSelectContentTypeForUri, makeSelectDownloadPathForUri, makeSelectStreamingUrlForUri, + makeSelectClaimIsMine, SETTINGS, } from 'lbry-redux'; import { makeSelectClientSetting } from 'redux/selectors/settings'; import { makeSelectFileRenderModeForUri, makeSelectFileExtensionForUri } from 'redux/selectors/content'; +import { doOpenModal } from 'redux/actions/app'; import FileRender from './view'; const select = (state, props) => { @@ -23,7 +26,13 @@ const select = (state, props) => { streamingUrl: makeSelectStreamingUrlForUri(props.uri)(state), renderMode: makeSelectFileRenderModeForUri(props.uri)(state), autoplay: autoplay, + fileInfo: makeSelectFileInfoForUri(props.uri)(state), + claimIsMine: makeSelectClaimIsMine(props.uri)(state), }; }; -export default connect(select)(FileRender); +const perform = (dispatch) => ({ + openModal: (modal, props) => dispatch(doOpenModal(modal, props)), +}); + +export default connect(select, perform)(FileRender); diff --git a/ui/component/fileRender/view.jsx b/ui/component/fileRender/view.jsx index e3b666d31..b812f7be9 100644 --- a/ui/component/fileRender/view.jsx +++ b/ui/component/fileRender/view.jsx @@ -35,6 +35,9 @@ type Props = { thumbnail: string, desktopPlayStartTime?: number, className?: string, + fileInfo: ?FileListItem, + openModal: (id: string, { path: string }) => void, + claimIsMine: boolean, }; class FileRender extends React.PureComponent { @@ -76,8 +79,11 @@ class FileRender extends React.PureComponent { fileExtension, streamingUrl, uri, + fileInfo, renderMode, desktopPlayStartTime, + openModal, + claimIsMine, } = this.props; const source = streamingUrl; @@ -93,7 +99,9 @@ class FileRender extends React.PureComponent { /> ); case RENDER_MODES.IMAGE: - return ; + return ( + + ); case RENDER_MODES.HTML: return ; case RENDER_MODES.DOCUMENT: @@ -102,7 +110,7 @@ class FileRender extends React.PureComponent { fs.createReadStream(downloadPath, options), + file: (options) => fs.createReadStream(downloadPath, options), // @endif stream: source, fileExtension, @@ -131,7 +139,7 @@ class FileRender extends React.PureComponent { fs.createReadStream(downloadPath, options), + file: (options) => fs.createReadStream(downloadPath, options), // @endif stream: source, }} diff --git a/ui/component/viewers/imageViewer.jsx b/ui/component/viewers/imageViewer.jsx index cb7ffe801..1524e7ff0 100644 --- a/ui/component/viewers/imageViewer.jsx +++ b/ui/component/viewers/imageViewer.jsx @@ -2,13 +2,17 @@ import React from 'react'; import Card from 'component/common/card'; import ErrorText from 'component/common/error-text'; +import * as MODALS from 'constants/modal_types'; type Props = { source: string, + fileInfo: ?FileListItem, + openModal: (id: string, { path: string }) => void, + claimIsMine: boolean, }; function ImageViewer(props: Props) { - const { source } = props; + const { source, fileInfo, openModal, claimIsMine } = props; const [loadingError, setLoadingError] = React.useState(false); return ( @@ -21,7 +25,16 @@ function ImageViewer(props: Props) { )} {!loadingError && (
- setLoadingError(true)} /> + setLoadingError(true)} + onClick={() => { + openModal(MODALS.CONFIRM_EXTERNAL_RESOURCE, { + path: (fileInfo && fileInfo.download_path) || '', + isMine: claimIsMine, + }); + }} + />
)} diff --git a/ui/modal/modalOpenExternalResource/view.jsx b/ui/modal/modalOpenExternalResource/view.jsx index ab092385e..4e690f9e2 100644 --- a/ui/modal/modalOpenExternalResource/view.jsx +++ b/ui/modal/modalOpenExternalResource/view.jsx @@ -1,7 +1,9 @@ // @flow -import React from 'react'; +import React, { useCallback, useEffect } from 'react'; import { Modal } from 'modal/modal'; import { formatFileSystemPath } from 'util/url'; +import { FormField } from 'component/common/form'; +import usePersistedState from 'effects/use-persisted-state'; // @if TARGET='app' import { shell } from 'electron'; // @endif @@ -15,13 +17,10 @@ type Props = { }; function ModalOpenExternalResource(props: Props) { + const [stopWarning, setStopWarning] = usePersistedState('stop-warning', false); const { uri, isTrusted, path, isMine, closeModal } = props; - if ((uri && isTrusted) || (path && isMine)) { - openResource(); - } - - function openResource() { + const openResource = useCallback(() => { // @if TARGET='app' const { openExternal, openPath, showItemInFolder } = shell; if (uri) { @@ -42,7 +41,14 @@ function ModalOpenExternalResource(props: Props) { // @endif closeModal(); - } + }, [closeModal, path, uri]); + + useEffect(() => { + if ((uri && isTrusted) || (path && isMine) || stopWarning) { + openResource(); + } + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [uri, isTrusted, path, isMine, openResource]); return (
{uri || path}

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

+
+ setStopWarning(!stopWarning)} + label={__("Don't Show This Message Again")} + name="stop_warning" + /> +
); } diff --git a/ui/scss/component/_file-render.scss b/ui/scss/component/_file-render.scss index dac8840f9..de87758db 100644 --- a/ui/scss/component/_file-render.scss +++ b/ui/scss/component/_file-render.scss @@ -726,3 +726,9 @@ video::-internal-media-controls-overlay-cast-button { } } } + +.file-page__image { + img { + cursor: pointer; + } +} diff --git a/ui/scss/component/_modal.scss b/ui/scss/component/_modal.scss index d349794cb..9bff23833 100644 --- a/ui/scss/component/_modal.scss +++ b/ui/scss/component/_modal.scss @@ -92,3 +92,7 @@ overflow-y: scroll; white-space: pre-wrap; } + +.stop-warning { + margin-top: 20px; +}