import React from 'react'; import {Link} from './link.js'; import {Icon, CreditAmount} from './common.js'; var Header = React.createClass({ _balanceSubscribeId: null, getInitialState: function() { return { balance: 0 }; }, componentDidMount: function() { this._balanceSubscribeId = lbry.balanceSubscribe((balance) => { this.setState({ balance: balance }); }); }, componentWillUnmount: function() { if (this._balanceSubscribeId) { lbry.balanceUnsubscribe(this._balanceSubscribeId) } }, render: function() { return
{this.props.links ? : ''}
} }); let WunderBar = React.createClass({ _userTypingTimer: null, _input: null, _stateBeforeSearch: null, getInitialState: function() { return { address: this.props.address, icon: this.props.icon }; }, componentWillUnmount: function() { if (this.userTypingTimer) { clearTimeout(this._userTypingTimer); } }, onChange: function(event) { if (this._userTypingTimer) { clearTimeout(this._userTypingTimer); } this.setState({ address: event.target.value }) //@TODO: Switch to React.js timing var searchTerm = event.target.value; this._userTypingTimer = setTimeout(() => { this.props.onSearch(searchTerm); }, 800); // 800ms delay, tweak for faster/slower }, componentWillReceiveProps(nextProps) { if (nextProps.address !== this.state.address || nextProps.icon !== this.state.icon) { this.setState({ address: nextProps.address, icon: nextProps.icon }); } }, onFocus: function() { this._stateBeforeSearch = this.state; let newState = { icon: "icon-search" } // this._input.value = ""; //trigger placeholder this._focusPending = true; if (!this.state.address.match(/^lbry:\/\//)) //onFocus, if they are not on an exact URL, clear the bar { newState.address = ""; } this.setState(newState); }, onBlur: function() { this.setState(this._stateBeforeSearch); this._input.value = this.state.address; }, componentDidUpdate: function() { this._input.value = this.state.address; if (this._input && this._focusPending) { this._input.select(); this._focusPending = false; } }, onReceiveRef: function(ref) { this._input = ref; }, render: function() { return
{this.state.icon ? : '' }
} }) var SubHeader = React.createClass({ render: function() { var links = [], viewingUrl = '?' + this.props.viewingPage; for (let link of Object.keys(this.props.links)) { links.push( {this.props.links[link]} ); } return ( ); } }); export default Header;