diff --git a/src/components/fileMenu.jsx b/src/components/fileMenu.jsx new file mode 100644 index 0000000..899e4aa --- /dev/null +++ b/src/components/fileMenu.jsx @@ -0,0 +1,130 @@ +import { Component,Fragment } from 'react' +import { Button, WarningButton, Input } from '../styled' +import { FileSettingsHeader, FileSettingsPopup, FileMenuContainer, ButtonWrapper } from './fileBrowser.styled' + +class FileMenu extends Component { + constructor() { + super() + this.state = { + action: "", + newFile: "" + } + } + + // update newFile state + handleInputChange = e => { + this.setState({ newFile: e.target.value }) + } + + // start the action + doAction = e => { + if (typeof e?.preventDefault === "function") e.preventDefault() + + const { action, newFile } = this.state + + this.props.action(action, newFile) + } + + // after clicking new folder or rename show popup to enter file name + handlePathClick = (e, action) => { + e.stopPropagation() + return this.setState({ action }) + } + + // after clicking copy or move show the dest path + handleSyncClick = (e, action) => { + e.stopPropagation() + this.setState({ action }) + } + + // show delete warning and stop close menu + handleDeleteClick = e => { + e.stopPropagation() + this.setState({ action: "delete" }) + } + + // ask user to enter a path and submit + renderPathPopup = () => { + const { newFile, action } = this.state + const { file } = this.props.info + + if (action === "rename" || action === "newfolder") return ( + e.stopPropagation()}> + + +
+ + +
+
+ ) + } + + // ask user to confirm the copy or move + renderConfirmPath = () => { + const { action } = this.state + const { otherPath, file } = this.props.info + + if (action === "copy" || action === "move") return ( + + Confirm +

+ { action === "copy" ? "Copy" : "Move" } { file.Name } to { otherPath }? +

+ + + + +
+ ) + } + + /** + * Renders a simple menu to perform actions on the clicked file + */ + renderMenu = () => { + const { cursorX, cursorY, file } = this.props.info + const { action } = this.state + + if (file?.Name?.length && (action === "delete" || action === "")) return ( + this.setState({ showMenu: false })} + cursorX={cursorX} cursorY={cursorY} + > + + + + + { + action === "delete" ? + Delete + : + + } + + ) + + if (action === "") return ( + this.doAction()} + cursorX={cursorX} cursorY={cursorY} + > + + + ) + } + + render = () => { + return ( + + { this.renderMenu() } + { this.renderConfirmPath() } + { this.renderPathPopup() } + + ) + } +} + +export default FileMenu \ No newline at end of file