2020-06-01 20:46:28 +02:00
|
|
|
import React from "react";
|
2020-07-08 00:14:08 +02:00
|
|
|
import style from "./RandomPage.module.css"
|
|
|
|
import SideBar, {SideBarTitle} from "../../elements/SideBar/SideBar";
|
2020-06-12 15:57:30 +00:00
|
|
|
import Tag from "../../elements/Tag/Tag";
|
2020-06-19 00:16:18 +02:00
|
|
|
import PageTitle from "../../elements/PageTitle/PageTitle";
|
2020-07-22 19:00:55 +02:00
|
|
|
import VideoContainer from "../../elements/VideoContainer/VideoContainer";
|
2020-06-01 20:46:28 +02:00
|
|
|
|
2020-08-12 17:50:25 +00:00
|
|
|
/**
|
|
|
|
* Randompage shuffles random viedeopreviews and provides a shuffle btn
|
|
|
|
*/
|
2020-06-01 20:46:28 +02:00
|
|
|
class RandomPage extends React.Component {
|
2020-06-01 21:36:55 +02:00
|
|
|
constructor(props, context) {
|
2020-06-01 20:46:28 +02:00
|
|
|
super(props, context);
|
|
|
|
|
|
|
|
this.state = {
|
2020-06-03 12:26:10 +02:00
|
|
|
videos: [],
|
|
|
|
tags: []
|
2020-06-01 20:46:28 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount() {
|
2020-06-04 00:15:06 +02:00
|
|
|
this.loadShuffledvideos(4);
|
2020-06-01 20:46:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2020-06-02 22:52:28 +02:00
|
|
|
return (
|
|
|
|
<div>
|
2020-10-19 21:12:07 +00:00
|
|
|
<PageTitle title='Random Videos'
|
|
|
|
subtitle='4pc'/>
|
2020-06-19 00:16:18 +02:00
|
|
|
|
2020-06-02 22:52:28 +02:00
|
|
|
<SideBar>
|
2020-07-08 00:14:08 +02:00
|
|
|
<SideBarTitle>Visible Tags:</SideBarTitle>
|
2020-06-03 12:26:10 +02:00
|
|
|
{this.state.tags.map((m) => (
|
2020-06-24 21:47:22 +02:00
|
|
|
<Tag
|
|
|
|
key={m.tag_name}
|
|
|
|
viewbinding={this.props.viewbinding}>{m.tag_name}</Tag>
|
2020-06-03 12:26:10 +02:00
|
|
|
))}
|
2020-06-02 22:52:28 +02:00
|
|
|
</SideBar>
|
2020-06-01 20:46:28 +02:00
|
|
|
|
2020-07-22 19:00:55 +02:00
|
|
|
{this.state.videos.length !== 0 ?
|
|
|
|
<VideoContainer
|
|
|
|
data={this.state.videos}
|
|
|
|
viewbinding={this.props.viewbinding}>
|
|
|
|
<div className={style.Shufflebutton}>
|
|
|
|
<button onClick={() => this.shuffleclick()} className={style.btnshuffle}>Shuffle</button>
|
|
|
|
</div>
|
|
|
|
</VideoContainer>
|
|
|
|
:
|
|
|
|
<div>No Data found!</div>}
|
|
|
|
|
2020-06-02 22:52:28 +02:00
|
|
|
</div>
|
|
|
|
);
|
2020-06-01 20:46:28 +02:00
|
|
|
}
|
|
|
|
|
2020-08-12 17:50:25 +00:00
|
|
|
/**
|
|
|
|
* click handler for shuffle btn
|
|
|
|
*/
|
2020-06-01 20:46:28 +02:00
|
|
|
shuffleclick() {
|
2020-06-04 00:15:06 +02:00
|
|
|
this.loadShuffledvideos(4);
|
2020-06-01 20:46:28 +02:00
|
|
|
}
|
|
|
|
|
2020-08-12 17:50:25 +00:00
|
|
|
/**
|
|
|
|
* load random videos from backend
|
|
|
|
* @param nr number of videos to load
|
|
|
|
*/
|
2020-06-01 20:46:28 +02:00
|
|
|
loadShuffledvideos(nr) {
|
|
|
|
const updateRequest = new FormData();
|
|
|
|
updateRequest.append('action', 'getRandomMovies');
|
|
|
|
updateRequest.append('number', nr);
|
|
|
|
|
|
|
|
// fetch all videos available
|
2020-08-12 17:50:25 +00:00
|
|
|
fetch('/api/video.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
|
|
|
console.log(result);
|
2020-07-22 19:00:55 +02:00
|
|
|
|
|
|
|
this.setState({videos: []}); // needed to trigger rerender of main videoview
|
2020-06-03 12:26:10 +02:00
|
|
|
this.setState({
|
|
|
|
videos: result.rows,
|
|
|
|
tags: result.tags
|
|
|
|
});
|
2020-06-01 20:46:28 +02:00
|
|
|
}))
|
|
|
|
.catch(() => {
|
|
|
|
console.log("no connection to backend");
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-01 21:36:55 +02:00
|
|
|
export default RandomPage;
|