Adds thumbnail support for default, null-valued thumbnails
This commit is contained in:
parent
27f1b4fa01
commit
6018429e68
1 changed files with 10 additions and 5 deletions
|
@ -6,7 +6,7 @@ import Gerbil from './gerbil.png';
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
thumbnail: ?string,
|
thumbnail: ?string,
|
||||||
uri: string,
|
uri: ?string,
|
||||||
className?: string,
|
className?: string,
|
||||||
thumbnailPreview: ?string,
|
thumbnailPreview: ?string,
|
||||||
obscure?: boolean,
|
obscure?: boolean,
|
||||||
|
@ -14,11 +14,16 @@ type Props = {
|
||||||
|
|
||||||
function ChannelThumbnail(props: Props) {
|
function ChannelThumbnail(props: Props) {
|
||||||
const { thumbnail, uri, className, thumbnailPreview, obscure } = props;
|
const { thumbnail, uri, className, thumbnailPreview, obscure } = props;
|
||||||
|
|
||||||
// Generate a random color class based on the first letter of the channel name
|
// Generate a random color class based on the first letter of the channel name
|
||||||
const { channelName } = parseURI(uri);
|
let initializer;
|
||||||
const initializer = channelName.charCodeAt(0) - 65; // will be between 0 and 57
|
if (thumbnail) {
|
||||||
const colorClassName = `channel-thumbnail__default--${Math.abs(initializer % 4)}`;
|
const { channelName } = parseURI(uri);
|
||||||
|
initializer = channelName.charCodeAt(0) - 65; // will be between 0 and 57
|
||||||
|
} else {
|
||||||
|
// if we want to default a thumbnail
|
||||||
|
initializer = Math.floor(Math.random() * 104729); // 10000th prime number
|
||||||
|
}
|
||||||
|
const colorClassName = `channel-thumbnail__default--${initializer % 4}`;
|
||||||
const showThumb = !obscure && !!thumbnail;
|
const showThumb = !obscure && !!thumbnail;
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
|
|
Loading…
Add table
Reference in a new issue