import React from 'react'; import {Link} from './link.js'; import {Icon} from './common.js'; var Header = React.createClass({ getInitialState: function() { return { title: "LBRY", isScrolled: false }; }, componentWillMount: function() { new MutationObserver((mutations) => { this.setState({ title: mutations[0].target.textContent }); }).observe( document.querySelector('title'), { subtree: true, characterData: true, childList: true } ); }, componentDidMount: function() { document.addEventListener('scroll', this.handleScroll); }, componentWillUnmount: function() { document.removeEventListener('scroll', this.handleScroll); if (this.userTypingTimer) { clearTimeout(this.userTypingTimer); } }, handleScroll: function() { this.setState({ isScrolled: document.body.scrollTop > 0 }); }, onQueryChange: function(event) { if (this.userTypingTimer) { clearTimeout(this.userTypingTimer); } //@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 }, render: function() { return ( ); } }); 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;