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-05-07 04:35:04 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
function ChannelThumbnail(props: Props) {
|
2019-05-11 21:06:22 +02:00
|
|
|
const { thumbnail, uri } = props;
|
|
|
|
|
|
|
|
function getColorClass() {
|
|
|
|
// 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
|
|
|
|
|
|
|
|
let thumbnailColorClass = `channel-thumbnail__default--`;
|
|
|
|
|
|
|
|
switch (true) {
|
|
|
|
case initializer < 15:
|
|
|
|
return (thumbnailColorClass += '1');
|
|
|
|
case initializer < 30:
|
|
|
|
return (thumbnailColorClass += '2');
|
|
|
|
case initializer < 45:
|
|
|
|
return (thumbnailColorClass += '3');
|
|
|
|
default:
|
|
|
|
return (thumbnailColorClass += '4');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-07 04:35:04 +02:00
|
|
|
return (
|
2019-05-11 21:06:22 +02:00
|
|
|
<div
|
|
|
|
className={classnames('channel-thumbnail', {
|
|
|
|
[getColorClass()]: !thumbnail,
|
|
|
|
})}
|
|
|
|
>
|
|
|
|
{!thumbnail && <img className="channel-thumbnail__default" src={Gerbil} />}
|
|
|
|
{thumbnail && <img className="channel-thumbnail__custom" src={thumbnail} />}
|
2019-05-07 04:35:04 +02:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export default ChannelThumbnail;
|