〰 Added error boundary to Card component

This commit is contained in:
2021-06-02 12:13:35 -07:00
parent 9d27a9dd95
commit 7e03a7bbe6

View File

@@ -1,6 +1,6 @@
import * as React from "react"; import * as React from "react";
import { IExtractedComicBookCoverFile } from "../../server/interfaces/folder.interface"; import { IExtractedComicBookCoverFile } from "../../server/interfaces/folder.interface";
import { map } from "lodash"; import { map, isUndefined, isEmpty } from "lodash";
interface IProps { interface IProps {
comicBookCoversMetadata: IExtractedComicBookCoverFile[]; comicBookCoversMetadata: IExtractedComicBookCoverFile[];
@@ -12,8 +12,10 @@ class Card extends React.Component<IProps, IState> {
super(props); super(props);
} }
private removeLeadingPeriod = (input: string): string => { private removeLeadingPeriod = (input: string): string => {
if (input.charAt(0) == ".") { if (!isUndefined(this.props.comicBookCoversMetadata)) {
input = input.substr(1); if (input.charAt(0) == ".") {
input = input.substr(1);
}
} }
return input; return input;
}; };
@@ -45,7 +47,13 @@ class Card extends React.Component<IProps, IState> {
}; };
public render() { public render() {
return <>{this.drawCoverCard(this.props.comicBookCoversMetadata)}</>; return (
<>
{!isUndefined(this.props.comicBookCoversMetadata) &&
!isEmpty(this.props.comicBookCoversMetadata) &&
this.drawCoverCard(this.props.comicBookCoversMetadata)}
</>
);
} }
} }