import React, { PropTypes } from 'react' import ReactDOM from 'react-dom' import ExternalLink from 'boost/components/ExternalLink' import { setSearchFilter, clearSearch, toggleTutorial } from 'boost/actions' const BRAND_COLOR = '#18AF90' const searchTutorialElement = ( Search some posts!! {'- Search by tag : #{string}'} {'- Search by folder : /{folder_name}\n'} {'exact match : //{folder_name}'} ) export default class ArticleTopBar extends React.Component { constructor (props) { super(props) this.state = { isTooltipHidden: true, isLinksDropdownOpen: false } } componentDidMount () { this.searchInput = ReactDOM.findDOMNode(this.refs.searchInput) this.linksButton = ReactDOM.findDOMNode(this.refs.links) this.showLinksDropdown = e => { e.preventDefault() e.stopPropagation() if (!this.state.isLinksDropdownOpen) { this.setState({isLinksDropdownOpen: true}) } } this.linksButton.addEventListener('click', this.showLinksDropdown) this.hideLinksDropdown = e => { if (this.state.isLinksDropdownOpen) { this.setState({isLinksDropdownOpen: false}) } } document.addEventListener('click', this.hideLinksDropdown) } componentWillUnmount () { document.removeEventListener('click', this.hideLinksDropdown) this.linksButton.removeEventListener('click', this.showLinksDropdown()) } handleTooltipRequest (e) { if (this.searchInput.value.length === 0 && (document.activeElement === this.searchInput)) { this.setState({isTooltipHidden: false}) } else { this.setState({isTooltipHidden: true}) } } isInputFocused () { return document.activeElement === ReactDOM.findDOMNode(this.refs.searchInput) } escape () { let { status, dispatch } = this.props if (status.search.length > 0) { dispatch(clearSearch()) return } this.blurInput() } focusInput () { this.searchInput.focus() } blurInput () { this.searchInput.blur() } handleSearchChange (e) { let { dispatch } = this.props dispatch(setSearchFilter(e.target.value)) this.handleTooltipRequest() } handleSearchClearButton (e) { this.searchInput.value = '' this.focusInput() } handleTutorialButtonClick (e) { let { dispatch } = this.props dispatch(toggleTutorial()) } render () { let { status } = this.props return (
this.handleSearchChange(e)} onBlur={e => this.handleSearchChange(e)} value={this.props.status.search} onChange={e => this.handleSearchChange(e)} placeholder='Search' type='text' /> { this.props.status.search != null && this.props.status.search.length > 0 ? : null }
  • - Search by tag : #{'{string}'}
  • - Search by folder : /{'{folder_name}'}
  • exact match : //{'{folder_name}'}
{status.isTutorialOpen ? searchTutorialElement : null}
{ this.state.isLinksDropdownOpen ? (
Boost official page Discuss
) : null }
{status.isTutorialOpen ? (
this.handleTutorialButtonClick(e)} className='clickJammer'/> Also, you can open Finder!! with pressing `Control` + `shift` + `tab` Hope you to enjoy our app :D Press any key or click to escape tutorial mode
) : null}
) } } ArticleTopBar.propTypes = { search: PropTypes.string, dispatch: PropTypes.func, status: PropTypes.shape({ search: PropTypes.string }) }