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 errSaga from './err-saga';
|
||||||
import titleSaga from './title-saga';
|
import titleSaga from './title-saga';
|
||||||
import localStorageSaga from './local-storage-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
|
// updatePoints(points: Number) => Action
|
||||||
export const updatePoints = createAction(types.updatePoints);
|
export const updatePoints = createAction(types.updatePoints);
|
||||||
|
|
||||||
|
// hardGoTo(path: String) => Action
|
||||||
|
export const hardGoTo = createAction(types.hardGoTo);
|
||||||
|
@ -6,7 +6,9 @@ const types = [
|
|||||||
|
|
||||||
'makeToast',
|
'makeToast',
|
||||||
'updatePoints',
|
'updatePoints',
|
||||||
'handleError'
|
'handleError',
|
||||||
|
// used to hit the server
|
||||||
|
'hardGoTo'
|
||||||
];
|
];
|
||||||
|
|
||||||
export default types
|
export default types
|
||||||
|
@ -29,7 +29,6 @@ const mapStateToProps = createSelector(
|
|||||||
|
|
||||||
const fetchOptions = {
|
const fetchOptions = {
|
||||||
fetchAction: 'fetchHikes',
|
fetchAction: 'fetchHikes',
|
||||||
|
|
||||||
isPrimed: ({ hikes }) => hikes && !!hikes.length,
|
isPrimed: ({ hikes }) => hikes && !!hikes.length,
|
||||||
getActionArgs: ({ params: { dashedName } }) => [ dashedName ],
|
getActionArgs: ({ params: { dashedName } }) => [ dashedName ],
|
||||||
shouldContainerFetch(props, nextProps) {
|
shouldContainerFetch(props, nextProps) {
|
||||||
|
@ -5,6 +5,7 @@ import Vimeo from 'react-vimeo';
|
|||||||
import { createSelector } from 'reselect';
|
import { createSelector } from 'reselect';
|
||||||
import debug from 'debug';
|
import debug from 'debug';
|
||||||
|
|
||||||
|
import { hardGoTo } from '../../../redux/actions';
|
||||||
import { toggleQuestionView } from '../redux/actions';
|
import { toggleQuestionView } from '../redux/actions';
|
||||||
import { getCurrentHike } from '../redux/selectors';
|
import { getCurrentHike } from '../redux/selectors';
|
||||||
|
|
||||||
@ -33,11 +34,18 @@ export class Lecture extends React.Component {
|
|||||||
// actions
|
// actions
|
||||||
toggleQuestionView: PropTypes.func,
|
toggleQuestionView: PropTypes.func,
|
||||||
// ui
|
// ui
|
||||||
id: PropTypes.string,
|
id: PropTypes.number,
|
||||||
description: PropTypes.array,
|
description: PropTypes.array,
|
||||||
dashedName: PropTypes.string
|
dashedName: PropTypes.string,
|
||||||
|
hardGoTo: PropTypes.func
|
||||||
};
|
};
|
||||||
|
|
||||||
|
componentWillMount() {
|
||||||
|
if (!this.props.id) {
|
||||||
|
this.props.hardGoTo('/map');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
shouldComponentUpdate(nextProps) {
|
shouldComponentUpdate(nextProps) {
|
||||||
const { props } = this;
|
const { props } = this;
|
||||||
return nextProps.id !== props.id;
|
return nextProps.id !== props.id;
|
||||||
@ -70,7 +78,7 @@ export class Lecture extends React.Component {
|
|||||||
<Vimeo
|
<Vimeo
|
||||||
onError={ this.handleError }
|
onError={ this.handleError }
|
||||||
onFinish= { toggleQuestionView }
|
onFinish= { toggleQuestionView }
|
||||||
videoId={ id } />
|
videoId={ '' + id } />
|
||||||
</Row>
|
</Row>
|
||||||
<Row>
|
<Row>
|
||||||
<article>
|
<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