Skip to content

🎥 Make videos programmatically with React

1.6 KB
Raw Blame
import type {MouseEventHandler} from 'react';
import React, {useContext, useMemo} from 'react';
import {FAIL_COLOR, LIGHT_TEXT, TRANSPARENT, WHITE} from '../helpers/colors';
import {Flex} from './layout';
import {RenderQueueContext} from './RenderQueue/context';
import {Tab} from './Tabs';

const row: React.CSSProperties = {
	display: 'flex',
	flexDirection: 'row',
	fontSize: 'inherit',
	color: 'inherit',
	alignItems: 'center',
	flex: 1,
	userSelect: 'none',
	WebkitUserSelect: 'none',
};

const badge: React.CSSProperties = {
	height: 16,
	width: 16,
	borderRadius: 3,
	fontSize: 10,
	display: 'inline-flex',
	justifyContent: 'center',
	alignItems: 'center',
	userSelect: 'none',
	WebkitUserSelect: 'none',
};

export const RendersTab: React.FC<{
	readonly selected: boolean;
	readonly onClick: MouseEventHandler<HTMLDivElement>;
}> = ({selected, onClick}) => {
	const {jobs, captionJobs} = useContext(RenderQueueContext);
	const failedJobs = [...jobs, ...captionJobs].filter(
		(job) => job.status === 'failed',
	).length;
	const jobCount = jobs.length + captionJobs.length;

	const badgeStyle: React.CSSProperties = useMemo(() => {
		return {
			...badge,
			backgroundColor: failedJobs > 0 ? FAIL_COLOR : TRANSPARENT,
			color: failedJobs > 0 ? WHITE : LIGHT_TEXT,
			borderWidth: failedJobs > 0 ? 0 : 1,
			borderStyle: 'solid',
			borderColor: LIGHT_TEXT,
		};
	}, [failedJobs]);

	return (
		<Tab selected={selected} onClick={onClick}>
			<div style={row}>
				Jobs
				{jobCount > 0 ? (
					<>
						<Flex />
						<div style={badgeStyle}>{jobCount}</div>
					</>
				) : null}
			</div>
		</Tab>
	);
};