diff --git a/packages/web-kitchensink-reactnext/src/categories/blob/react/components/ImageFilePreview/index.tsx b/packages/web-kitchensink-reactnext/src/categories/blob/react/components/ImageFilePreview/index.tsx index d9d0ad1..82b2ab0 100644 --- a/packages/web-kitchensink-reactnext/src/categories/blob/react/components/ImageFilePreview/index.tsx +++ b/packages/web-kitchensink-reactnext/src/categories/blob/react/components/ImageFilePreview/index.tsx @@ -1,5 +1,5 @@ import * as React from 'react'; -import {augmentImageFile, getMimeTypeDescription} from '@/utils/blob'; +import {augmentImageFile, FallbackFile, getMimeTypeDescription} from '@/utils/blob'; import {formatFileSize, formatNumeral} from '@/utils/numeral'; import clsx from 'clsx'; import {useAugmentedFile, useImageControls} from '@/categories/blob/react'; @@ -7,7 +7,7 @@ import {useAugmentedFile, useImageControls} from '@/categories/blob/react'; type ImageFilePreviewDerivedComponent = HTMLImageElement; export interface ImageFilePreviewProps extends Omit, 'src' | 'alt'> { - file?: File; + file?: File | FallbackFile; disabled?: boolean; } @@ -19,14 +19,14 @@ export const ImageFilePreview = React.forwardRef { const { augmentedFile, error } = useAugmentedFile({ - file, + file: file as File, augmentFunction: augmentImageFile, }); const { fullScreen, handleAction, imageRef, filenameRef } = useImageControls({ forwardedRef, }); - if (!augmentedFile) { + if (!(augmentedFile)) { return null; } @@ -96,17 +96,22 @@ export const ImageFilePreview = React.forwardRef -
-
- Size -
-
- {formatFileSize(augmentedFile.size)} -
-
+ { + typeof augmentedFile?.size === 'number' + && ( +
+
+ Size +
+
+ {formatFileSize(augmentedFile.size)} +
+
+ ) + } { typeof augmentedFile.metadata?.width === 'number' && typeof augmentedFile.metadata?.height === 'number' diff --git a/packages/web-kitchensink-reactnext/src/categories/blob/react/hooks/blob/metadata.ts b/packages/web-kitchensink-reactnext/src/categories/blob/react/hooks/blob/metadata.ts index 51f633a..1f58618 100644 --- a/packages/web-kitchensink-reactnext/src/categories/blob/react/hooks/blob/metadata.ts +++ b/packages/web-kitchensink-reactnext/src/categories/blob/react/hooks/blob/metadata.ts @@ -15,6 +15,7 @@ export const useAugmentedFile = >(options = {} as UseAug return; } + setError(undefined); augmentFunction(file) .then((theAugmentedFile) => { setAugmentedFile(theAugmentedFile); diff --git a/packages/web-kitchensink-reactnext/src/pages/categories/blob/index.tsx b/packages/web-kitchensink-reactnext/src/pages/categories/blob/index.tsx index 6a77f8a..9f5e2d2 100644 --- a/packages/web-kitchensink-reactnext/src/pages/categories/blob/index.tsx +++ b/packages/web-kitchensink-reactnext/src/pages/categories/blob/index.tsx @@ -43,7 +43,7 @@ const BlobPage: NextPage = () => {
diff --git a/packages/web-kitchensink-reactnext/src/utils/blob.ts b/packages/web-kitchensink-reactnext/src/utils/blob.ts index ebfc68a..1149423 100644 --- a/packages/web-kitchensink-reactnext/src/utils/blob.ts +++ b/packages/web-kitchensink-reactnext/src/utils/blob.ts @@ -5,6 +5,10 @@ import {getImageMetadata} from './image'; import {getAudioMetadata} from './audio'; import {getVideoMetadata} from '@/utils/video'; +export interface FallbackFile extends Partial { + metadata?: Record; +} + const MIME_TYPE_DESCRIPTIONS = { 'image/gif': 'GIF Image', 'image/jpeg': 'JPEG Image',