fix: moved sidenav logic to saga

This commit is contained in:
Ahmad Abdolsaheb
2019-02-28 22:25:38 +03:00
committed by Stuart Taylor
parent b6198417d0
commit 23b01464ac
2 changed files with 25 additions and 32 deletions

View File

@ -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';

View File

@ -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)];
}