improved tag clicking events

This commit is contained in:
2020-06-21 23:08:46 +02:00
parent ec4e54e991
commit 89153b5da9
8 changed files with 77 additions and 48 deletions

View File

@ -13,7 +13,7 @@ describe('<Preview/>', function () {
const wrapper = shallow(<PageTitle>heyimachild</PageTitle>);
const children = wrapper.children();
expect(children.at(children.length-2).text()).toBe("heyimachild");
expect(children.at(children.length - 2).text()).toBe("heyimachild");
});
it('renders pagetitle prop', function () {

View File

@ -60,9 +60,10 @@ class Preview extends React.Component {
itemClick() {
console.log("item clicked!" + this.state.name);
this.props.viewbinding.showVideo(<Player
viewbinding={this.props.viewbinding}
movie_id={this.props.movie_id}/>);
this.props.viewbinding.changeRootElement(
<Player
viewbinding={this.props.viewbinding}
movie_id={this.props.movie_id}/>);
}
}

View File

@ -1,6 +1,7 @@
import React from "react";
import "./Tag.css"
import VideoContainer from "../VideoContainer/VideoContainer";
class Tag extends React.Component {
constructor(props, context) {
@ -10,12 +11,33 @@ class Tag extends React.Component {
}
render() {
// todo onclick events correctlyy
return (
<button className='tagbtn' onClick={this.props.onClick}
<button className='tagbtn' onClick={() => this.TagClick()}
data-testid="Test-Tag">{this.props.children}</button>
);
}
TagClick() {
const tag = this.props.children.toString().toLowerCase();
const updateRequest = new FormData();
updateRequest.append('action', 'getMovies');
updateRequest.append('tag', tag);
// fetch all videos available
fetch('/api/videoload.php', {method: 'POST', body: updateRequest})
.then((response) => response.json()
.then((result) => {
this.props.contentbinding(
<VideoContainer
data={result}
viewbinding={this.props.viewbinding}/>, tag
);
}))
.catch(() => {
console.log("no connection to backend");
});
}
}
export default Tag;