import React from "react"; import SideBar from "../elements/SideBar"; import Tag from "../elements/Tag"; import VideoContainer from "../elements/VideoContainer"; import "../css/HomePage.css" import "../css/DefaultPage.css" class HomePage extends React.Component { constructor(props, context) { super(props, context); this.state = { sideinfo: { videonr: null, fullhdvideonr: null, hdvideonr: null, sdvideonr: null, tagnr: null }, tag: "All", data: [], selectionnr: 0 }; } componentDidMount() { // document.addEventListener('scroll', this.trackScrolling); // initial get of all videos this.fetchVideoData("all"); this.fetchStartData(); } /** * fetch available videos for specified tag * this function clears all preview elements an reloads gravity with tag * * @param tag tag to fetch videos */ fetchVideoData(tag) { const updateRequest = new FormData(); updateRequest.append('action', 'getMovies'); updateRequest.append('tag', tag); console.log("fetching data"); // fetch all videos available fetch('/api/videoload.php', {method: 'POST', body: updateRequest}) .then((response) => response.json() .then((result) => { this.setState({ data: [] }); this.setState({ data: result, selectionnr: result.length }); })) .catch(() => { console.log("no connection to backend"); }); } /** * fetch the necessary data for left info box */ 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"); }); } render() { return (
Home Page {this.state.tag} Videos - {this.state.selectionnr}
Infos:

{this.state.sideinfo.videonr} Videos Total!
{this.state.sideinfo.fullhdvideonr} FULL-HD Videos!
{this.state.sideinfo.hdvideonr} HD Videos!
{this.state.sideinfo.sdvideonr} SD Videos!
{this.state.sideinfo.tagnr} different Tags!

Default Tags:
{ this.setState({tag: "All"}); this.fetchVideoData("all"); }}>All { this.setState({tag: "Full HD"}); this.fetchVideoData("fullhd"); }}>FullHd { this.setState({tag: "Low Quality"}); this.fetchVideoData("lowquality"); }}>LowQuality { this.setState({tag: "HD"}); this.fetchVideoData("hd"); }}>HD
{this.state.data.length !== 0 ? : null}
); } } export default HomePage;