2017-06-06 23:19:12 +02:00
|
|
|
import React from "react";
|
2017-08-18 19:09:40 +02:00
|
|
|
import Router from "component/router/index";
|
2017-06-06 23:19:12 +02:00
|
|
|
import Header from "component/header";
|
2017-09-07 02:52:34 +02:00
|
|
|
import Theme from "component/theme";
|
2017-08-18 19:09:40 +02:00
|
|
|
import ModalRouter from "modal/modalRouter";
|
2017-06-06 23:19:12 +02:00
|
|
|
import lbry from "lbry";
|
2017-11-17 22:27:35 +01:00
|
|
|
import throttle from "util/throttle";
|
2017-04-07 07:15:22 +02:00
|
|
|
|
2017-06-08 06:42:19 +02:00
|
|
|
class App extends React.PureComponent {
|
2017-11-17 22:27:35 +01:00
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
this.mainContent = undefined;
|
|
|
|
}
|
|
|
|
|
2017-05-04 05:44:08 +02:00
|
|
|
componentWillMount() {
|
2017-11-16 22:39:10 +01:00
|
|
|
const { alertError } = this.props;
|
2017-07-16 18:29:46 +02:00
|
|
|
|
2017-06-06 23:19:12 +02:00
|
|
|
document.addEventListener("unhandledError", event => {
|
2017-07-16 18:29:46 +02:00
|
|
|
alertError(event.detail);
|
2017-04-07 07:15:22 +02:00
|
|
|
});
|
2017-11-17 22:27:35 +01:00
|
|
|
}
|
2017-04-07 07:15:22 +02:00
|
|
|
|
2017-11-17 22:27:35 +01:00
|
|
|
componentDidMount() {
|
|
|
|
const { recordScroll } = this.props;
|
|
|
|
const mainContent = document.getElementById("main-content");
|
|
|
|
this.mainContent = mainContent;
|
2017-07-19 10:35:03 +02:00
|
|
|
|
2017-11-17 22:27:35 +01:00
|
|
|
const scrollListener = () => recordScroll(this.mainContent.scrollTop);
|
2017-08-30 14:48:32 +02:00
|
|
|
|
2017-11-17 22:27:35 +01:00
|
|
|
this.mainContent.addEventListener("scroll", throttle(scrollListener, 750));
|
2017-07-16 18:29:46 +02:00
|
|
|
}
|
|
|
|
|
2017-07-19 10:35:03 +02:00
|
|
|
componentWillUnmount() {
|
2017-11-17 22:27:35 +01:00
|
|
|
this.mainContent.removeEventListener("scroll", this.scrollListener);
|
2017-05-04 05:44:08 +02:00
|
|
|
}
|
|
|
|
|
2017-08-30 14:48:32 +02:00
|
|
|
componentWillReceiveProps(props) {
|
|
|
|
this.setTitleFromProps(props);
|
|
|
|
}
|
|
|
|
|
2017-11-17 22:27:35 +01:00
|
|
|
componentDidUpdate(prevProps) {
|
|
|
|
const { currentStackIndex: prevStackIndex } = prevProps;
|
|
|
|
const { currentStackIndex, currentPageAttributes } = this.props;
|
|
|
|
|
|
|
|
if (currentStackIndex !== prevStackIndex) {
|
|
|
|
this.mainContent.scrollTop = currentPageAttributes.scrollY || 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-30 14:48:32 +02:00
|
|
|
setTitleFromProps(props) {
|
2017-10-11 04:04:08 +02:00
|
|
|
window.document.title = props.pageTitle || "LBRY";
|
2017-08-30 14:48:32 +02:00
|
|
|
}
|
|
|
|
|
2017-05-04 05:44:08 +02:00
|
|
|
render() {
|
2017-06-06 23:19:12 +02:00
|
|
|
return (
|
|
|
|
<div id="window">
|
2017-09-07 02:52:34 +02:00
|
|
|
<Theme />
|
2017-06-06 23:19:12 +02:00
|
|
|
<Header />
|
|
|
|
<div id="main-content">
|
|
|
|
<Router />
|
|
|
|
</div>
|
2017-08-18 19:09:40 +02:00
|
|
|
<ModalRouter />
|
2017-04-21 04:31:50 +02:00
|
|
|
</div>
|
2017-06-06 23:19:12 +02:00
|
|
|
);
|
2017-04-07 07:15:22 +02:00
|
|
|
}
|
2017-05-04 05:44:08 +02:00
|
|
|
}
|
2017-04-07 07:15:22 +02:00
|
|
|
|
2017-06-06 06:21:55 +02:00
|
|
|
export default App;
|