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) } componentWillUnmount () { this.searchInput.removeEventListener('keydown', this.showTooltip) this.searchInput.removeEventListener('focus', this.showTooltip) this.searchInput.removeEventListener('blur', this.showTooltip) } 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()) } handleLinksDropdownClick (e) { e.preventDefault() let linksButton = document.activeElement this.handleLinksDropdownClickHandler = e => { if (linksButton !== document.activeElement) { console.log('hide dropdown') document.removeEventListener('click', this.handleLinksDropdownClickHandler) this.setState({ isLinksDropdownOpen: false }) } } if (!this.state.isLinksDropdownOpen) { document.removeEventListener('click', this.handleLinksDropdownClickHandler) document.addEventListener('click', this.handleLinksDropdownClickHandler) this.setState({ isLinksDropdownOpen: true }) } } 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.handleLinksDropdownClick(e)} href> { 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 }) }