Skip to content

Commit

Permalink
feat(ImageBlock): allow types other than images (#693)
Browse files Browse the repository at this point in the history
* feat(ImageBlock): allow types other than images

* enable extensions in imageblock

* update extension sets
  • Loading branch information
fulopdaniel authored Nov 30, 2023
1 parent de58b55 commit d7bbc1f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
12 changes: 6 additions & 6 deletions packages/image-block/src/ImageBlock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

import {
Asset,
AssetChooserObjectType,
FileExtensionSets,
getMimeType,
useAssetChooser,
useAssetUpload,
useBlockAssets,
Expand All @@ -16,7 +15,7 @@ import 'tailwindcss/tailwind.css';
import '@frontify/guideline-blocks-settings/styles';
import { CaptionPosition, Settings, mapCaptionPositionClasses, ratioValues } from './types';
import { ImageCaption } from './components/ImageCaption';
import { IMAGE_ID } from './settings';
import { ALLOWED_EXTENSIONS, IMAGE_ID } from './settings';
import {
BlockItemWrapper,
BlockProps,
Expand Down Expand Up @@ -47,7 +46,9 @@ export const ImageBlock = ({ appBridge }: BlockProps) => {
const [isLoading, setIsLoading] = useState(false);
const { blockAssets, deleteAssetIdsFromKey, updateAssetIdsFromKey } = useBlockAssets(appBridge);
const image = blockAssets?.[IMAGE_ID]?.[0];
const [openFileDialog, { selectedFiles }] = useFileInput({ accept: 'image/*' });
const [openFileDialog, { selectedFiles }] = useFileInput({
accept: getMimeType(ALLOWED_EXTENSIONS).join(','),
});
const [uploadFile, { results: uploadResults, doneAll }] = useAssetUpload({
onUploadProgress: () => !isLoading && setIsLoading(true),
});
Expand All @@ -70,8 +71,7 @@ export const ImageBlock = ({ appBridge }: BlockProps) => {
},
{
selectedValueId: blockAssets[IMAGE_ID]?.[0]?.id,
objectTypes: [AssetChooserObjectType.ImageVideo],
extensions: FileExtensionSets.Images,
extensions: ALLOWED_EXTENSIONS,
},
);
};
Expand Down
1 change: 0 additions & 1 deletion packages/image-block/src/components/UploadPlaceholder.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ export const UploadPlaceholder = ({
onAssetChooseClick={onAssetChooseClick}
onDrop={onFilesDrop}
isLoading={loading}
validFileType={'Images'}
/>
</div>
);
Expand Down
12 changes: 7 additions & 5 deletions packages/image-block/src/settings.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
/* (c) Copyright Frontify Ltd., all rights reserved. */

import { FileExtensionSets } from '@frontify/app-bridge';

import {
AssetChooserObjectType,
FileExtensionSets,
IconEnum,
NotificationBlockDividerPosition,
NotificationStyleType,
Expand All @@ -24,6 +22,11 @@ const PADDING_CHOICE_ID = 'paddingChoice';
const PADDING_CUSTOM_ID = 'paddingCustom';
export const IMAGE_ID = 'image';
export const ATTACHMENTS_ASSET_ID = 'attachments';
export const ALLOWED_EXTENSIONS = [
...FileExtensionSets.Images,
...FileExtensionSets.Documents,
...FileExtensionSets.Templates,
];

export const settings = defineSettings({
basics: [
Expand All @@ -37,8 +40,7 @@ export const settings = defineSettings({
type: 'assetInput',
label: 'Image',
size: 'small',
objectTypes: [AssetChooserObjectType.ImageVideo],
extensions: FileExtensionSets.Images,
extensions: ALLOWED_EXTENSIONS,
},
{
id: 'hasLink',
Expand Down

0 comments on commit d7bbc1f

Please sign in to comment.