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);
|
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) {
|
renderPanels(parents, pages) {
|
||||||
if (!parents) {
|
if (!parents) {
|
||||||
return 'No Parents Here';
|
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 { toggleExpandedState } from './';
|
||||||
|
import { types as appTypes } from '../../../../../redux';
|
||||||
import { openDonationModal } from '../../../../../redux';
|
|
||||||
|
|
||||||
function* showDonateModalSaga() {
|
function* showDonateModalSaga() {
|
||||||
console.log('hello');
|
let guideRegex = /^\/guide\//;
|
||||||
yield put(openDonationModal());
|
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) {
|
export function createSideNavigationSaga() {
|
||||||
takeEvery(types.toggleDisplaySideNav, showDonateModalSaga);
|
return [takeEvery(appTypes.appMount, showDonateModalSaga)];
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user