Skip to content

Commit

Permalink
refactor: make content type optional
Browse files Browse the repository at this point in the history
  • Loading branch information
vsgoulart committed Dec 12, 2024
1 parent cd0e2c5 commit e2877e2
Showing 1 changed file with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const type = 'documentPreview';
* @typedef DocumentMetadata
* @property {string} documentId
* @property {Object} metadata
* @property {string} metadata.contentType
* @property {string|undefined} [metadata.contentType]
* @property {string} metadata.fileName
*
* @typedef Field
Expand Down Expand Up @@ -133,7 +133,6 @@ function isValidDocument(document) {
'documentId' in document &&
'metadata' in document &&
typeof document.metadata === 'object' &&
'contentType' in document.metadata &&
'fileName' in document.metadata
);
}
Expand Down Expand Up @@ -172,8 +171,9 @@ function DocumentRenderer(props) {
const singleDocumentContainerClassName = `fjs-${type}-single-document-container`;
const errorMessageId = `${domId}-error-message`;
const errorMessage = 'Unable to download document';
const isContentTypePresent = typeof metadata.contentType === 'string';

if (metadata.contentType.toLowerCase().startsWith('image/') && isInViewport) {
if (isContentTypePresent && metadata.contentType.toLowerCase().startsWith('image/') && isInViewport) {
return (
<div
class={singleDocumentContainerClassName}
Expand All @@ -192,7 +192,7 @@ function DocumentRenderer(props) {
);
}

if (metadata.contentType.toLowerCase() === 'application/pdf' && isInViewport) {
if (isContentTypePresent && metadata.contentType.toLowerCase() === 'application/pdf' && isInViewport) {
return (
<div
class={singleDocumentContainerClassName}
Expand Down

0 comments on commit e2877e2

Please sign in to comment.