78 lines
2.3 KiB
JavaScript
Raw Normal View History

2020-06-01 20:46:28 +02:00
import React from "react";
2020-06-12 15:57:30 +00:00
import Preview from "../../elements/Preview/Preview";
import "./RandomPage.css"
import SideBar from "../../elements/SideBar/SideBar";
import Tag from "../../elements/Tag/Tag";
import PageTitle from "../../elements/PageTitle/PageTitle";
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 = {
videos: [],
tags: []
2020-06-01 20:46:28 +02:00
};
}
componentDidMount() {
this.loadShuffledvideos(4);
2020-06-01 20:46:28 +02:00
}
render() {
return (
<div>
<PageTitle
title='Random Videos'
subtitle='4pc'/>
<SideBar>
<div className='sidebartitle'>Visible Tags:</div>
{this.state.tags.map((m) => (
<Tag>{m.tag_name}</Tag>
))}
</SideBar>
2020-06-01 20:46:28 +02: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 20:46:28 +02:00
}
shuffleclick() {
this.loadShuffledvideos(4);
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-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) => {
console.log(result);
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;