Fix(challenges): Let code load update the main frame
Also display a message to the user that we loaded in-progress code.
This commit is contained in:
@ -1,8 +1,11 @@
|
|||||||
|
import { Observable } from 'rx';
|
||||||
import store from 'store';
|
import store from 'store';
|
||||||
|
|
||||||
|
import { makeToast } from '../../common/app/toasts/redux/actions';
|
||||||
import types from '../../common/app/routes/challenges/redux/types';
|
import types from '../../common/app/routes/challenges/redux/types';
|
||||||
import {
|
import {
|
||||||
savedCodeFound
|
savedCodeFound,
|
||||||
|
updateMain
|
||||||
} from '../../common/app/routes/challenges/redux/actions';
|
} from '../../common/app/routes/challenges/redux/actions';
|
||||||
import {
|
import {
|
||||||
updateContents
|
updateContents
|
||||||
@ -50,7 +53,8 @@ export default function codeStorageSaga(actions$, getState) {
|
|||||||
type === types.saveCode ||
|
type === types.saveCode ||
|
||||||
type === types.loadCode
|
type === types.loadCode
|
||||||
))
|
))
|
||||||
.map(({ type }) => {
|
.flatMap(({ type }) => {
|
||||||
|
let finalFiles;
|
||||||
const {
|
const {
|
||||||
challengesApp: {
|
challengesApp: {
|
||||||
id = '',
|
id = '',
|
||||||
@ -63,14 +67,26 @@ export default function codeStorageSaga(actions$, getState) {
|
|||||||
store.set(id, files);
|
store.set(id, files);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const codeFound = getCode(id);
|
const codeFound = getCode(id);
|
||||||
if (codeFound) {
|
if (codeFound) {
|
||||||
return savedCodeFound(codeFound);
|
finalFiles = codeFound;
|
||||||
|
} else {
|
||||||
|
const legacyCode = getLegacyCode(legacyKey);
|
||||||
|
if (legacyCode) {
|
||||||
|
finalFiles = legacyToFile(legacyCode, files, key);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
const legacyCode = getLegacyCode(legacyKey);
|
|
||||||
if (legacyCode) {
|
if (finalFiles) {
|
||||||
return savedCodeFound(legacyToFile(legacyCode, files, key));
|
return Observable.of(
|
||||||
|
makeToast({
|
||||||
|
message: 'I found some saved work. Loading now'
|
||||||
|
}),
|
||||||
|
savedCodeFound(finalFiles),
|
||||||
|
updateMain()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
return null;
|
return Observable.empty();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,6 @@ import BugModal from '../Bug-Modal.jsx';
|
|||||||
import { challengeSelector } from '../../redux/selectors';
|
import { challengeSelector } from '../../redux/selectors';
|
||||||
import {
|
import {
|
||||||
executeChallenge,
|
executeChallenge,
|
||||||
updateMain,
|
|
||||||
updateFile,
|
updateFile,
|
||||||
loadCode
|
loadCode
|
||||||
} from '../../redux/actions';
|
} from '../../redux/actions';
|
||||||
@ -41,7 +40,6 @@ const mapStateToProps = createSelector(
|
|||||||
const bindableActions = {
|
const bindableActions = {
|
||||||
executeChallenge,
|
executeChallenge,
|
||||||
updateFile,
|
updateFile,
|
||||||
updateMain,
|
|
||||||
loadCode
|
loadCode
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -55,13 +53,11 @@ export class Challenge extends PureComponent {
|
|||||||
mode: PropTypes.string,
|
mode: PropTypes.string,
|
||||||
updateFile: PropTypes.func,
|
updateFile: PropTypes.func,
|
||||||
executeChallenge: PropTypes.func,
|
executeChallenge: PropTypes.func,
|
||||||
updateMain: PropTypes.func,
|
|
||||||
loadCode: PropTypes.func
|
loadCode: PropTypes.func
|
||||||
};
|
};
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
this.props.loadCode();
|
this.props.loadCode();
|
||||||
this.props.updateMain();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillReceiveProps(nextProps) {
|
componentWillReceiveProps(nextProps) {
|
||||||
|
Reference in New Issue
Block a user