aboutsummaryrefslogtreecommitdiffstats
path: root/web
diff options
context:
space:
mode:
authorClemens <cle1000.cb@gmail.com>2016-08-16 12:37:35 +0200
committerClemens <cle1000.cb@gmail.com>2016-08-16 12:37:35 +0200
commit779e5e84e37278b8f3255a1061f2137f5b6a3a7d (patch)
treefe91c08c5cdf87bfb99cf3cfe6bfcf3a7e67e933 /web
parent57fafd3281af7a35f8e650fa9fb2cf5af70995f0 (diff)
downloadmitmproxy-779e5e84e37278b8f3255a1061f2137f5b6a3a7d.tar.gz
mitmproxy-779e5e84e37278b8f3255a1061f2137f5b6a3a7d.tar.bz2
mitmproxy-779e5e84e37278b8f3255a1061f2137f5b6a3a7d.zip
refactor file up and download
Diffstat (limited to 'web')
-rw-r--r--web/src/js/components/ContentView/UploadContentButton.jsx20
-rw-r--r--web/src/js/components/Header/FileMenu.jsx32
-rw-r--r--web/src/js/components/common/FileChooser.jsx27
3 files changed, 49 insertions, 30 deletions
diff --git a/web/src/js/components/ContentView/UploadContentButton.jsx b/web/src/js/components/ContentView/UploadContentButton.jsx
index 0652b584..6764e234 100644
--- a/web/src/js/components/ContentView/UploadContentButton.jsx
+++ b/web/src/js/components/ContentView/UploadContentButton.jsx
@@ -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"/>
)
}
diff --git a/web/src/js/components/Header/FileMenu.jsx b/web/src/js/components/Header/FileMenu.jsx
index d3786475..392cc163 100644
--- a/web/src/js/components/Header/FileMenu.jsx
+++ b/web/src/js/components/Header/FileMenu.jsx
@@ -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>
diff --git a/web/src/js/components/common/FileChooser.jsx b/web/src/js/components/common/FileChooser.jsx
new file mode 100644
index 00000000..d8a80ad7
--- /dev/null
+++ b/web/src/js/components/common/FileChooser.jsx
@@ -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>
+ )
+}