Update file on codemirror change
This commit is contained in:
@ -8,6 +8,7 @@ import Editor from './Editor.jsx';
|
|||||||
import SidePanel from './Side-Panel.jsx';
|
import SidePanel from './Side-Panel.jsx';
|
||||||
import Preview from './Preview.jsx';
|
import Preview from './Preview.jsx';
|
||||||
import { challengeSelector } from '../redux/selectors';
|
import { challengeSelector } from '../redux/selectors';
|
||||||
|
import { updateFile } from '../redux/actions';
|
||||||
|
|
||||||
const mapStateToProps = createSelector(
|
const mapStateToProps = createSelector(
|
||||||
challengeSelector,
|
challengeSelector,
|
||||||
@ -16,12 +17,15 @@ const mapStateToProps = createSelector(
|
|||||||
state => state.challengesApp.path,
|
state => state.challengesApp.path,
|
||||||
({ challenge, showPreview, mode }, tests, files = {}, path = '') => ({
|
({ challenge, showPreview, mode }, tests, files = {}, path = '') => ({
|
||||||
content: files[path] && files[path].contents || '',
|
content: files[path] && files[path].contents || '',
|
||||||
|
file: files[path],
|
||||||
showPreview,
|
showPreview,
|
||||||
mode,
|
mode,
|
||||||
tests
|
tests
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const bindableActions = { updateFile };
|
||||||
|
|
||||||
export class Challenge extends PureComponent {
|
export class Challenge extends PureComponent {
|
||||||
static displayName = 'Challenge';
|
static displayName = 'Challenge';
|
||||||
|
|
||||||
@ -45,7 +49,13 @@ export class Challenge extends PureComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { content, mode, showPreview } = this.props;
|
const {
|
||||||
|
content,
|
||||||
|
updateFile,
|
||||||
|
file,
|
||||||
|
mode,
|
||||||
|
showPreview
|
||||||
|
} = this.props;
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<Col
|
<Col
|
||||||
@ -59,6 +69,7 @@ export class Challenge extends PureComponent {
|
|||||||
<Editor
|
<Editor
|
||||||
content={ content }
|
content={ content }
|
||||||
mode={ mode }
|
mode={ mode }
|
||||||
|
updateFile={ content => updateFile(content, file) }
|
||||||
/>
|
/>
|
||||||
</Col>
|
</Col>
|
||||||
{ this.renderPreview(showPreview) }
|
{ this.renderPreview(showPreview) }
|
||||||
@ -67,4 +78,4 @@ export class Challenge extends PureComponent {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default connect(mapStateToProps)(Challenge);
|
export default connect(mapStateToProps, bindableActions)(Challenge);
|
||||||
|
@ -30,7 +30,8 @@ export class Editor extends PureComponent {
|
|||||||
static propTypes = {
|
static propTypes = {
|
||||||
height: PropTypes.number,
|
height: PropTypes.number,
|
||||||
content: PropTypes.string,
|
content: PropTypes.string,
|
||||||
mode: PropTypes.string
|
mode: PropTypes.string,
|
||||||
|
updateFile: PropTypes.func
|
||||||
};
|
};
|
||||||
|
|
||||||
static defaultProps = {
|
static defaultProps = {
|
||||||
@ -39,7 +40,7 @@ export class Editor extends PureComponent {
|
|||||||
};
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { content, height, mode } = this.props;
|
const { content, height, mode, updateFile } = this.props;
|
||||||
const style = {};
|
const style = {};
|
||||||
if (height) {
|
if (height) {
|
||||||
style.height = height + 'px';
|
style.height = height + 'px';
|
||||||
@ -50,6 +51,7 @@ export class Editor extends PureComponent {
|
|||||||
style={ style }>
|
style={ style }>
|
||||||
<NoSSR>
|
<NoSSR>
|
||||||
<Codemirror
|
<Codemirror
|
||||||
|
onChange={ updateFile }
|
||||||
options={{ ...options, mode }}
|
options={{ ...options, mode }}
|
||||||
value={ content } />
|
value={ content } />
|
||||||
</NoSSR>
|
</NoSSR>
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import { createAction } from 'redux-actions';
|
import { createAction } from 'redux-actions';
|
||||||
|
import { updateContents } from '../../../../utils/polyvinyl';
|
||||||
|
|
||||||
import types from './types';
|
import types from './types';
|
||||||
|
|
||||||
@ -34,5 +35,8 @@ export const updateFilter = createAction(
|
|||||||
export const clearFilter = createAction(types.clearFilter);
|
export const clearFilter = createAction(types.clearFilter);
|
||||||
|
|
||||||
// files
|
// files
|
||||||
export const updateFile = createAction(types.updateFile);
|
export const updateFile = createAction(
|
||||||
|
types.updateFile,
|
||||||
|
(content, file) => updateContents(content, file)
|
||||||
|
);
|
||||||
export const updateFiles = createAction(types.updateFiles);
|
export const updateFiles = createAction(types.updateFiles);
|
||||||
|
Reference in New Issue
Block a user