2020-06-02 16:15:12 +02:00
|
|
|
import React from "react";
|
2020-06-12 15:57:30 +00:00
|
|
|
import SideBar from "../../elements/SideBar/SideBar";
|
|
|
|
import Tag from "../../elements/Tag/Tag";
|
|
|
|
import VideoContainer from "../../elements/VideoContainer/VideoContainer";
|
2020-06-02 22:52:28 +02:00
|
|
|
|
2020-06-12 15:57:30 +00:00
|
|
|
import "./HomePage.css"
|
|
|
|
import "../../css/DefaultPage.css"
|
2020-05-31 20:24:35 +02:00
|
|
|
|
|
|
|
class HomePage extends React.Component {
|
|
|
|
constructor(props, context) {
|
|
|
|
super(props, context);
|
|
|
|
|
|
|
|
this.state = {
|
2020-06-01 20:46:28 +02:00
|
|
|
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
|
|
|
},
|
2020-06-03 12:26:10 +02:00
|
|
|
tag: "All",
|
2020-06-07 21:42:01 +02:00
|
|
|
data: [],
|
|
|
|
selectionnr: 0
|
2020-05-31 20:24:35 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-06-12 19:48:09 +02:00
|
|
|
/** keyword variable needed temporary store search keyword */
|
|
|
|
keyword = "";
|
|
|
|
|
2020-05-31 20:24:35 +02:00
|
|
|
componentDidMount() {
|
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-03 12:26:10 +02:00
|
|
|
/**
|
|
|
|
* fetch available videos for specified tag
|
|
|
|
* this function clears all preview elements an reloads gravity with tag
|
|
|
|
*
|
|
|
|
* @param tag tag to fetch videos
|
|
|
|
*/
|
2020-06-02 16:15:12 +02:00
|
|
|
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
|
|
|
|
2020-06-07 21:42:01 +02:00
|
|
|
console.log("fetching data");
|
|
|
|
|
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) => {
|
2020-06-03 12:26:10 +02:00
|
|
|
this.setState({
|
2020-06-07 21:42:01 +02:00
|
|
|
data: []
|
|
|
|
});
|
|
|
|
this.setState({
|
|
|
|
data: result,
|
|
|
|
selectionnr: result.length
|
2020-06-03 12:26:10 +02:00
|
|
|
});
|
2020-06-01 20:46:28 +02:00
|
|
|
}))
|
|
|
|
.catch(() => {
|
|
|
|
console.log("no connection to backend");
|
2020-05-31 20:24:35 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-06-03 12:26:10 +02:00
|
|
|
/**
|
|
|
|
* fetch the necessary data for left info box
|
|
|
|
*/
|
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']
|
2020-06-03 12:26:10 +02:00
|
|
|
}
|
|
|
|
});
|
2020-06-02 22:52:28 +02:00
|
|
|
}))
|
|
|
|
.catch(() => {
|
|
|
|
console.log("no connection to backend");
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-06-12 19:48:09 +02:00
|
|
|
/**
|
|
|
|
* search for a keyword in db and update previews
|
|
|
|
*
|
|
|
|
* @param keyword The keyword to search for
|
|
|
|
*/
|
|
|
|
searchVideos(keyword) {
|
|
|
|
console.log("search called");
|
|
|
|
|
|
|
|
const updateRequest = new FormData();
|
|
|
|
updateRequest.append('action', 'getSearchKeyWord');
|
|
|
|
updateRequest.append('keyword', keyword);
|
|
|
|
|
|
|
|
// 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");
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
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>
|
2020-06-03 12:26:10 +02:00
|
|
|
<span className='pageheadersubtitle'>{this.state.tag} Videos - {this.state.selectionnr}</span>
|
2020-06-15 22:02:34 +02:00
|
|
|
<form className="form-inline searchform" onSubmit={(e) => {
|
|
|
|
e.preventDefault();
|
|
|
|
this.searchVideos(this.keyword);
|
|
|
|
}}>
|
2020-06-12 19:48:09 +02:00
|
|
|
<input data-testid='searchtextfield' className="form-control mr-sm-2"
|
|
|
|
type="text" placeholder="Search"
|
|
|
|
onChange={(e) => {
|
|
|
|
this.keyword = e.target.value
|
|
|
|
}}/>
|
2020-06-15 22:02:34 +02:00
|
|
|
<button data-testid='searchbtnsubmit' className="btn btn-success" type="submit">Search</button>
|
2020-06-12 19:48:09 +02:00
|
|
|
</form>
|
2020-06-02 22:52:28 +02:00
|
|
|
<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>
|
2020-06-03 12:26:10 +02:00
|
|
|
<Tag onClick={() => {
|
|
|
|
this.setState({tag: "All"});
|
|
|
|
this.fetchVideoData("all");
|
|
|
|
}}>All
|
|
|
|
</Tag>
|
|
|
|
<Tag onClick={() => {
|
|
|
|
this.setState({tag: "Full HD"});
|
|
|
|
this.fetchVideoData("fullhd");
|
|
|
|
}}>FullHd
|
|
|
|
</Tag>
|
|
|
|
<Tag onClick={() => {
|
|
|
|
this.setState({tag: "Low Quality"});
|
|
|
|
this.fetchVideoData("lowquality");
|
|
|
|
}}>LowQuality
|
|
|
|
</Tag>
|
|
|
|
<Tag onClick={() => {
|
|
|
|
this.setState({tag: "HD"});
|
|
|
|
this.fetchVideoData("hd");
|
|
|
|
}}>HD
|
|
|
|
</Tag>
|
2020-06-02 22:52:28 +02:00
|
|
|
</SideBar>
|
2020-06-07 21:42:01 +02:00
|
|
|
{this.state.data.length !== 0 ?
|
|
|
|
<VideoContainer
|
|
|
|
data={this.state.data}
|
2020-06-12 15:57:30 +00:00
|
|
|
viewbinding={this.props.viewbinding}/> :
|
|
|
|
<div>No Data found!</div>}
|
2020-06-01 19:09:32 +02:00
|
|
|
<div className='rightinfo'>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
2020-05-31 20:24:35 +02:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default HomePage;
|