diff --git a/src/components/StrategyEditor/StrategyEditor.container.js b/src/components/StrategyEditor/StrategyEditor.container.js index 20af893d3..529f393ad 100644 --- a/src/components/StrategyEditor/StrategyEditor.container.js +++ b/src/components/StrategyEditor/StrategyEditor.container.js @@ -11,6 +11,7 @@ const mapStateToProps = (state = {}) => ({ activeMarket: getActiveMarket(state), authToken: getAuthToken(state), strategyId: getStrategyId(state), + strategyContent: state.ui.content, }) const mapDispatchToProps = dispatch => ({ diff --git a/src/components/StrategyEditor/StrategyEditor.js b/src/components/StrategyEditor/StrategyEditor.js index f92a777f5..a7c96faf3 100644 --- a/src/components/StrategyEditor/StrategyEditor.js +++ b/src/components/StrategyEditor/StrategyEditor.js @@ -49,12 +49,19 @@ export default class StrategyEditor extends React.PureComponent { gaCreateStrategy: PropTypes.func.isRequired, onIndicatorsChange: PropTypes.func.isRequired, clearBacktestOptions: PropTypes.func.isRequired, + strategyContent: PropTypes.objectOf( + PropTypes.oneOfType([ + PropTypes.string.isRequired, + PropTypes.oneOf([null]).isRequired, + ]), + ), } static defaultProps = { strategyId: '', moveable: false, removeable: false, renderResults: true, + strategyContent: {}, } state = { @@ -69,6 +76,13 @@ export default class StrategyEditor extends React.PureComponent { openExistingStrategyModalOpen: false, } + componentDidMount() { + const { strategyContent } = this.props + this.setState(() => ({ + strategy: strategyContent, + })) + } + onCreateNewStrategy = (label, templateLabel) => { const strategy = { label } const template = Templates.find(t => t.label === templateLabel) @@ -395,7 +409,7 @@ export default class StrategyEditor extends React.PureComponent { openExistingStrategyModalOpen, } = this.state - if (!strategy) { + if (!strategy || _isEmpty(strategy)) { return this.renderPanel(this.renderEmptyContent()) } diff --git a/src/pages/StrategyEditor/StrategyEditor.js b/src/pages/StrategyEditor/StrategyEditor.js index ff74938aa..9b0afbc85 100644 --- a/src/pages/StrategyEditor/StrategyEditor.js +++ b/src/pages/StrategyEditor/StrategyEditor.js @@ -60,10 +60,6 @@ export default class StrategyEditorPage extends React.Component { .then(t => this.setState(() => ({ docsText: t }))) } - componentWillUnmount() { - this.setContent(null) - } - onIndicatorsChange = (indicators) => { // TODO: Better color generation; to save time we generate enough colors for // all indicators here, but optimally we'd switch on i.constructor.ui