mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-22 07:08:10 +00:00
refactor file up and download
This commit is contained in:
parent
57fafd3281
commit
779e5e84e3
@ -1,4 +1,5 @@
|
||||
import { PropTypes } from 'react'
|
||||
import FileChooser from '../common/FileChooser'
|
||||
|
||||
UploadContentButton.propTypes = {
|
||||
uploadContent: PropTypes.func.isRequired,
|
||||
@ -9,20 +10,11 @@ export default function UploadContentButton({ uploadContent }) {
|
||||
let fileInput;
|
||||
|
||||
return (
|
||||
<a className="btn btn-default btn-xs"
|
||||
onClick={() => fileInput.click()}
|
||||
title="Upload a file to replace the content.">
|
||||
<i className="fa fa-upload"/>
|
||||
<input
|
||||
ref={ref => fileInput = ref}
|
||||
className="hidden"
|
||||
type="file"
|
||||
onChange={e => {
|
||||
if (e.target.files.length > 0) uploadContent(e.target.files[0])
|
||||
}}
|
||||
/>
|
||||
</a>
|
||||
|
||||
<FileChooser
|
||||
icon="fa-upload"
|
||||
title="Upload a file to replace the content."
|
||||
onOpenFile={uploadContent}
|
||||
className="btn btn-default btn-xs"/>
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -1,10 +1,19 @@
|
||||
import React, { Component } from 'react'
|
||||
import React, { Component, PropTypes } from 'react'
|
||||
import { connect } from 'react-redux'
|
||||
import classnames from 'classnames'
|
||||
import FileChooser from '../common/FileChooser'
|
||||
import * as flowsActions from '../../ducks/flows'
|
||||
|
||||
|
||||
|
||||
class FileMenu extends Component {
|
||||
|
||||
static propTypes = {
|
||||
clearFlows: PropTypes.func.isRequired,
|
||||
loadFlows: PropTypes.func.isRequired,
|
||||
saveFlows: PropTypes.func.isRequired
|
||||
}
|
||||
|
||||
constructor(props, context) {
|
||||
super(props, context)
|
||||
this.state = { show: false }
|
||||
@ -45,12 +54,8 @@ class FileMenu extends Component {
|
||||
this.fileInput.click()
|
||||
}
|
||||
|
||||
onOpenFile(e) {
|
||||
e.preventDefault()
|
||||
if (e.target.files.length > 0) {
|
||||
this.props.loadFlows(e.target.files[0])
|
||||
this.fileInput.value = ''
|
||||
}
|
||||
onOpenFile(file) {
|
||||
this.props.loadFlows(file)
|
||||
}
|
||||
|
||||
onSaveClick(e) {
|
||||
@ -70,15 +75,10 @@ class FileMenu extends Component {
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="#" onClick={this.onOpenClick}>
|
||||
<i className="fa fa-fw fa-folder-open"></i>
|
||||
Open...
|
||||
</a>
|
||||
<input
|
||||
ref={ref => this.fileInput = ref}
|
||||
className="hidden"
|
||||
type="file"
|
||||
onChange={this.onOpenFile}
|
||||
<FileChooser
|
||||
icon="fa-folder-open"
|
||||
text="Open..."
|
||||
onOpenFile={this.onOpenFile}
|
||||
/>
|
||||
</li>
|
||||
<li>
|
||||
|
27
web/src/js/components/common/FileChooser.jsx
Normal file
27
web/src/js/components/common/FileChooser.jsx
Normal file
@ -0,0 +1,27 @@
|
||||
import React, { PropTypes } from 'react'
|
||||
|
||||
FileChooser.propTypes = {
|
||||
icon: PropTypes.string,
|
||||
text: PropTypes.string,
|
||||
className: PropTypes.string,
|
||||
title: PropTypes.string,
|
||||
onOpenFile: PropTypes.func.isRequired
|
||||
}
|
||||
|
||||
export default function FileChooser({ icon, text, className, title, onOpenFile }) {
|
||||
let fileInput;
|
||||
return (
|
||||
<a onClick={() => fileInput.click()}
|
||||
className={className}
|
||||
title={title}>
|
||||
<i className={'fa fa-fw ' + icon}></i>
|
||||
{text}
|
||||
<input
|
||||
ref={ref => fileInput = ref}
|
||||
className="hidden"
|
||||
type="file"
|
||||
onChange={e => { e.preventDefault(); if(e.target.files.length > 0) onOpenFile(e.target.files[0]); fileInput = "";}}
|
||||
/>
|
||||
</a>
|
||||
)
|
||||
}
|
Loading…
Reference in New Issue
Block a user