100 lines
2.9 KiB
JavaScript
Raw Normal View History

import React from 'react';
import style from './Preview.module.css';
import Player from '../../pages/Player/Player';
import {Spinner} from 'react-bootstrap';
import GlobalInfos from '../../GlobalInfos';
2020-05-31 20:24:35 +02:00
/**
* Component for single preview tile
* floating side by side
*/
2020-05-31 20:24:35 +02:00
class Preview extends React.Component {
constructor(props, context) {
super(props, context);
this.state = {
previewpicture: null,
name: null
2020-05-31 20:24:35 +02:00
};
}
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);
fetch('/api/video.php', {method: 'POST', body: updateRequest})
2020-06-12 15:57:30 +00:00
.then((response) => response.text()
.then((result) => {
this.setState({
previewpicture: result
});
2020-05-31 20:24:35 +02:00
}));
}
render() {
const themeStyle = GlobalInfos.getThemeStyle();
2020-05-31 20:24:35 +02:00
return (
<div className={style.videopreview + ' ' + themeStyle.secbackground + ' ' + themeStyle.preview}
onClick={() => this.itemClick()}>
<div className={style.previewtitle + ' ' + themeStyle.lighttextcolor}>{this.state.name}</div>
<div className={style.previewpic}>
{this.state.previewpicture !== null ?
<img className={style.previewimage}
src={this.state.previewpicture}
alt='Pic loading.'/> :
<span className={style.loadAnimation}><Spinner animation='border'/></span>}
2020-05-31 20:24:35 +02:00
</div>
<div className={style.previewbottom}>
</div>
2020-05-31 20:24:35 +02:00
</div>
);
}
/**
* handle the click event of a tile
*/
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
}
/**
* Component for a Tag-name tile (used in category page)
*/
export class TagPreview extends React.Component {
render() {
const themeStyle = GlobalInfos.getThemeStyle();
return (
<div
className={style.videopreview + ' ' + style.tagpreview + ' ' + themeStyle.secbackground + ' ' + themeStyle.preview}
onClick={() => this.itemClick()}>
<div className={style.tagpreviewtitle + ' ' + themeStyle.lighttextcolor}>
{this.props.name}
</div>
</div>
);
}
/**
* handle the click event of a Tag tile
*/
itemClick() {
this.props.categorybinding(this.props.name);
}
}
2020-05-31 20:24:35 +02:00
export default Preview;