/** * @author oldj * @blog https://oldj.net */ 'use strict' import React from 'react' import { Icon, Input, Button, Row, Col } from 'antd' import Agent from '../Agent' import styles from './SearchBar.less' export default class SearchBar extends React.Component { constructor (props) { super(props) this.state = { kw: undefined, current: 0, count: 0, cursor: null, has_previous: false, has_next: false, pos: [] } } gotoPrevious () { Agent.emit('search:goto_previous') } gotoNext () { Agent.emit('search:goto_next') } doSearch () { clearTimeout(this._t) this._t = setTimeout(() => { Agent.emit('search:kw', this.state.kw) }, 300) } searchEnd () { Agent.emit('search:kw', '') Agent.emit('search:end') this.setState({kw: undefined}) } componentDidMount () { this.refs.ipt.focus() Agent.on('search:state', d => this.setState({...d})) Agent.on('search:start', () => { let ipt = this.refs.ipt ipt && ipt.focus() }) } render () { let {kw, count, has_previous, has_next} = this.state let {lang} = this.props return (