OpenMediaCenter/src/RandomPage.js

73 lines
2.4 KiB
JavaScript
Raw Normal View History

2020-06-01 18:46:28 +00:00
import React from "react";
import Preview from "./Preview";
import "./css/RandomPage.css"
import SideBar from "./SideBar";
2020-06-01 18:46:28 +00:00
class RandomPage extends React.Component {
2020-06-01 19:36:55 +00:00
constructor(props, context) {
2020-06-01 18:46:28 +00:00
super(props, context);
this.state = {
videos: []
};
}
componentDidMount() {
this.loadShuffledvideos(6);
}
render() {
return (
<div>
<div className='pageheader'>
<span className='pageheadertitle'>Random Videos</span>
<span className='pageheadersubtitle'>6pc</span>
<hr/>
</div>
<SideBar>
<div className='sidebartitle'>Visible 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 18:46:28 +00:00
<div className='maincontent'>
{this.state.videos.map(elem => (
<Preview
key={elem.movie_id}
name={elem.movie_name}
movie_id={elem.movie_id}
viewbinding={this.props.viewbinding}/>
))}
<div className='Shufflebutton'>
<button onClick={() => this.shuffleclick()} className='btnshuffle'>Shuffle</button>
</div>
</div>
</div>
);
2020-06-01 18:46:28 +00:00
}
shuffleclick() {
this.loadShuffledvideos(6);
}
loadShuffledvideos(nr) {
const updateRequest = new FormData();
updateRequest.append('action', 'getRandomMovies');
updateRequest.append('number', nr);
// fetch all videos available
2020-06-01 19:36:55 +00:00
fetch('/api/videoload.php', {method: 'POST', body: updateRequest})
2020-06-01 18:46:28 +00:00
.then((response) => response.json()
.then((result) => {
this.setState({videos: result});
}))
.catch(() => {
console.log("no connection to backend");
});
}
}
2020-06-01 19:36:55 +00:00
export default RandomPage;