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:
Berkeley Martinez
2016-08-13 17:53:03 -07:00
parent 1c460e3319
commit c3d9d48b01
2 changed files with 23 additions and 11 deletions

View File

@ -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); const legacyCode = getLegacyCode(legacyKey);
if (legacyCode) { if (legacyCode) {
return savedCodeFound(legacyToFile(legacyCode, files, key)); finalFiles = legacyToFile(legacyCode, files, key);
} }
return null; }
if (finalFiles) {
return Observable.of(
makeToast({
message: 'I found some saved work. Loading now'
}),
savedCodeFound(finalFiles),
updateMain()
);
}
return Observable.empty();
}); });
} }

View File

@ -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) {