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 { makeToast } from '../../common/app/toasts/redux/actions';
|
||||
import types from '../../common/app/routes/challenges/redux/types';
|
||||
import {
|
||||
savedCodeFound
|
||||
savedCodeFound,
|
||||
updateMain
|
||||
} from '../../common/app/routes/challenges/redux/actions';
|
||||
import {
|
||||
updateContents
|
||||
@ -50,7 +53,8 @@ export default function codeStorageSaga(actions$, getState) {
|
||||
type === types.saveCode ||
|
||||
type === types.loadCode
|
||||
))
|
||||
.map(({ type }) => {
|
||||
.flatMap(({ type }) => {
|
||||
let finalFiles;
|
||||
const {
|
||||
challengesApp: {
|
||||
id = '',
|
||||
@ -63,14 +67,26 @@ export default function codeStorageSaga(actions$, getState) {
|
||||
store.set(id, files);
|
||||
return null;
|
||||
}
|
||||
|
||||
const codeFound = getCode(id);
|
||||
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) {
|
||||
return savedCodeFound(legacyToFile(legacyCode, files, key));
|
||||
|
||||
if (finalFiles) {
|
||||
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 {
|
||||
executeChallenge,
|
||||
updateMain,
|
||||
updateFile,
|
||||
loadCode
|
||||
} from '../../redux/actions';
|
||||
@ -41,7 +40,6 @@ const mapStateToProps = createSelector(
|
||||
const bindableActions = {
|
||||
executeChallenge,
|
||||
updateFile,
|
||||
updateMain,
|
||||
loadCode
|
||||
};
|
||||
|
||||
@ -55,13 +53,11 @@ export class Challenge extends PureComponent {
|
||||
mode: PropTypes.string,
|
||||
updateFile: PropTypes.func,
|
||||
executeChallenge: PropTypes.func,
|
||||
updateMain: PropTypes.func,
|
||||
loadCode: PropTypes.func
|
||||
};
|
||||
|
||||
componentDidMount() {
|
||||
this.props.loadCode();
|
||||
this.props.updateMain();
|
||||
}
|
||||
|
||||
componentWillReceiveProps(nextProps) {
|
||||
|
Reference in New Issue
Block a user