mirror of
https://github.com/GoogleChromeLabs/squoosh.git
synced 2025-11-14 17:49:52 +00:00
Simplifying FileSize
This commit is contained in:
@@ -7,32 +7,10 @@ interface Props {
|
|||||||
compareTo?: Blob;
|
compareTo?: Blob;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface State {
|
interface State {}
|
||||||
sizeFormatted?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export default class FileSize extends Component<Props, State> {
|
export default class FileSize extends Component<Props, State> {
|
||||||
constructor(props: Props) {
|
render({ blob, compareTo }: Props) {
|
||||||
super(props);
|
|
||||||
if (props.blob) {
|
|
||||||
this.setState({
|
|
||||||
sizeFormatted: prettyBytes(props.blob.size),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
componentWillReceiveProps({ blob }: Props) {
|
|
||||||
if (blob) {
|
|
||||||
this.setState({
|
|
||||||
sizeFormatted: prettyBytes(blob.size),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
render(
|
|
||||||
{ blob, compareTo }: Props,
|
|
||||||
{ sizeFormatted }: State,
|
|
||||||
) {
|
|
||||||
let comparison: JSX.Element | undefined;
|
let comparison: JSX.Element | undefined;
|
||||||
|
|
||||||
if (compareTo) {
|
if (compareTo) {
|
||||||
@@ -58,6 +36,6 @@ export default class FileSize extends Component<Props, State> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return <span>{sizeFormatted} {comparison}</span>;
|
return <span>{prettyBytes(blob.size)} {comparison}</span>;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user