import React from 'react'; import { Link, hashHistory } from 'react-router'; import FlatButton from 'material-ui/FlatButton'; import 'jquery-slimscroll/jquery.slimscroll.min'; import { loggedUser, planScheduler, providerScheduler, visitReporter, } from 'utils/authorization'; class SidebarContent extends React.Component { state = { user: { user_uuid: '', }, } componentDidMount() { const nav = this.nav; const $nav = $(nav); // scroll $nav.slimscroll({ height: '100%' }); // Append icon to submenu // Append to child `div` $nav.find('.prepend-icon').children('div').prepend('keyboard_arrow_right'); // AccordionNav const slideTime = 250; const $lists = $nav.find('ul').parent('li'); $lists.append('arrow_drop_down'); const $As = $lists.children('a'); // Disable A link that has ul $As.on('click', event => event.preventDefault()); // Accordion nav $nav.on('click', (e) => { const target = e.target; const $parentLi = $(target).closest('li'); // closest, insead of parent, so it still works when click on i icons if (!$parentLi.length) return; // return if doesn't click on li const $subUl = $parentLi.children('ul'); // let depth = $subUl.parents().length; // but some li has no sub ul, so... const depth = $parentLi.parents().length + 1; // filter out all elements (except target) at current depth or greater const allAtDepth = $nav.find('ul').filter(function () { if ($(this).parents().length >= depth && this !== $subUl.get(0)) { return true; } return false; }); allAtDepth.slideUp(slideTime).closest('li').removeClass('open'); // Toggle target if ($parentLi.has('ul').length) { $parentLi.toggleClass('open'); } $subUl.stop().slideToggle(slideTime); }); // HighlightActiveItems const $links = $nav.find('a'); const currentLocation = hashHistory.getCurrentLocation(); function highlightActive(pathname) { const path = `#${pathname}`; $links.each((i, link) => { const $link = $(link); const $li = $link.parent('li'); const href = $link.attr('href'); // console.log(href); if ($li.hasClass('active')) { $li.removeClass('active'); } if (path.indexOf(href) === 0) { $li.addClass('active'); } }); } highlightActive(currentLocation.pathname); hashHistory.listen((location) => { highlightActive(location.pathname); }); const user = JSON.parse(localStorage.getItem('loggedUser')); if (user) { this.setState(Object.assign(this.state, { user: user })); } } render() { return ( ); } } module.exports = SidebarContent;