From 67119fbc7ce4b5e800bdb7d9b65655c0150e750c Mon Sep 17 00:00:00 2001 From: Ahmad Abdolsaheb Date: Thu, 28 Feb 2019 11:20:30 +0300 Subject: [PATCH] fix: removed context and added saga --- .../guide/redux/side-navigation-saga.js | 0 client/src/contexts/GuideNavigationContext.js | 95 ------------------- 2 files changed, 95 deletions(-) create mode 100644 client/src/components/layouts/components/guide/redux/side-navigation-saga.js delete mode 100644 client/src/contexts/GuideNavigationContext.js diff --git a/client/src/components/layouts/components/guide/redux/side-navigation-saga.js b/client/src/components/layouts/components/guide/redux/side-navigation-saga.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/client/src/contexts/GuideNavigationContext.js b/client/src/contexts/GuideNavigationContext.js deleted file mode 100644 index 9ccf32e1af..0000000000 --- a/client/src/contexts/GuideNavigationContext.js +++ /dev/null @@ -1,95 +0,0 @@ -import React, { Component, createContext } from 'react'; -import PropTypes from 'prop-types'; - -const noop = () => {}; - -const initialState = { displaySideNav: false, expandedState: {} }; - -const { Provider, Consumer } = createContext({ - ...initialState, - toggleDisplaySideNav: () => { - console.warn('no method from provider'); - }, - toggleExpandedState: () => { - console.warn('no method from provider'); - } -}); - -const propTypes = { - children: PropTypes.any -}; - -class NavigationContextProvider extends Component { - constructor(...props) { - super(...props); - - this.state = { ...initialState }; - - this.toggleSideNav = this.toggleSideNav.bind(this); - this.toggleExpandedState = this.toggleExpandedState.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.toggleExpandedState(path); - }); - } - return null; - } - - toggleExpandedState(path) { - return this.setState(state => ({ - ...state, - expandedState: { - ...state.expandedState, - [path]: !state.expandedState[path] - } - })); - } - - toggleSideNav() { - return this.setState(state => ({ - ...state, - displaySideNav: !this.state.displaySideNav - })); - } - - render() { - const { children } = this.props; - const { displaySideNav, expandedState } = this.state; - return ( - - {children} - - ); - } -} - -NavigationContextProvider.displayName = 'NavigationContextProvider'; -NavigationContextProvider.propTypes = propTypes; - -export const NavigationContext = Consumer; -export default NavigationContextProvider;