import React from 'react'; import { connect } from 'react-redux' import * as selectors from '../selectors' import { Tab, Tabs, TabList, TabPanel } from 'react-tabs'; import Search from './Search.jsx'; import TagListPanel from './TagListPanel.jsx'; import ToolbarBottomActions from './ToolbarBottomActions.jsx'; import copy from '../js/data/copy.json'; class Toolbar extends React.Component { constructor(props) { super(props); this.state = { tabNum: -1 }; } toggleTab(tabNum) { this.setState({ tabNum: (this.state.tabNum === tabNum) ? -1 : tabNum }); } renderClosePanel() { return (
this.toggleTab(-1)}>
); } renderSearch() { if (this.props.features.USE_SEARCH) { return ( ) } } goToNarrative(narrative) { this.setState({ tabNum: -1 }, () => { this.props.actions.updateNarrative(narrative); }); } renderToolbarNarrativePanel() { return (

Focus stories

Here are some highlighted stories

{this.props.narratives.map((narr) => { return (
) })}
); } renderToolbarTagPanel() { if (this.props.features.USE_TAGS && this.props.tags.children) { return ( ) } return ''; } renderToolbarTab(tabNum, label) { const isActive = (this.state.tabNum === tabNum); let classes = (isActive) ? 'toolbar-tab active' : 'toolbar-tab'; return (
{ this.toggleTab(tabNum); }}>
{label}
); } renderToolbarTabs() { const title = copy[this.props.language].toolbar.title; const isTags = this.props.tags && (this.props.tags.children > 0); return (

{title}

{/*this.renderToolbarTab(0, 'search')*/} {this.renderToolbarTab(0, 'Focus stories')} {this.renderToolbarTab(1, 'Explore freely')}
) } renderToolbarPanels() { let classes = (this.state.tabNum !== -1) ? 'toolbar-panels' : 'toolbar-panels folded'; return (
{this.renderClosePanel()} {this.renderToolbarNarrativePanel()} {this.renderToolbarTagPanel()}
) } renderToolbarNavs() { if (this.props.narratives) { return this.props.narratives.map((nar, idx) => { const isActive = (idx === this.state.tab); let classes = (isActive) ? 'toolbar-tab active' : 'toolbar-tab'; return (
{ this.toggleTab(idx); }}>
{nar.label}
); }) } return ''; } renderToolbarTabs() { const title = copy[this.props.language].toolbar.title; const isTags = this.props.tags && (this.props.tags.children > 0); return (

{title}

{/*this.renderToolbarTab(0, 'search')*/} {this.renderToolbarTab(0, 'Narratives')} {(isTags) ? this.renderToolbarTab(1, 'Explore by tag') : ''}
) } render() { return (
{this.renderToolbarTabs()} {this.renderToolbarPanels()}
); } } function mapStateToProps(state) { return { tags: selectors.getTagTree(state), categories: selectors.selectCategories(state), narratives: selectors.selectNarratives(state), language: state.app.language, tagFilters: selectors.selectTagList(state), categoryFilter: state.app.filters.categories, viewFilters: state.app.filters.views, features: state.app.features, } } export default connect(mapStateToProps)(Toolbar)