118 lines
3.3 KiB
JavaScript
Raw Normal View History

2020-05-31 20:24:35 +02:00
import React from "react";
2020-06-12 15:57:30 +00:00
import "./Preview.css";
import Player from "../../pages/Player/Player";
import VideoContainer from "../VideoContainer/VideoContainer";
import {Spinner} from "react-bootstrap";
2020-05-31 20:24:35 +02:00
class Preview extends React.Component {
constructor(props, context) {
super(props, context);
this.props = props;
this.state = {
previewpicture: null,
name: null
2020-05-31 20:24:35 +02:00
};
}
componentWillUnmount() {
this.setState({});
}
componentDidMount() {
this.setState({
previewpicture: null,
name: this.props.name
});
2020-05-31 20:24:35 +02:00
const updateRequest = new FormData();
updateRequest.append('action', 'readThumbnail');
updateRequest.append('movieid', this.props.movie_id);
2020-06-01 21:36:55 +02:00
fetch('/api/videoload.php', {method: 'POST', body: updateRequest})
2020-06-12 15:57:30 +00:00
.then((response) => response.text()
.then((result) => {
this.setState(prevState => ({
...prevState.previewpicture, previewpicture: result
}));
2020-05-31 20:24:35 +02:00
}));
}
render() {
return (
<div className='videopreview' onClick={() => this.itemClick()}>
2020-06-12 15:57:30 +00:00
<div className='previewtitle'>{this.state.name}</div>
2020-05-31 20:24:35 +02:00
<div className='previewpic'>
{this.state.previewpicture != null ?
<img className='previewimage'
src={this.state.previewpicture}
alt='Pic loading.'/> :
<span className='loadAnimation'><Spinner animation="border"/></span>}
2020-05-31 20:24:35 +02:00
</div>
<div className='previewbottom'>
</div>
2020-05-31 20:24:35 +02:00
</div>
);
}
itemClick() {
console.log("item clicked!" + this.state.name);
2020-06-21 23:08:46 +02:00
this.props.viewbinding.changeRootElement(
<Player
viewbinding={this.props.viewbinding}
movie_id={this.props.movie_id}/>);
}
2020-05-31 20:24:35 +02:00
}
export class TagPreview extends React.Component {
2020-06-07 22:17:55 +02:00
constructor(props, context) {
super(props, context);
this.props = props;
}
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) => {
console.log(result);
2020-06-07 22:17:55 +02:00
this.props.categorybinding(
<VideoContainer
data={result}
2020-06-12 15:57:30 +00:00
viewbinding={this.props.viewbinding}/>, tag
);
}))
.catch(() => {
console.log("no connection to backend");
});
}
render() {
return (
<div className='videopreview tagpreview' onClick={() => this.itemClick()}>
<div className='tagpreviewtitle'>
{this.props.name}
</div>
</div>
);
}
itemClick() {
this.fetchVideoData(this.props.name);
}
}
2020-05-31 20:24:35 +02:00
export default Preview;