2020-06-07 11:37:50 +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";
|
2020-06-07 15:48:27 +02:00
|
|
|
|
2020-06-12 15:57:30 +00:00
|
|
|
import {TagPreview} from "../../elements/Preview/Preview";
|
|
|
|
import NewTagPopup from "../../elements/NewTagPopup/NewTagPopup";
|
2020-06-19 00:16:18 +02:00
|
|
|
import PageTitle from "../../elements/PageTitle/PageTitle";
|
2020-06-24 21:47:22 +02:00
|
|
|
import VideoContainer from "../../elements/VideoContainer/VideoContainer";
|
2020-06-07 15:48:27 +02:00
|
|
|
|
|
|
|
class CategoryPage extends React.Component {
|
2020-06-07 22:17:55 +02:00
|
|
|
constructor(props, context) {
|
2020-06-07 15:48:27 +02:00
|
|
|
super(props, context);
|
|
|
|
|
|
|
|
this.state = {
|
2020-06-07 22:17:55 +02:00
|
|
|
loadedtags: [],
|
2020-06-08 17:52:58 +02:00
|
|
|
selected: null
|
2020-06-07 15:48:27 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount() {
|
2020-06-24 21:47:22 +02:00
|
|
|
// check if predefined category is set
|
|
|
|
if (this.props.category) {
|
|
|
|
this.fetchVideoData(this.props.category);
|
|
|
|
} else {
|
|
|
|
this.loadTags();
|
|
|
|
}
|
2020-06-07 15:48:27 +02:00
|
|
|
}
|
2020-06-07 11:37:50 +02:00
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<>
|
2020-06-19 00:16:18 +02:00
|
|
|
<PageTitle
|
|
|
|
title='Categories'
|
|
|
|
subtitle={!this.state.selected ? this.state.loadedtags.length + " different Tags" : this.state.selected}/>
|
|
|
|
|
2020-06-07 15:48:27 +02:00
|
|
|
<SideBar>
|
|
|
|
<div className='sidebartitle'>Default Tags:</div>
|
2020-06-24 22:47:46 +02:00
|
|
|
<Tag viewbinding={{
|
|
|
|
changeRootElement: (e) => {
|
|
|
|
this.loadTag(e.props.category)
|
|
|
|
}
|
|
|
|
}}>All</Tag>
|
|
|
|
<Tag viewbinding={{
|
|
|
|
changeRootElement: (e) => {
|
|
|
|
this.loadTag(e.props.category)
|
|
|
|
}
|
|
|
|
}}>FullHd</Tag>
|
|
|
|
<Tag viewbinding={{
|
|
|
|
changeRootElement: (e) => {
|
|
|
|
this.loadTag(e.props.category)
|
|
|
|
}
|
|
|
|
}}>LowQuality</Tag>
|
|
|
|
<Tag viewbinding={{
|
|
|
|
changeRootElement: (e) => {
|
|
|
|
this.loadTag(e.props.category)
|
|
|
|
}
|
|
|
|
}}>HD</Tag>
|
2020-06-07 21:42:01 +02:00
|
|
|
<hr/>
|
2020-06-12 15:57:30 +00:00
|
|
|
<button data-testid='btnaddtag' className='btn btn-success' onClick={() => {
|
2020-06-08 17:52:58 +02:00
|
|
|
this.setState({popupvisible: true})
|
|
|
|
}}>Add a new Tag!
|
|
|
|
</button>
|
2020-06-07 15:48:27 +02:00
|
|
|
</SideBar>
|
2020-06-07 11:37:50 +02:00
|
|
|
|
2020-06-24 22:47:46 +02:00
|
|
|
{this.state.selected ?
|
|
|
|
<>
|
|
|
|
{this.videodata ?
|
|
|
|
<VideoContainer
|
|
|
|
data={this.videodata}
|
|
|
|
viewbinding={this.props.viewbinding}/> : null}
|
|
|
|
<button data-testid='backbtn' className="btn btn-success"
|
|
|
|
onClick={this.loadCategoryPageDefault}>Back
|
|
|
|
</button>
|
|
|
|
</> :
|
|
|
|
<div className='maincontent'>
|
2020-06-07 23:27:31 +02:00
|
|
|
{this.state.loadedtags ?
|
|
|
|
this.state.loadedtags.map((m) => (
|
|
|
|
<TagPreview
|
2020-06-08 17:52:58 +02:00
|
|
|
key={m.tag_name}
|
2020-06-07 23:27:31 +02:00
|
|
|
name={m.tag_name}
|
|
|
|
tag_id={m.tag_id}
|
|
|
|
viewbinding={this.props.viewbinding}
|
2020-06-24 21:47:22 +02:00
|
|
|
categorybinding={this.loadTag}/>
|
2020-06-07 23:27:31 +02:00
|
|
|
)) :
|
|
|
|
"loading"}
|
2020-06-24 22:47:46 +02:00
|
|
|
</div>
|
2020-06-07 23:27:31 +02:00
|
|
|
}
|
|
|
|
|
2020-06-08 17:52:58 +02:00
|
|
|
{this.state.popupvisible ?
|
|
|
|
<NewTagPopup show={this.state.popupvisible}
|
|
|
|
onHide={() => {
|
|
|
|
this.setState({popupvisible: false});
|
|
|
|
this.loadTags();
|
|
|
|
}}/> :
|
|
|
|
null
|
|
|
|
}
|
2020-06-07 23:27:31 +02:00
|
|
|
|
2020-06-07 11:37:50 +02:00
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
2020-06-07 15:48:27 +02:00
|
|
|
|
2020-06-24 21:47:22 +02:00
|
|
|
loadTag = (tagname) => {
|
|
|
|
this.fetchVideoData(tagname);
|
2020-06-08 17:52:58 +02:00
|
|
|
};
|
|
|
|
|
2020-06-24 21:47:22 +02:00
|
|
|
fetchVideoData(tag) {
|
|
|
|
console.log(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) => {
|
2020-06-24 22:47:46 +02:00
|
|
|
this.videodata = result;
|
|
|
|
this.setState({selected: null}); // needed to trigger the state reload correctly
|
2020-06-24 21:47:22 +02:00
|
|
|
this.setState({selected: tag});
|
|
|
|
}))
|
|
|
|
.catch(() => {
|
|
|
|
console.log("no connection to backend");
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-06-08 17:52:58 +02:00
|
|
|
loadCategoryPageDefault = () => {
|
|
|
|
this.setState({selected: null});
|
2020-06-24 22:47:46 +02:00
|
|
|
this.loadTags();
|
2020-06-07 22:17:55 +02:00
|
|
|
};
|
|
|
|
|
2020-06-07 15:48:27 +02:00
|
|
|
/**
|
|
|
|
* load all available tags from db.
|
|
|
|
*/
|
|
|
|
loadTags() {
|
|
|
|
const updateRequest = new FormData();
|
|
|
|
updateRequest.append('action', 'getAllTags');
|
|
|
|
|
|
|
|
// fetch all videos available
|
|
|
|
fetch('/api/Tags.php', {method: 'POST', body: updateRequest})
|
|
|
|
.then((response) => response.json()
|
|
|
|
.then((result) => {
|
|
|
|
this.setState({loadedtags: result});
|
|
|
|
}))
|
|
|
|
.catch(() => {
|
|
|
|
console.log("no connection to backend");
|
|
|
|
});
|
|
|
|
}
|
2020-06-07 11:37:50 +02:00
|
|
|
}
|
|
|
|
|
2020-06-07 22:17:55 +02:00
|
|
|
export default CategoryPage;
|