2016-08-07 22:10:44 +02:00
|
|
|
var Header = React.createClass({
|
2016-08-08 00:13:17 +02:00
|
|
|
getInitialState: function() {
|
|
|
|
return {
|
2016-08-08 02:20:14 +02:00
|
|
|
title: "LBRY",
|
|
|
|
isScrolled: false
|
2016-08-08 00:13:17 +02:00
|
|
|
};
|
|
|
|
},
|
|
|
|
componentWillMount: function() {
|
|
|
|
new MutationObserver(function(mutations) {
|
2016-08-09 22:33:01 +02:00
|
|
|
this.setState({ title: mutations[0].target.textContent });
|
2016-08-08 00:13:17 +02:00
|
|
|
}.bind(this)).observe(
|
|
|
|
document.querySelector('title'),
|
|
|
|
{ subtree: true, characterData: true, childList: true }
|
|
|
|
);
|
|
|
|
},
|
2016-08-08 04:48:45 +02:00
|
|
|
componentDidMount: function() {
|
2016-08-08 02:20:14 +02:00
|
|
|
document.addEventListener('scroll', this.handleScroll);
|
|
|
|
},
|
2016-08-08 04:48:45 +02:00
|
|
|
componentWillUnmount: function() {
|
2016-08-08 02:20:14 +02:00
|
|
|
document.removeEventListener('scroll', this.handleScroll);
|
2016-08-08 04:48:45 +02:00
|
|
|
if (this.userTypingTimer)
|
|
|
|
{
|
|
|
|
clearTimeout(this.userTypingTimer);
|
|
|
|
}
|
2016-08-08 02:20:14 +02:00
|
|
|
},
|
2016-08-08 04:48:45 +02:00
|
|
|
handleScroll: function() {
|
2016-08-08 02:20:14 +02:00
|
|
|
this.setState({
|
|
|
|
isScrolled: event.srcElement.body.scrollTop > 0
|
|
|
|
});
|
|
|
|
},
|
2016-08-08 02:57:12 +02:00
|
|
|
onQueryChange: function(event) {
|
|
|
|
|
|
|
|
if (this.userTypingTimer)
|
|
|
|
{
|
|
|
|
clearTimeout(this.userTypingTimer);
|
|
|
|
}
|
|
|
|
|
|
|
|
//@TODO: Switch to React.js timing
|
2016-08-08 04:48:45 +02:00
|
|
|
var searchTerm = event.target.value;
|
|
|
|
this.userTypingTimer = setTimeout(() => {
|
|
|
|
this.props.onSearch(searchTerm);
|
|
|
|
}, 800); // 800ms delay, tweak for faster/slower
|
2016-08-08 02:57:12 +02:00
|
|
|
|
|
|
|
},
|
2016-08-07 22:10:44 +02:00
|
|
|
render: function() {
|
|
|
|
return (
|
2016-08-08 02:20:14 +02:00
|
|
|
<header id="header" className={this.state.isScrolled ? 'header-scrolled' : 'header-unscrolled'}>
|
2016-08-07 22:10:44 +02:00
|
|
|
<Link onClick={this.props.onOpenDrawer} icon="icon-bars" className="open-drawer-link" />
|
2016-08-08 00:13:17 +02:00
|
|
|
<h1>{ this.state.title }</h1>
|
2016-08-08 04:48:45 +02:00
|
|
|
<div className="header-search">
|
|
|
|
<input type="search" onChange={this.onQueryChange}
|
2016-08-08 02:57:12 +02:00
|
|
|
placeholder="Find movies, music, games, and more"/>
|
2016-08-08 04:48:45 +02:00
|
|
|
</div>
|
2016-08-07 22:10:44 +02:00
|
|
|
</header>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|