diff --git a/src/components/fileBrowser.jsx b/src/components/fileBrowser.jsx index 7149955..f6d0d16 100644 --- a/src/components/fileBrowser.jsx +++ b/src/components/fileBrowser.jsx @@ -35,6 +35,8 @@ import ZIP from '../assets/fileTypes/zip.svg' import CaretDown from '../assets/icons/caretDown.svg' import bytesToString from '../utils/bytestring.js' +import { Button } from '../styled.js' +import assert from 'assert' const FBContainer = styled.div` display: flex; @@ -204,7 +206,11 @@ class FileBrowser extends Component { orderAscending: true, files: [], prevPath: "", - transitionFiles: 0 + transitionFiles: 0, + renderMenu: false, + cursorX: 0, + cursorY: 0, + clicked: "" } this.backListener = undefined @@ -220,6 +226,9 @@ class FileBrowser extends Component { // if the component was just created set the path if (this.state.prevPath === "" && this.props.currentPath !== "") return this.setState({ prevPath: this.props.currentPath, files: this.props.files }) + // add click event listener for closing menu + window.addEventListener('click', () => this.setState({ renderMenu: false })) + // the path changed if (this.props.currentPath !== this.state.prevPath) { let direction = 1 @@ -327,13 +336,44 @@ class FileBrowser extends Component { } } + doAction = a => this.props.action(a, this.state.clicked) + openMenu = (e) => { e.preventDefault() - // get position of the cursor - // somehow know the file that was clicked - // open menu on the position of the cursor - // display different options for dir and files? + assert( + typeof e.pageX === "number" + && typeof e.pageY === "number" + && typeof e.target.innerHTML === "string" + && e.target.innerHTML.length > 0 + ) + + this.setState({ + cursorX: e.pageX, + cursorY: e.pageY, + renderMenu: true, + clicked: e.target.innerHTML + }) + } + + renderMenu = () => { + if (this.state.renderMenu) return ( +