Better downloading

now downloads file on button click
This commit is contained in:
Graeme
2018-04-05 20:51:12 -07:00
parent 485d04ff3c
commit 6173d3b966
2 changed files with 26 additions and 10 deletions
+9 -10
View File
@@ -26,10 +26,11 @@ export default class HighlightCode extends Component {
this.setState({ contentsHidden: !this.state.contentsHidden })
}
downloadJSON = (value) => {
let fileName = 'response'
let fileToSave = new Blob([value], {type: 'text/json', name: fileName})
saveAs(fileToSave)
downloadJSON = () => {
let content = this.props.value
let fileName = "response"
let fileToSave = new Blob([content], {type: 'text/plain'})
saveAs(fileToSave, fileName)
}
render () {
@@ -39,6 +40,9 @@ export default class HighlightCode extends Component {
return (
<div>
<div className='download-contents' onClick={this.downloadJSON}>
{"Download"}
</div>
<pre
ref={this.initializeComponent}
className={className + " microlight" + (contentsHidden ? ' flat-bottom' : '')}>
@@ -46,12 +50,7 @@ export default class HighlightCode extends Component {
</pre>
{ value.length > 600 &&
<div className='see-full-contents' onClick={this.onToggleSeeFullContents}>
{ contentsHidden ? 'See full contents' : 'Collapse contents'}
</div>
}
{ value.length > 600 &&
<div className='see-full-contents' onClick={this.downloadJSON(value)}>
{'Download'}
{ contentsHidden ? "See full contents" : "Collapse contents"}
</div>
}
</div>
+17
View File
@@ -654,6 +654,23 @@
height: 20px;
}
.download-contents {
display: inline-flex;
justify-content: center;
align-items: center;
cursor: pointer;
background: #7d8293;
padding: 5px 5px 5px;
border: 10px solid #41444e;
border-top-right-radius: 6px;
border-top-left-radius: 6px;
font-family: 'Titillium Web', sans-serif;
font-weight: 600;
color: white;
font-size: 14px;
bottom: 0px;
}
.scheme-container
{
margin: 0 0 20px 0;