move format code into editor and make it work again

main
Mike Fix 6 years ago
parent 0aa7432022
commit 90a0ead95b

@ -34,7 +34,7 @@ import {
DEFAULT_LANGUAGE DEFAULT_LANGUAGE
} from '../lib/constants' } from '../lib/constants'
import { serializeState, getQueryStringState } from '../lib/routing' import { serializeState, getQueryStringState } from '../lib/routing'
import { getState, escapeHtml, unescapeHtml } from '../lib/util' import { getState, escapeHtml, unescapeHtml, formatCode } from '../lib/util'
import LanguageIcon from './svg/Language' import LanguageIcon from './svg/Language'
import ThemeIcon from './svg/Theme' import ThemeIcon from './svg/Theme'
@ -264,6 +264,13 @@ class Editor extends React.Component {
} }
} }
format = () =>
formatCode(this.state.code)
.then(this.updateCode)
.catch(() => {
// create toast here in the future
})
render() { render() {
const { const {
loading, loading,
@ -329,6 +336,7 @@ class Editor extends React.Component {
{...config} {...config}
onChange={this.updateSetting} onChange={this.updateSetting}
resetDefaultSettings={this.resetDefaultSettings} resetDefaultSettings={this.resetDefaultSettings}
format={this.format}
/> />
<div className="buttons"> <div className="buttons">
{this.props.api.tweet && {this.props.api.tweet &&

@ -7,7 +7,7 @@ import Slider from './Slider'
import Toggle from './Toggle' import Toggle from './Toggle'
import WindowPointer from './WindowPointer' import WindowPointer from './WindowPointer'
import { COLORS } from '../lib/constants' import { COLORS } from '../lib/constants'
import { toggle, formatCode } from '../lib/util' import { toggle } from '../lib/util'
import SettingsIcon from './svg/Settings' import SettingsIcon from './svg/Settings'
import * as Arrows from './svg/Arrows' import * as Arrows from './svg/Arrows'
//import Remove from './svg/Remove' //import Remove from './svg/Remove'
@ -304,13 +304,6 @@ class Settings extends React.PureComponent {
handleClickOutside = () => this.setState({ isVisible: false }) handleClickOutside = () => this.setState({ isVisible: false })
format = () =>
formatCode(this.props.code)
.then(this.props.onChange.bind(this, 'code'))
.catch(() => {
// create toast here in the future
})
selectMenu = selectedMenu => () => this.setState({ selectedMenu }) selectMenu = selectedMenu => () => this.setState({ selectedMenu })
renderContent = () => { renderContent = () => {
@ -341,7 +334,7 @@ class Settings extends React.PureComponent {
/> />
) )
case 'Misc': case 'Misc':
return <MiscSettings format={this.format} reset={this.props.resetDefaultSettings} /> return <MiscSettings format={this.props.format} reset={this.props.resetDefaultSettings} />
default: default:
return null return null
} }

Loading…
Cancel
Save