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';
import { trimAndEllipse } from '../js/utilities.js';
class Toolbar extends React.Component {
constructor(props) {
super(props)
this.state = { _selected: -1 }
}
selectTab(selected) {
const _selected = (this.state._selected === selected) ? -1 : selected
this.setState({ _selected });
}
renderClosePanel() {
return (
);
}
renderSearch() {
if (process.env.features.USE_SEARCH) {
return (
)
}
}
goToNarrative(narrative) {
this.selectTab(-1) // set all unselected within this component
this.props.methods.onSelectNarrative(narrative);
}
renderToolbarNarrativePanel() {
return (
{copy[this.props.language].toolbar.narrative_panel_title}
{copy[this.props.language].toolbar.narrative_summary}
{this.props.narratives.map((narr) => {
return (
)
})}
);
}
renderToolbarTagPanel() {
if (process.env.features.USE_TAGS &&
this.props.tags.children) {
return (
)
}
return '';
}
renderToolbarTab(_selected, label) {
const isActive = (this.state._selected === _selected);
let classes = (isActive) ? 'toolbar-tab active' : 'toolbar-tab';
return (
{ this.selectTab(_selected); }}>
timeline
{label}
);
}
renderToolbarTabs() {
const title = copy[this.props.language].toolbar.title;
const isTags = this.props.tags && (this.props.tags.children > 0);
return (
{/*this.renderToolbarTab(0, 'search')*/}
{this.renderToolbarTab(0, 'Focus stories')}
{this.renderToolbarTab(1, 'Explore freely')}
{/*
*/}
)
}
renderToolbarPanels() {
let classes = (this.state._selected >= 0) ? '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._selected);
let classes = (isActive) ? 'toolbar-tab active' : 'toolbar-tab';
return (
{ this.selectTab(idx); }}>
{nar.label}
);
})
}
return '';
}
renderToolbarTabs() {
const title = copy[this.props.language].toolbar.title;
const isTags = this.props.tags && (this.props.tags.children > 0);
return (
{/*this.renderToolbarTab(0, 'search')*/}
{this.renderToolbarTab(0, 'Narratives')}
{(isTags) ? this.renderToolbarTab(1, 'Explore by tag') : ''}
{/*
*/}
)
}
render() {
const { isNarrative } = this.props
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,
narrative: state.app.narrative,
}
}
export default connect(mapStateToProps)(Toolbar)