/** * @author oldj * @blog http://oldj.net */ 'use strict' import React from 'react' import classnames from 'classnames' import Agent from '../../../renderer/Agent' import './buttons.less' export default class Buttons extends React.Component { constructor (props) { super(props) this.state = { top_toggle_on: true, search_on: false } this.on_items = null Agent.on('toggle_host', (on) => { if (on && !this.state.top_toggle_on) { this.setState({ top_toggle_on: true }) this.on_items = null } }) Agent.on('cancel_search', () => { this.calcelSearch() }) Agent.on('to_add_host', () => { Agent.emit('add_host') }) } static btnAdd () { Agent.emit('add_host') } btnToggle () { if (this.state.top_toggle_on) { Agent.emit('get_on_hosts', (items) => { this.on_items = items }) } this.setState({ top_toggle_on: !this.state.top_toggle_on }, () => { Agent.emit('top_toggle', this.state.top_toggle_on, this.on_items) if (this.state.top_toggle_on) { this.on_items = null } }) } btnSearch () { this.setState({ search_on: !this.state.search_on }, () => { Agent.emit(this.state.search_on ? 'search_on' : 'search_off') }) } calcelSearch () { this.setState({ search_on: false }, () => { Agent.emit('search_off') }) } componentDidMount () { Agent.on('to_search', () => { this.btnSearch() }) } render () { return (
Buttons.btnAdd()} >+
this.btnSearch()} /> this.btnToggle()} />
) } }