diff --git a/src/bundles/ipfs-provider.js b/src/bundles/ipfs-provider.js index a673f5fed..edf6206b6 100644 --- a/src/bundles/ipfs-provider.js +++ b/src/bundles/ipfs-provider.js @@ -169,9 +169,10 @@ const writeSetting = (id, value) => { /** * @typedef {Object} IPFSAPI * @property {(callback?:Function) => Promise} stop + * @property {Object} files + * @property {(callback?:Function) => Promise} files.stat */ - -/** @type {IPFSAPI|void} */ +/** @type {IPFSAPI|null} */ let ipfs = null /** @@ -232,6 +233,11 @@ const bundle = { doDismissIpfsInvalidAddress: () => (store) => { store.dispatch({ type: 'IPFS_API_ADDRESS_INVALID_DISMISS' }) + }, + + doGetCidForPath: (path) => async () => { + const { cid } = await ipfs.files.stat(path) + return cid } } diff --git a/src/files/FilesPage.js b/src/files/FilesPage.js index 3f9c40c6d..5e439af52 100644 --- a/src/files/FilesPage.js +++ b/src/files/FilesPage.js @@ -225,7 +225,7 @@ class FilesPage extends React.Component { translateX={contextMenu.translateX} translateY={contextMenu.translateY} handleClick={this.handleContextMenu} - isUpperDir={contextMenu.file && contextMenu.file.name === '..'} + isDirectory={contextMenu.file && contextMenu.file.type === 'directory'} isMfs={filesPathInfo ? filesPathInfo.isMfs : false} isUnknown={!!(contextMenu.file && contextMenu.file.type === 'unknown')} pinned={contextMenu.file && contextMenu.file.pinned} diff --git a/src/files/breadcrumbs/Breadcrumbs.css b/src/files/breadcrumbs/Breadcrumbs.css index d8e75060a..dfc8b752e 100644 --- a/src/files/breadcrumbs/Breadcrumbs.css +++ b/src/files/breadcrumbs/Breadcrumbs.css @@ -17,3 +17,7 @@ .BreadcrumbsButton.dragging::after { opacity: 1; } + +.BreadcrumbsButton.no-events { + pointer-events: none; +} diff --git a/src/files/breadcrumbs/Breadcrumbs.js b/src/files/breadcrumbs/Breadcrumbs.js index 84db22985..b07cd9c12 100644 --- a/src/files/breadcrumbs/Breadcrumbs.js +++ b/src/files/breadcrumbs/Breadcrumbs.js @@ -1,28 +1,30 @@ -import React, { useEffect, useState, useRef } from 'react' +import React, { useEffect, useState, useRef, useMemo } from 'react' import classNames from 'classnames' import PropTypes from 'prop-types' +import { basename, join } from 'path' +import { connect } from 'redux-bundler-react' import { withTranslation } from 'react-i18next' +import { useDrop } from 'react-dnd' import { NativeTypes } from 'react-dnd-html5-backend' -import './Breadcrumbs.css' -import { useDrop } from 'react-dnd' -import { basename, join } from 'path' import { normalizeFiles } from '../../lib/files' -const DropableBreadcrumb = ({ index, link, path, onAddFiles, onMove, onClick, onContextMenuHandle }) => { +import './Breadcrumbs.css' + +const DropableBreadcrumb = ({ index, link, fullPath, immutable, onAddFiles, onMove, onClick, onContextMenuHandle, getCidForPath }) => { const [{ isOver }, drop] = useDrop({ accept: [NativeTypes.FILE, 'FILE'], - drop: ({ files, filesPromise, path: filePath }) => { + drop: async ({ files, filesPromise, path: filePath }) => { if (files) { (async () => { const files = await filesPromise - onAddFiles(await normalizeFiles(files), path) + onAddFiles(await normalizeFiles(files), fullPath) })() } else { const src = filePath - const dst = join(path, basename(filePath)) + const dst = join(link.path, basename(filePath)) - onMove(src, dst) + try { await onMove(src, dst) } catch (e) { console.error(e) } } }, collect: (monitor) => ({ @@ -32,12 +34,29 @@ const DropableBreadcrumb = ({ index, link, path, onAddFiles, onMove, onClick, on const buttonRef = useRef() - const handleOnContextMenuHandle = (ev) => onContextMenuHandle(ev, buttonRef.current) + const handleOnContextMenuHandle = async (ev) => { + ev.preventDefault() + + const { path } = link + const sanitizedPath = path.substring(path.indexOf('/', 1), path.length) + const cid = await getCidForPath(sanitizedPath) + + onContextMenuHandle(undefined, buttonRef.current, { + ...link, + ...(!link.last && { type: 'directory' }), + cid + }) + } return ( @@ -45,8 +64,9 @@ const DropableBreadcrumb = ({ index, link, path, onAddFiles, onMove, onClick, on ) } -const Breadcrumbs = ({ t, tReady, path, onClick, className, onContextMenuHandle, onAddFiles, onMove, ...props }) => { +const Breadcrumbs = ({ t, tReady, path, onClick, className, onContextMenuHandle, onAddFiles, onMove, doGetCidForPath, ...props }) => { const [overflows, setOverflows] = useState(false) + const [isImmutable, setImmutable] = useState(false) const anchors = useRef() useEffect(() => { @@ -58,21 +78,22 @@ const Breadcrumbs = ({ t, tReady, path, onClick, className, onContextMenuHandle, } }, [overflows]) - const bread = makeBread(path, t) + const bread = useMemo(() => + makeBread(path, t, isImmutable, setImmutable) + , [isImmutable, path, t]) return ( -