import React, { Component } from 'react'; import { Layout, Drawer, Header, Navigation, Content, Footer, FooterSection, FooterDropDownSection, FooterLinkList, Grid, Cell, Icon, } from 'react-mdl'; import { Link } from 'react-router'; import style from './styles.scss'; import ErrorContainer from './error/error-container'; import UserContainer from './user/user-container'; import ShowUserContainer from './user/show-user-container'; const base = { name: 'Unleash', link: '/', }; function replace (input, params) { if (!params) { return input; } Object.keys(params).forEach(key => { input = input.replace(`:${key}`, params[key]); }); return input; } export default class App extends Component { static contextTypes = { router: React.PropTypes.object, } componentWillReceiveProps (nextProps) { if (this.props.location.pathname !== nextProps.location.pathname) { clearTimeout(this.timer); this.timer = setTimeout(() => { window.requestAnimationFrame(() => { document.querySelector('.mdl-layout__content').scrollTop = 0; }); const layout = document.querySelector('.mdl-js-layout'); const drawer = document.querySelector('.mdl-layout__drawer'); // hack, might get a built in alternative later if (drawer.classList.contains('is-visible')) { layout.MaterialLayout.toggleDrawer(); } }, 10); } } getSections () { const { routes, params } = this.props; const unique = {}; let result = [base].concat(routes.splice(1).map((routeEntry) => ({ name: replace(routeEntry.pageTitle, params), link: replace(routeEntry.link || routeEntry.path, params), }))).filter(entry => { if (!unique[entry.link]) { unique[entry.link] = true; return true; } return false; }); // mutate document.title: document.title = result .map(e => e.name) .reverse() .join(' - '); if (result.length > 2) { result = result.splice(1); } return result; } getTitleWithLinks () { const result = this.getSections(); return ( {result.map((entry, index) => ( {entry.name} {(index + 1) < result.length ? ' / ' : null} ))} ); } render () { const createListItem = (path, caption, icon) => {icon && } {caption} ; return (
Github
{createListItem('/features', 'Feature toggles', 'list')} {createListItem('/strategies', 'Strategies', 'extension')} {createListItem('/history', 'Event history', 'history')} {createListItem('/archive', 'Archived toggles', 'archive')} {createListItem('/applications', 'Applications', 'apps')} {this.props.children}
); } };