2020-05-31 20:24:35 +02:00
|
|
|
import React from "react";
|
|
|
|
import Preview from "./Preview";
|
2020-06-01 19:09:32 +02:00
|
|
|
import "./css/HomePage.css"
|
2020-05-31 20:24:35 +02:00
|
|
|
|
|
|
|
class HomePage extends React.Component {
|
2020-05-31 23:22:50 +02:00
|
|
|
// stores all available movies
|
|
|
|
data = null;
|
|
|
|
// stores current index of loaded elements
|
|
|
|
loadindex = 0;
|
|
|
|
|
2020-05-31 20:24:35 +02:00
|
|
|
constructor(props, context) {
|
|
|
|
super(props, context);
|
|
|
|
|
|
|
|
this.state = {
|
2020-05-31 23:22:50 +02:00
|
|
|
loadeditems: []
|
2020-05-31 20:24:35 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount() {
|
2020-05-31 23:22:50 +02:00
|
|
|
document.addEventListener('scroll', this.trackScrolling);
|
|
|
|
|
2020-05-31 20:24:35 +02:00
|
|
|
const updateRequest = new FormData();
|
|
|
|
updateRequest.append('action', 'getMovies');
|
|
|
|
|
|
|
|
// fetch all videos available
|
|
|
|
fetch('/php/videoload.php', {method: 'POST', body: updateRequest})
|
|
|
|
.then((response) => response.json())
|
|
|
|
.then((result) => {
|
2020-05-31 23:22:50 +02:00
|
|
|
this.data = result;
|
|
|
|
this.loadPreviewBlock(12);
|
2020-05-31 20:24:35 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
componentWillUnmount() {
|
|
|
|
this.setState({});
|
2020-05-31 23:22:50 +02:00
|
|
|
document.removeEventListener('scroll', this.trackScrolling);
|
2020-05-31 20:24:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
<div><h1>Home page</h1></div>
|
2020-06-01 19:09:32 +02:00
|
|
|
<div className='sideinfo'>
|
|
|
|
beep beep
|
|
|
|
</div>
|
|
|
|
<div className='maincontent'>
|
|
|
|
{this.state.loadeditems.map(elem => (
|
|
|
|
<Preview
|
|
|
|
key={elem.movie_id}
|
|
|
|
name={elem.movie_name}
|
|
|
|
movie_id={elem.movie_id}
|
|
|
|
viewbinding={this.props.viewbinding}/>
|
|
|
|
))}
|
|
|
|
</div>
|
|
|
|
<div className='rightinfo'>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
2020-05-31 20:24:35 +02:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
loadPreviewBlock(nr) {
|
2020-05-31 23:22:50 +02:00
|
|
|
console.log("loadpreviewblock called ...")
|
2020-05-31 20:24:35 +02:00
|
|
|
let ret = [];
|
|
|
|
for (let i = 0; i < nr; i++) {
|
2020-05-31 23:22:50 +02:00
|
|
|
// only add if not end
|
|
|
|
if (this.data.length > this.loadindex + i) {
|
|
|
|
ret.push(this.data[this.loadindex + i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this.setState({
|
|
|
|
loadeditems: [
|
|
|
|
...this.state.loadeditems,
|
|
|
|
...ret
|
|
|
|
]
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
this.loadindex += nr;
|
|
|
|
}
|
|
|
|
|
|
|
|
trackScrolling = (e) => {
|
|
|
|
if (window.innerHeight + document.documentElement.scrollTop === document.documentElement.offsetHeight) {
|
|
|
|
this.loadPreviewBlock(6);
|
2020-05-31 20:24:35 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default HomePage;
|