Ability to name file downloads (#562)

* Ability to name file downloads

- Closes #561

* fix codemirror-graphql
main
Michael Fix 6 years ago committed by GitHub
parent 6c96791912
commit 6ab33153a8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -199,10 +199,11 @@ class Editor extends React.Component {
const link = document.createElement('a') const link = document.createElement('a')
const timestamp = this.state.timestamp ? `_${formatTimestamp()}` : '' const timestamp = this.state.timestamp ? `_${formatTimestamp()}` : ''
const prefix = this.state.filename || 'carbon'
return this.getCarbonImage({ format, type: 'blob' }).then(url => { return this.getCarbonImage({ format, type: 'blob' }).then(url => {
if (format !== 'open ↗') { if (format !== 'open ↗') {
link.download = `carbon${timestamp}.${format}` link.download = `${prefix}${timestamp}.${format}`
} }
link.href = url link.href = url
document.body.appendChild(link) document.body.appendChild(link)

@ -20,6 +20,7 @@ class Settings extends React.PureComponent {
} }
this.toggle = this.toggle.bind(this) this.toggle = this.toggle.bind(this)
this.format = this.format.bind(this) this.format = this.format.bind(this)
this.handleInputChange = this.handleInputChange.bind(this)
} }
toggle() { toggle() {
@ -30,6 +31,10 @@ class Settings extends React.PureComponent {
this.setState({ isVisible: false }) this.setState({ isVisible: false })
} }
handleInputChange(e) {
this.props.onChange(e.target.name, e.target.value)
}
format() { format() {
return formatCode(this.props.code) return formatCode(this.props.code)
.then(this.props.onChange.bind(this, 'code')) .then(this.props.onChange.bind(this, 'code'))
@ -53,6 +58,13 @@ class Settings extends React.PureComponent {
selected={this.props.windowTheme || 'none'} selected={this.props.windowTheme || 'none'}
onChange={this.props.onChange.bind(null, 'windowTheme')} onChange={this.props.onChange.bind(null, 'windowTheme')}
/> />
<input
title="filename"
placeholder="File name..."
value={this.props.filename}
name="filename"
onChange={this.handleInputChange}
/>
<FontSelect <FontSelect
selected={this.props.fontFamily || 'Hack'} selected={this.props.fontFamily || 'Hack'}
onChange={this.props.onChange.bind(null, 'fontFamily')} onChange={this.props.onChange.bind(null, 'fontFamily')}
@ -203,6 +215,17 @@ class Settings extends React.PureComponent {
.red { .red {
color: red; color: red;
} }
input {
padding: 8px;
width: 100%;
font-size: 12px;
color: ${COLORS.SECONDARY};
background: ${COLORS.BLACK};
border: none;
border-bottom: solid 1px ${COLORS.SECONDARY};
outline: none;
}
`} `}
</style> </style>
</div> </div>

@ -20,7 +20,7 @@
"dependencies": { "dependencies": {
"axios": "^0.18.0", "axios": "^0.18.0",
"codemirror": "^5.40.2", "codemirror": "^5.40.2",
"codemirror-graphql": "^0.8.2", "codemirror-graphql": "0.7.1",
"codemirror-mode-elixir": "^1.1.1", "codemirror-mode-elixir": "^1.1.1",
"dom-to-image": "^2.5.2", "dom-to-image": "^2.5.2",
"downshift": "^3.1.4", "downshift": "^3.1.4",

@ -13,7 +13,10 @@ import { saveState } from '../lib/util'
class Index extends React.Component { class Index extends React.Component {
onEditorUpdate = state => { onEditorUpdate = state => {
updateQueryString(this.props.router, state) updateQueryString(this.props.router, state)
saveState(localStorage, omit(state, ['code', 'backgroundImage', 'backgroundImageSelection'])) saveState(
localStorage,
omit(state, ['code', 'backgroundImage', 'backgroundImageSelection', 'filename'])
)
} }
render() { render() {

Loading…
Cancel
Save