From 3f6a09ae046647bb3a6446613e3ad0bb47d561ce Mon Sep 17 00:00:00 2001 From: Henrique Dias Date: Wed, 1 Sep 2021 01:46:53 +0200 Subject: [PATCH] fix: selection for text files (#1842) License: MIT Signed-off-by: Henrique Dias --- src/files/file-preview/FilePreview.js | 55 +++++++++++++++------------ 1 file changed, 30 insertions(+), 25 deletions(-) diff --git a/src/files/file-preview/FilePreview.js b/src/files/file-preview/FilePreview.js index b4292d79d..110a0a69d 100644 --- a/src/files/file-preview/FilePreview.js +++ b/src/files/file-preview/FilePreview.js @@ -1,6 +1,5 @@ -import React, { useCallback, useEffect, useRef, useState } from 'react' +import React, { useCallback, useEffect, useState } from 'react' import PropTypes from 'prop-types' -import classNames from 'classnames' import { connect } from 'redux-bundler-react' import isBinary from 'is-binary' import { Trans, withTranslation } from 'react-i18next' @@ -12,26 +11,22 @@ import { useDrag } from 'react-dnd' import fromUint8ArrayToString from 'uint8arrays/to-string' import Button from '../../components/button/Button' -const Preview = (props) => { - const { name, size, cid, path } = props +const Drag = ({ name, size, cid, path, children }) => { const [, drag] = useDrag({ item: { name, size, cid, path, type: 'FILE' } }) - const type = typeFromExt(name) - - // Hack: Allows for text selection if it's a text file (bypass useDrag) - const dummyRef = useRef() - - return
- + return
+ { children }
} -const PreviewItem = ({ t, name, cid, size, type, availableGatewayUrl: gatewayUrl, read, onDownload }) => { +const Preview = (props) => { + const { t, name, cid, size, availableGatewayUrl: gatewayUrl, read, onDownload } = props const [content, setContent] = useState(null) const [hasMoreContent, setHasMoreContent] = useState(false) const [buffer, setBuffer] = useState(null) + const type = typeFromExt(name) const loadContent = useCallback(async () => { const readBuffer = buffer || await read() @@ -62,27 +57,37 @@ const PreviewItem = ({ t, name, cid, size, type, availableGatewayUrl: gatewayUrl switch (type) { case 'audio': return ( - // eslint-disable-next-line jsx-a11y/media-has-caption - + + {/* eslint-disable-next-line jsx-a11y/media-has-caption */} + + ) case 'pdf': return ( - - {t('noPDFSupport')} - {t('downloadPDF')} - + + + {t('noPDFSupport')} + {t('downloadPDF')} + + ) case 'video': return ( - // eslint-disable-next-line jsx-a11y/media-has-caption - + + {/* eslint-disable-next-line jsx-a11y/media-has-caption */} + + ) case 'image': - return {name} + return ( + + {name} + + ) default: { const cantPreview = (