add choose remotefs
rename browser variable to brIndex add assert
This commit is contained in:
parent
423df7cfb1
commit
7f6216f032
@ -1,7 +1,8 @@
|
|||||||
import { Component } from 'react'
|
import { Component } from 'react'
|
||||||
import { Cross, PopupContainer, PopupTitle } from '../styled'
|
import { Button, Cross, PopupContainer, PopupTitle } from '../styled'
|
||||||
import API from '../utils/API'
|
import API from '../utils/API'
|
||||||
import FileBrowser from './fileBrowser'
|
import FileBrowser from './fileBrowser'
|
||||||
|
import { FileBrowserRemotes, FileBrowsersContainer, FileBrowserWrapper } from './fileBrowser.styled'
|
||||||
|
|
||||||
class FileBrowserMenu extends Component {
|
class FileBrowserMenu extends Component {
|
||||||
constructor() {
|
constructor() {
|
||||||
@ -36,11 +37,11 @@ class FileBrowserMenu extends Component {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param {Number} browser identify which browser wants new files
|
* @param {Number} brIndex identify which browser wants new files
|
||||||
*/
|
*/
|
||||||
getFiles = (browser, newPath) => {
|
getFiles = (brIndex, newPath) => {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
if (browser !== 0 && browser !== 1) return reject(new Error("Invalid browser id"))
|
if (brIndex !== 0 && brIndex !== 1) return reject(new Error("Invalid browser id: " + brIndex))
|
||||||
|
|
||||||
// if (newPath.charAt(0) === "/") newPath = newPath.substring(1)
|
// if (newPath.charAt(0) === "/") newPath = newPath.substring(1)
|
||||||
|
|
||||||
@ -48,12 +49,12 @@ class FileBrowserMenu extends Component {
|
|||||||
|
|
||||||
let { browserFs } = this.state
|
let { browserFs } = this.state
|
||||||
let currentPath = Object.assign({}, this.state.currentPath)
|
let currentPath = Object.assign({}, this.state.currentPath)
|
||||||
currentPath[browser] = newPath
|
currentPath[brIndex] = newPath
|
||||||
|
|
||||||
return API.request({
|
return API.request({
|
||||||
url: "/operations/list",
|
url: "/operations/list",
|
||||||
data: {
|
data: {
|
||||||
fs: browserFs[browser] + ":",
|
fs: browserFs[brIndex] + ":",
|
||||||
remote: newPath.charAt(0) === "/" ? newPath.substring(1) : newPath
|
remote: newPath.charAt(0) === "/" ? newPath.substring(1) : newPath
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -61,21 +62,22 @@ class FileBrowserMenu extends Component {
|
|||||||
if (typeof response.data.list !== "object") return reject(new Error("Invalid response"))
|
if (typeof response.data.list !== "object") return reject(new Error("Invalid response"))
|
||||||
|
|
||||||
let { files } = this.state
|
let { files } = this.state
|
||||||
files[browser] = response.data.list
|
files[brIndex] = response.data.list
|
||||||
this.setState({ files, currentPath, errMessage: "" })
|
this.setState({ files, currentPath, errMessage: "" })
|
||||||
|
|
||||||
return resolve()
|
return resolve()
|
||||||
})
|
})
|
||||||
|
.catch(() => {})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param {Number} browser identify which browser wants to do the action
|
* @param {Number} brIndex identify which browser wants to do the action
|
||||||
* @param {String} path dir or file
|
* @param {String} path dir or file
|
||||||
* @param {String} name name of the action to be performed
|
* @param {String} name name of the action to be performed
|
||||||
*/
|
*/
|
||||||
action = (browser, path, name) => {
|
action = (brIndex, path, name) => {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
switch(name) {
|
switch(name) {
|
||||||
case "copy":
|
case "copy":
|
||||||
@ -89,20 +91,45 @@ class FileBrowserMenu extends Component {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setRemote = (brIndex, remoteName) => {
|
||||||
|
let { browserFs, currentPath } = this.state
|
||||||
|
browserFs[brIndex] = remoteName
|
||||||
|
|
||||||
|
this.setState({ browserFs, currentPath })
|
||||||
|
setTimeout(() => {
|
||||||
|
this.getFiles(brIndex, "/")
|
||||||
|
}, 50)
|
||||||
|
}
|
||||||
|
|
||||||
|
renderRemoteButtons = brIndex => {
|
||||||
|
console.assert( brIndex === 0 || brIndex === 1, {brIndex})
|
||||||
|
return this.props.remotes.map(v => (
|
||||||
|
<Button onClick={() => this.setRemote(brIndex, v.name)}> { v.name } </Button>
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
render = () => {
|
render = () => {
|
||||||
|
const { files, currentPath } = this.state
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<PopupContainer>
|
<PopupContainer>
|
||||||
<PopupTitle> Browser </PopupTitle>
|
<PopupTitle> Browser </PopupTitle>
|
||||||
<Cross onClick={this.props.close}> Close </Cross>
|
<Cross onClick={this.props.close}> Close </Cross>
|
||||||
|
|
||||||
<FileBrowser
|
<FileBrowsersContainer>
|
||||||
id={0}
|
<FileBrowserWrapper>
|
||||||
action={(path, name) => this.action(0, path, name)}
|
<FileBrowserRemotes>
|
||||||
files={this.state.files[0]}
|
{ this.renderRemoteButtons(0) }
|
||||||
updateFiles={path => this.getFiles(0, path)}
|
</FileBrowserRemotes>
|
||||||
currentPath={this.state.currentPath[0]}
|
|
||||||
/>
|
<FileBrowser
|
||||||
|
action={(path, name) => this.action(0, path, name)}
|
||||||
|
files={files[0]}
|
||||||
|
updateFiles={path => this.getFiles(0, path)}
|
||||||
|
currentPath={currentPath[0]}
|
||||||
|
/>
|
||||||
|
</FileBrowserWrapper>
|
||||||
|
</FileBrowsersContainer>
|
||||||
</PopupContainer>
|
</PopupContainer>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user