2020-06-02 16:15:12 +02:00
|
|
|
import React from "react";
|
2020-05-31 20:24:35 +02:00
|
|
|
import Preview from "./Preview";
|
2020-06-02 22:52:28 +02:00
|
|
|
import SideBar from "./SideBar";
|
|
|
|
|
2020-06-01 19:09:32 +02:00
|
|
|
import "./css/HomePage.css"
|
2020-06-02 22:52:28 +02:00
|
|
|
import "./css/DefaultPage.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-06-01 20:46:28 +02:00
|
|
|
loadeditems: [],
|
|
|
|
sideinfo: {
|
|
|
|
videonr: null,
|
2020-06-02 22:52:28 +02:00
|
|
|
fullhdvideonr: null,
|
2020-06-01 20:46:28 +02:00
|
|
|
hdvideonr: null,
|
|
|
|
sdvideonr: null,
|
2020-06-02 22:52:28 +02:00
|
|
|
tagnr: null
|
2020-06-02 16:15:12 +02:00
|
|
|
},
|
|
|
|
tag: "all"
|
2020-05-31 20:24:35 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount() {
|
2020-05-31 23:22:50 +02:00
|
|
|
document.addEventListener('scroll', this.trackScrolling);
|
2020-06-02 16:15:12 +02:00
|
|
|
// initial get of all videos
|
|
|
|
this.fetchVideoData("all");
|
2020-06-02 22:52:28 +02:00
|
|
|
this.fetchStartData();
|
2020-06-02 16:15:12 +02:00
|
|
|
}
|
2020-05-31 23:22:50 +02:00
|
|
|
|
2020-06-02 16:15:12 +02:00
|
|
|
// this function clears all preview elements an reloads gravity with tag
|
|
|
|
fetchVideoData(tag) {
|
2020-05-31 20:24:35 +02:00
|
|
|
const updateRequest = new FormData();
|
|
|
|
updateRequest.append('action', 'getMovies');
|
2020-06-02 16:15:12 +02:00
|
|
|
updateRequest.append('tag', tag);
|
2020-05-31 20:24:35 +02:00
|
|
|
|
|
|
|
// fetch all videos available
|
2020-06-01 21:36:55 +02:00
|
|
|
fetch('/api/videoload.php', {method: 'POST', body: updateRequest})
|
2020-06-01 20:46:28 +02:00
|
|
|
.then((response) => response.json()
|
|
|
|
.then((result) => {
|
|
|
|
this.data = result;
|
2020-06-02 16:15:12 +02:00
|
|
|
this.setState({loadeditems: []});
|
2020-06-02 22:52:28 +02:00
|
|
|
this.loadindex = 0;
|
2020-06-01 20:46:28 +02:00
|
|
|
this.loadPreviewBlock(12);
|
|
|
|
}))
|
|
|
|
.catch(() => {
|
|
|
|
console.log("no connection to backend");
|
2020-05-31 20:24:35 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-06-02 22:52:28 +02:00
|
|
|
fetchStartData() {
|
|
|
|
const updateRequest = new FormData();
|
|
|
|
updateRequest.append('action', 'getStartData');
|
|
|
|
|
|
|
|
// fetch all videos available
|
|
|
|
fetch('/api/videoload.php', {method: 'POST', body: updateRequest})
|
|
|
|
.then((response) => response.json()
|
|
|
|
.then((result) => {
|
|
|
|
this.setState({
|
|
|
|
sideinfo: {
|
|
|
|
videonr: result['total'],
|
|
|
|
fullhdvideonr: result['fullhd'],
|
|
|
|
hdvideonr: result['hd'],
|
|
|
|
sdvideonr: result['sd'],
|
|
|
|
tagnr: result['tags']
|
|
|
|
}});
|
|
|
|
}))
|
|
|
|
.catch(() => {
|
|
|
|
console.log("no connection to backend");
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
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>
|
2020-06-02 22:52:28 +02:00
|
|
|
<div className='pageheader'>
|
|
|
|
<span className='pageheadertitle'>Home Page</span>
|
|
|
|
<span className='pageheadersubtitle'>All Videos - {this.state.sideinfo.videonr}</span>
|
|
|
|
<hr/>
|
2020-06-01 19:09:32 +02:00
|
|
|
</div>
|
2020-06-02 22:52:28 +02:00
|
|
|
<SideBar>
|
|
|
|
<div className='sidebartitle'>Infos:</div>
|
|
|
|
<hr/>
|
|
|
|
<div className='sidebarinfo'><b>{this.state.sideinfo.videonr}</b> Videos Total!</div>
|
|
|
|
<div className='sidebarinfo'><b>{this.state.sideinfo.fullhdvideonr}</b> FULL-HD Videos!</div>
|
|
|
|
<div className='sidebarinfo'><b>{this.state.sideinfo.hdvideonr}</b> HD Videos!</div>
|
|
|
|
<div className='sidebarinfo'><b>{this.state.sideinfo.sdvideonr}</b> SD Videos!</div>
|
|
|
|
<div className='sidebarinfo'><b>{this.state.sideinfo.tagnr}</b> different Tags!</div>
|
|
|
|
<hr/>
|
|
|
|
<div className='sidebartitle'>Default Tags:</div>
|
|
|
|
<button className='tagbtn' onClick={() => this.fetchVideoData("all")}>All</button>
|
|
|
|
<button className='tagbtn' onClick={() => this.fetchVideoData("fullhd")}>FullHd</button>
|
|
|
|
<button className='tagbtn' onClick={() => this.fetchVideoData("lowquality")}>LowQuality</button>
|
|
|
|
<button className='tagbtn' onClick={() => this.fetchVideoData("hd")}>HD</button>
|
|
|
|
</SideBar>
|
2020-06-01 19:09:32 +02:00
|
|
|
<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;
|
|
|
|
}
|
|
|
|
|
2020-06-02 16:15:12 +02:00
|
|
|
trackScrolling = () => {
|
2020-06-02 22:52:28 +02:00
|
|
|
// comparison if current scroll position is on bottom
|
|
|
|
// 200 stands for bottom offset to trigger load
|
|
|
|
if (window.innerHeight + document.documentElement.scrollTop + 200 >= document.documentElement.offsetHeight) {
|
2020-05-31 23:22:50 +02:00
|
|
|
this.loadPreviewBlock(6);
|
2020-05-31 20:24:35 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default HomePage;
|