Fix unknown hike redirect to map
This commit is contained in:
24
client/sagas/hard-go-to-saga.js
Normal file
24
client/sagas/hard-go-to-saga.js
Normal 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;
|
||||
};
|
||||
};
|
@ -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 ];
|
||||
|
@ -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);
|
||||
|
@ -6,7 +6,9 @@ const types = [
|
||||
|
||||
'makeToast',
|
||||
'updatePoints',
|
||||
'handleError'
|
||||
'handleError',
|
||||
// used to hit the server
|
||||
'hardGoTo'
|
||||
];
|
||||
|
||||
export default types
|
||||
|
@ -29,7 +29,6 @@ const mapStateToProps = createSelector(
|
||||
|
||||
const fetchOptions = {
|
||||
fetchAction: 'fetchHikes',
|
||||
|
||||
isPrimed: ({ hikes }) => hikes && !!hikes.length,
|
||||
getActionArgs: ({ params: { dashedName } }) => [ dashedName ],
|
||||
shouldContainerFetch(props, nextProps) {
|
||||
|
@ -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);
|
||||
|
Reference in New Issue
Block a user