86 lines
2.9 KiB
TypeScript
Raw Normal View History

import React from 'react';
import style from './Preview.module.css';
import {Spinner} from 'react-bootstrap';
2020-12-29 19:39:30 +00:00
import {Link} from 'react-router-dom';
import GlobalInfos from '../../utils/GlobalInfos';
import {APINode, callAPIPlain} from '../../utils/Api';
import {FontAwesomeIcon} from '@fortawesome/react-fontawesome';
import {faPhotoVideo} from '@fortawesome/free-solid-svg-icons';
2020-05-31 20:24:35 +02:00
2021-01-24 16:43:38 +01:00
interface PreviewProps {
name: string;
movieId: number;
}
interface PreviewState {
previewpicture: string | null;
}
/**
* Component for single preview tile
* floating side by side
*/
class Preview extends React.Component<PreviewProps, PreviewState> {
constructor(props: PreviewProps) {
super(props);
2020-05-31 20:24:35 +02:00
this.state = {
previewpicture: null
2020-05-31 20:24:35 +02:00
};
}
componentDidMount(): void {
callAPIPlain(APINode.Video, {action: 'readThumbnail', movieid: this.props.movieId}, (result) => {
this.setState({
previewpicture: result
});
});
2020-05-31 20:24:35 +02:00
}
render(): JSX.Element {
const themeStyle = GlobalInfos.getThemeStyle();
2020-05-31 20:24:35 +02:00
return (
<Link to={'/player/' + this.props.movieId}>
2020-12-29 19:39:30 +00:00
<div className={style.videopreview + ' ' + themeStyle.secbackground + ' ' + themeStyle.preview}>
<div className={style.previewtitle + ' ' + themeStyle.lighttextcolor}>{this.props.name}</div>
2020-12-29 19:39:30 +00:00
<div className={style.previewpic}>
{this.state.previewpicture === '' ? (
<FontAwesomeIcon
style={{
color: 'white',
marginTop: '55px'
}}
icon={faPhotoVideo}
size='5x'
/>
) : this.state.previewpicture === null ? (
<span className={style.loadAnimation}>
<Spinner animation='border' />
</span>
) : (
<img className={style.previewimage} src={this.state.previewpicture} alt='Pic loading.' />
)}
2020-12-29 19:39:30 +00:00
</div>
<div className={style.previewbottom} />
</div>
2020-12-29 19:39:30 +00:00
</Link>
);
}
2020-05-31 20:24:35 +02:00
}
/**
* Component for a Tag-name tile (used in category page)
*/
export class TagPreview extends React.Component<{name: string}> {
render(): JSX.Element {
const themeStyle = GlobalInfos.getThemeStyle();
return (
<div className={style.videopreview + ' ' + style.tagpreview + ' ' + themeStyle.secbackground + ' ' + themeStyle.preview}>
<div className={style.tagpreviewtitle + ' ' + themeStyle.lighttextcolor}>{this.props.name}</div>
</div>
);
}
}
2020-05-31 20:24:35 +02:00
export default Preview;