import React, { PropTypes } from 'react' import ReactDOM from 'react-dom' import ExternalLink from 'browser/components/ExternalLink' import { setSearchFilter, clearSearch, toggleOnlyUnsavedFilter, toggleTutorial, saveAllArticles, switchArticle } from '../actions' import store from '../store' const electron = require('electron') const remote = electron.remote const Menu = remote.Menu const MenuItem = remote.MenuItem const OSX = process.platform === 'darwin' var menu = new Menu() var lastIndex = -1 menu.append(new MenuItem({ label: 'Show only unsaved', click: function () { store.dispatch(setSearchFilter('--unsaved')) } })) menu.append(new MenuItem({ label: 'Go to an unsaved article', click: function () { lastIndex++ let state = store.getState() let modified = state.articles.modified if (modified.length === 0) return if (modified.length <= lastIndex) { lastIndex = 0 } store.dispatch(switchArticle(modified[lastIndex].key)) } })) 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() } handleOnlyUnsavedChange (e) { let { dispatch } = this.props dispatch(toggleOnlyUnsavedFilter()) } handleSaveAllButtonClick (e) { let { dispatch } = this.props dispatch(saveAllArticles()) } handleSaveMenuButtonClick (e) { menu.popup(590, 45) } handleTutorialButtonClick (e) { let { dispatch } = this.props dispatch(toggleTutorial()) } render () { let { status, modified } = 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}'}
  • - Only unsaved : --unsaved
{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 }), modified: PropTypes.array }