import React from 'react'
import { connect } from 'react-redux'
import { bindActionCreators } from 'redux'
import * as actions from '../../actions'
import * as selectors from '../../selectors'
import { Tabs, TabPanel } from 'react-tabs'
import Search from './Search'
import TagListPanel from './TagListPanel'
import CategoriesListPanel from './CategoriesListPanel'
import BottomActions from './BottomActions'
import copy from '../../common/data/copy.json'
import { trimAndEllipse } from '../../common/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 (this.props.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 (
)
})}
)
}
renderToolbarCategoriesPanel () {
if (this.props.features.CATEGORIES_AS_TAGS) {
return (
)
}
}
renderToolbarFilterPanel () {
console.log(this.props)
return (
)
}
renderToolbarTab (_selected, label, iconKey) {
const isActive = (this.state._selected === _selected)
let classes = (isActive) ? 'toolbar-tab active' : 'toolbar-tab'
return (
{ this.selectTab(_selected) }}>
{iconKey}
{label}
)
}
renderToolbarPanels () {
const { features } = this.props
let classes = (this.state._selected >= 0) ? 'toolbar-panels' : 'toolbar-panels folded'
return (
{this.renderClosePanel()}
{features.USE_NARRATIVES ? this.renderToolbarNarrativePanel() : null}
{features.CATEGORIES_AS_TAGS ? this.renderToolbarCategoriesPanel() : null}
{features.USE_FILTERS ? this.renderToolbarFilterPanel() : null}
)
}
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 null
}
renderToolbarTabs () {
const { features } = this.props
let title = copy[this.props.language].toolbar.title
if (process.env.display_title) title = process.env.display_title
const narrativesLabel = copy[this.props.language].toolbar.narratives_label
const tagsLabel = copy[this.props.language].toolbar.tags_label
const categoriesLabel = 'Categories' // TODO:
return (
{features.USE_NARRATIVES ? this.renderToolbarTab(0, narrativesLabel, 'timeline') : null}
{features.CATEGORIES_AS_TAGS ? this.renderToolbarTab(1, categoriesLabel, 'widgets') : null}
{features.USE_FILTERS ? this.renderToolbarTab(2, tagsLabel, 'filter_list') : null}
)
}
render () {
const { isNarrative } = this.props
return (
{this.renderToolbarTabs()}
{this.renderToolbarPanels()}
)
}
}
function mapStateToProps (state) {
return {
tags: selectors.getTagTree(state),
categories: selectors.getCategories(state),
narratives: selectors.selectNarratives(state),
language: state.app.language,
activeTags: selectors.getActiveTags(state),
activeCategories: selectors.getActiveCategories(state),
viewFilters: state.app.filters.views,
narrative: state.app.narrative,
sitesShowing: state.app.flags.isShowingSites,
infoShowing: state.app.flags.isInfopopup,
features: selectors.getFeatures(state)
}
}
function mapDispatchToProps (dispatch) {
return {
actions: bindActionCreators(actions, dispatch)
}
}
export default connect(mapStateToProps, mapDispatchToProps)(Toolbar)