Convert MovieQuality to TypeScript

pull/10365/head
Bogdan 5 months ago
parent 0d6ba200d3
commit fde87a38f9

@ -1,11 +1,16 @@
import PropTypes from 'prop-types';
import React from 'react'; import React from 'react';
import Label from 'Components/Label'; import Label from 'Components/Label';
import { kinds } from 'Helpers/Props'; import { kinds } from 'Helpers/Props';
import { QualityModel } from 'Quality/Quality';
import formatBytes from 'Utilities/Number/formatBytes'; import formatBytes from 'Utilities/Number/formatBytes';
import translate from 'Utilities/String/translate'; import translate from 'Utilities/String/translate';
function getTooltip(title, quality, size, isMonitored, isCutoffNotMet) { function getTooltip(
title: string,
quality: QualityModel,
size: number | undefined,
isCutoffNotMet: boolean
) {
const revision = quality.revision; const revision = quality.revision;
if (revision.real && revision.real > 0) { if (revision.real && revision.real > 0) {
@ -20,16 +25,18 @@ function getTooltip(title, quality, size, isMonitored, isCutoffNotMet) {
title += ` - ${formatBytes(size)}`; title += ` - ${formatBytes(size)}`;
} }
if (!isMonitored) { if (isCutoffNotMet) {
title += ' [Not Monitored]'; title += ` [${translate('CutoffNotMet')}]`;
} else if (isCutoffNotMet) {
title += ' [Cutoff Not Met]';
} }
return title; return title;
} }
function revisionLabel(className, quality, showRevision) { function revisionLabel(
className: string | undefined,
quality: QualityModel,
showRevision: boolean
) {
if (!showRevision) { if (!showRevision) {
return; return;
} }
@ -57,26 +64,29 @@ function revisionLabel(className, quality, showRevision) {
</Label> </Label>
); );
} }
return null;
} }
function MovieQuality(props) { interface MovieQualityProps {
className?: string;
title?: string;
quality: QualityModel;
size?: number;
isCutoffNotMet?: boolean;
showRevision?: boolean;
}
function MovieQuality(props: MovieQualityProps) {
const { const {
className, className,
title, title = '',
quality, quality,
size, size,
isMonitored, isCutoffNotMet = false,
isCutoffNotMet, showRevision = false,
showRevision
} = props; } = props;
let kind = kinds.DEFAULT;
if (!isMonitored) {
kind = kinds.DISABLED;
} else if (isCutoffNotMet) {
kind = kinds.INVERSE;
}
if (!quality) { if (!quality) {
return null; return null;
} }
@ -85,29 +95,14 @@ function MovieQuality(props) {
<span> <span>
<Label <Label
className={className} className={className}
kind={kind} kind={isCutoffNotMet ? kinds.INVERSE : kinds.DEFAULT}
title={getTooltip(title, quality, size, isMonitored, isCutoffNotMet)} title={getTooltip(title, quality, size, isCutoffNotMet)}
> >
{quality.quality.name} {quality.quality.name}
</Label>{revisionLabel(className, quality, showRevision)} </Label>
{revisionLabel(className, quality, showRevision)}
</span> </span>
); );
} }
MovieQuality.propTypes = {
className: PropTypes.string,
title: PropTypes.string,
quality: PropTypes.object.isRequired,
size: PropTypes.number,
isMonitored: PropTypes.bool,
isCutoffNotMet: PropTypes.bool,
showRevision: PropTypes.bool
};
MovieQuality.defaultProps = {
title: '',
isMonitored: true,
showRevision: false
};
export default MovieQuality; export default MovieQuality;
Loading…
Cancel
Save