2020-10-25 18:48:23 +00:00
|
|
|
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';
|
2020-12-17 20:53:22 +00:00
|
|
|
import GlobalInfos from '../../utils/GlobalInfos';
|
2021-03-14 16:56:26 +01:00
|
|
|
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 {
|
2021-01-22 21:05:21 +00:00
|
|
|
name: string;
|
2021-04-16 21:12:56 +02:00
|
|
|
picLoader: (callback: (pic: string) => void) => void;
|
|
|
|
linkPath?: string;
|
|
|
|
onClick?: () => void;
|
2021-01-22 21:05:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
interface PreviewState {
|
2021-04-16 21:12:56 +02:00
|
|
|
picLoaded: boolean | null;
|
2021-01-22 21:05:21 +00:00
|
|
|
}
|
|
|
|
|
2020-08-12 17:50:25 +00:00
|
|
|
/**
|
|
|
|
* Component for single preview tile
|
|
|
|
* floating side by side
|
|
|
|
*/
|
2021-01-22 21:05:21 +00:00
|
|
|
class Preview extends React.Component<PreviewProps, PreviewState> {
|
2021-04-16 21:12:56 +02:00
|
|
|
// store the picture to display
|
|
|
|
pic?: string;
|
|
|
|
|
2021-01-22 21:05:21 +00:00
|
|
|
constructor(props: PreviewProps) {
|
|
|
|
super(props);
|
2020-05-31 20:24:35 +02:00
|
|
|
|
|
|
|
this.state = {
|
2021-04-16 21:12:56 +02:00
|
|
|
picLoaded: null
|
2020-05-31 20:24:35 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-01-22 21:05:21 +00:00
|
|
|
componentDidMount(): void {
|
2021-04-16 21:12:56 +02:00
|
|
|
this.props.picLoader((result) => {
|
|
|
|
this.pic = result;
|
2020-12-17 20:53:22 +00:00
|
|
|
this.setState({
|
2021-04-16 21:12:56 +02:00
|
|
|
picLoaded: result !== ''
|
2020-12-17 20:53:22 +00:00
|
|
|
});
|
2020-05-31 23:22:50 +02:00
|
|
|
});
|
2020-05-31 20:24:35 +02:00
|
|
|
}
|
|
|
|
|
2021-01-22 21:05:21 +00:00
|
|
|
render(): JSX.Element {
|
2021-04-16 21:12:56 +02:00
|
|
|
if (this.props.linkPath !== undefined) {
|
|
|
|
return <Link to={this.props.linkPath}>{this.content()}</Link>;
|
|
|
|
} else {
|
|
|
|
return this.content();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
content(): JSX.Element {
|
2020-08-05 22:00:55 +02:00
|
|
|
const themeStyle = GlobalInfos.getThemeStyle();
|
2020-05-31 20:24:35 +02:00
|
|
|
return (
|
2021-04-16 21:12:56 +02:00
|
|
|
<div
|
|
|
|
className={style.videopreview + ' ' + themeStyle.secbackground + ' ' + themeStyle.preview}
|
|
|
|
onClick={this.props.onClick}>
|
|
|
|
<div className={style.previewtitle + ' ' + themeStyle.lighttextcolor}>{this.props.name}</div>
|
|
|
|
<div className={style.previewpic}>
|
|
|
|
{this.state.picLoaded === false ? (
|
|
|
|
<FontAwesomeIcon
|
|
|
|
style={{
|
|
|
|
color: 'white',
|
|
|
|
marginTop: '55px'
|
|
|
|
}}
|
|
|
|
icon={faPhotoVideo}
|
|
|
|
size='5x'
|
|
|
|
/>
|
|
|
|
) : this.state.picLoaded === null ? (
|
|
|
|
<span className={style.loadAnimation}>
|
|
|
|
<Spinner animation='border' />
|
|
|
|
</span>
|
|
|
|
) : (
|
|
|
|
<img className={style.previewimage} src={this.pic} alt='Pic loading.' />
|
|
|
|
)}
|
2020-06-04 16:45:24 +02:00
|
|
|
</div>
|
2021-04-16 21:12:56 +02:00
|
|
|
<div className={style.previewbottom} />
|
|
|
|
</div>
|
2020-12-29 19:39:30 +00:00
|
|
|
);
|
2020-05-31 23:22:50 +02:00
|
|
|
}
|
2020-05-31 20:24:35 +02:00
|
|
|
}
|
|
|
|
|
2020-08-12 17:50:25 +00:00
|
|
|
/**
|
|
|
|
* Component for a Tag-name tile (used in category page)
|
|
|
|
*/
|
2021-03-14 14:51:53 +00:00
|
|
|
export class TagPreview extends React.Component<{name: string}> {
|
2021-01-22 21:05:21 +00:00
|
|
|
render(): JSX.Element {
|
2020-08-05 22:00:55 +02:00
|
|
|
const themeStyle = GlobalInfos.getThemeStyle();
|
2020-06-07 15:48:27 +02:00
|
|
|
return (
|
2021-03-14 14:51:53 +00:00
|
|
|
<div className={style.videopreview + ' ' + style.tagpreview + ' ' + themeStyle.secbackground + ' ' + themeStyle.preview}>
|
|
|
|
<div className={style.tagpreviewtitle + ' ' + themeStyle.lighttextcolor}>{this.props.name}</div>
|
2020-06-07 15:48:27 +02:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-31 20:24:35 +02:00
|
|
|
export default Preview;
|