fix: moved sidenav logic to saga
This commit is contained in:
committed by
Stuart Taylor
parent
b6198417d0
commit
23b01464ac
@ -27,30 +27,6 @@ class SideNav extends Component {
|
||||
this.renderParent = this.renderParent.bind(this);
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
if (typeof window !== 'undefined') {
|
||||
const pathMap = window.location.pathname
|
||||
.slice(1)
|
||||
.split('/')
|
||||
.slice(0, -1)
|
||||
.reduce((map, current, i, pathArray) => {
|
||||
const path =
|
||||
i !== 0 ? map[pathArray[i - 1]] + `/${current}` : `/${current}`;
|
||||
return {
|
||||
...map,
|
||||
[current]: path
|
||||
};
|
||||
}, {});
|
||||
|
||||
return Object.keys(pathMap)
|
||||
.map(key => pathMap[key])
|
||||
.forEach(path => {
|
||||
this.props.toggleExpandedState(path);
|
||||
});
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
renderPanels(parents, pages) {
|
||||
if (!parents) {
|
||||
return 'No Parents Here';
|
||||
|
@ -1,14 +1,31 @@
|
||||
import { takeEvery, put } from 'redux-saga/effects';
|
||||
import { takeEvery, put, all } from 'redux-saga/effects';
|
||||
|
||||
// import { put, takeEvery, take } from 'redux-saga/effects';
|
||||
|
||||
import { openDonationModal } from '../../../../../redux';
|
||||
import { toggleExpandedState } from './';
|
||||
import { types as appTypes } from '../../../../../redux';
|
||||
|
||||
function* showDonateModalSaga() {
|
||||
console.log('hello');
|
||||
yield put(openDonationModal());
|
||||
let guideRegex = /^\/guide\//;
|
||||
let onGuide = guideRegex.test(window.location.pathname);
|
||||
if (onGuide && typeof window !== 'undefined') {
|
||||
const pathMap = window.location.pathname
|
||||
.slice(1)
|
||||
.split('/')
|
||||
.slice(0, -1)
|
||||
.reduce((map, current, i, pathArray) => {
|
||||
const path =
|
||||
i !== 0 ? map[pathArray[i - 1]] + `/${current}` : `/${current}`;
|
||||
return {
|
||||
...map,
|
||||
[current]: path
|
||||
};
|
||||
}, {});
|
||||
|
||||
let routes = Object.keys(pathMap).map(key => pathMap[key]);
|
||||
|
||||
yield all(routes.map(route => put(toggleExpandedState(route))));
|
||||
}
|
||||
}
|
||||
|
||||
export function createSideNavigationSaga(types) {
|
||||
takeEvery(types.toggleDisplaySideNav, showDonateModalSaga);
|
||||
export function createSideNavigationSaga() {
|
||||
return [takeEvery(appTypes.appMount, showDonateModalSaga)];
|
||||
}
|
||||
|
Reference in New Issue
Block a user