Files
OpenMediaCenter/src/pages/CategoryPage.js
T

108 lines
3.4 KiB
JavaScript
Raw Normal View History

2020-06-07 11:37:50 +02:00
import React from "react";
2020-06-09 23:22:43 +02:00
import SideBar from "../elements/SideBar/SideBar";
import Tag from "../elements/Tag/Tag";
2020-06-07 15:48:27 +02:00
import {TagPreview} from "../elements/Preview";
2020-06-08 17:52:58 +02:00
import NewTagPopup from "../elements/NewTagPopup";
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.props = props;
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() {
this.loadTags();
}
2020-06-07 11:37:50 +02:00
render() {
return (
<>
2020-06-07 15:48:27 +02:00
<div className='pageheader'>
2020-06-08 17:52:58 +02:00
<span className='pageheadertitle'>Categories</span>
2020-06-07 15:48:27 +02:00
<span
2020-06-08 17:52:58 +02:00
className='pageheadersubtitle'>{!this.state.selected ? this.state.loadedtags.length + " different Tags" : this.state.selected}</span>
2020-06-07 15:48:27 +02:00
<hr/>
</div>
<SideBar>
<div className='sidebartitle'>Default Tags:</div>
<Tag>All</Tag>
2020-06-07 15:48:27 +02:00
<Tag>FullHd</Tag>
<Tag>LowQuality</Tag>
<Tag>HD</Tag>
<hr/>
2020-06-08 17:52:58 +02:00
<button className='btn btn-success' onClick={() => {
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-07 23:27:31 +02:00
{!this.state.selected ?
(<div className='maincontent'>
{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}
categorybinding={this.setPage}/>
)) :
"loading"}
</div>) :
2020-06-08 17:52:58 +02:00
<>
{this.selectionelements}
<button className="btn btn-success" onClick={this.loadCategoryPageDefault}>Back</button>
</>
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-08 17:52:58 +02:00
setPage = (element, tagname) => {
2020-06-07 22:17:55 +02:00
this.selectionelements = element;
2020-06-08 17:52:58 +02:00
this.setState({selected: tagname});
};
loadCategoryPageDefault = () => {
this.setState({selected: null});
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;