2019-05-07 04:35:04 +02:00
|
|
|
// @flow
|
|
|
|
import React from 'react';
|
2019-05-11 21:06:22 +02:00
|
|
|
import { parseURI } from 'lbry-redux';
|
|
|
|
import classnames from 'classnames';
|
|
|
|
import Gerbil from './gerbil.png';
|
2019-05-07 04:35:04 +02:00
|
|
|
|
|
|
|
type Props = {
|
|
|
|
thumbnail: ?string,
|
2019-05-11 21:06:22 +02:00
|
|
|
uri: string,
|
2019-06-11 20:10:58 +02:00
|
|
|
className?: string,
|
2019-06-28 19:00:29 +02:00
|
|
|
thumbnailPreview: ?string,
|
2019-05-07 04:35:04 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
function ChannelThumbnail(props: Props) {
|
2019-06-28 19:00:29 +02:00
|
|
|
const { thumbnail, uri, className, thumbnailPreview } = props;
|
2019-05-11 21:06:22 +02:00
|
|
|
|
2019-05-14 04:53:04 +02:00
|
|
|
// Generate a random color class based on the first letter of the channel name
|
|
|
|
const { channelName } = parseURI(uri);
|
|
|
|
const initializer = channelName.charCodeAt(0) - 65; // will be between 0 and 57
|
2019-06-11 20:10:58 +02:00
|
|
|
const colorClassName = `channel-thumbnail__default--${initializer % 4}`;
|
2019-05-11 21:06:22 +02:00
|
|
|
|
2019-05-07 04:35:04 +02:00
|
|
|
return (
|
2019-05-11 21:06:22 +02:00
|
|
|
<div
|
2019-06-11 20:10:58 +02:00
|
|
|
className={classnames('channel-thumbnail', className, {
|
|
|
|
[colorClassName]: !thumbnail,
|
2019-05-11 21:06:22 +02:00
|
|
|
})}
|
|
|
|
>
|
2019-06-28 19:00:29 +02:00
|
|
|
{!thumbnail && <img className="channel-thumbnail__default" src={thumbnailPreview || Gerbil} />}
|
|
|
|
{thumbnail && <img className="channel-thumbnail__custom" src={thumbnailPreview || thumbnail} />}
|
2019-05-07 04:35:04 +02:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export default ChannelThumbnail;
|