Fix unknown hike redirect to map

This commit is contained in:
Berkeley Martinez
2016-03-02 22:19:04 -08:00
parent 71ebfade15
commit 2df87854c4
6 changed files with 47 additions and 7 deletions

View File

@ -0,0 +1,24 @@
import { hardGoTo } from '../../common/app/redux/types';
const loc = typeof window !== 'undefined' ?
window.location :
{};
export default () => ({ dispatch }) => next => {
return function hardGoToSaga(action) {
const result = next(action);
if (action.type !== hardGoTo) {
return result;
}
if (!loc.pathname) {
dispatch({
type: 'app.error',
error: new Error('no location object found')
});
}
loc.pathname = action.payload || '/map';
return null;
};
};

View File

@ -1,5 +1,6 @@
import errSaga from './err-saga';
import titleSaga from './title-saga';
import localStorageSaga from './local-storage-saga';
import hardGoToSaga from './hard-go-to-saga';
export default [errSaga, titleSaga, localStorageSaga];
export default [ errSaga, titleSaga, localStorageSaga, hardGoToSaga ];

View File

@ -27,3 +27,6 @@ export const setUser = createAction(types.setUser);
// updatePoints(points: Number) => Action
export const updatePoints = createAction(types.updatePoints);
// hardGoTo(path: String) => Action
export const hardGoTo = createAction(types.hardGoTo);

View File

@ -6,7 +6,9 @@ const types = [
'makeToast',
'updatePoints',
'handleError'
'handleError',
// used to hit the server
'hardGoTo'
];
export default types

View File

@ -29,7 +29,6 @@ const mapStateToProps = createSelector(
const fetchOptions = {
fetchAction: 'fetchHikes',
isPrimed: ({ hikes }) => hikes && !!hikes.length,
getActionArgs: ({ params: { dashedName } }) => [ dashedName ],
shouldContainerFetch(props, nextProps) {

View File

@ -5,6 +5,7 @@ import Vimeo from 'react-vimeo';
import { createSelector } from 'reselect';
import debug from 'debug';
import { hardGoTo } from '../../../redux/actions';
import { toggleQuestionView } from '../redux/actions';
import { getCurrentHike } from '../redux/selectors';
@ -33,11 +34,18 @@ export class Lecture extends React.Component {
// actions
toggleQuestionView: PropTypes.func,
// ui
id: PropTypes.string,
id: PropTypes.number,
description: PropTypes.array,
dashedName: PropTypes.string
dashedName: PropTypes.string,
hardGoTo: PropTypes.func
};
componentWillMount() {
if (!this.props.id) {
this.props.hardGoTo('/map');
}
}
shouldComponentUpdate(nextProps) {
const { props } = this;
return nextProps.id !== props.id;
@ -70,7 +78,7 @@ export class Lecture extends React.Component {
<Vimeo
onError={ this.handleError }
onFinish= { toggleQuestionView }
videoId={ id } />
videoId={ '' + id } />
</Row>
<Row>
<article>
@ -89,4 +97,7 @@ export class Lecture extends React.Component {
}
}
export default connect(mapStateToProps, { toggleQuestionView })(Lecture);
export default connect(
mapStateToProps,
{ hardGoTo, toggleQuestionView }
)(Lecture);