From 679563a71a75db8b10d0e61fb436c633601e9ac2 Mon Sep 17 00:00:00 2001 From: Nakamura Yuki <111046707+powaaaaa@users.noreply.github.com> Date: Fri, 7 Jun 2024 11:25:45 +0900 Subject: [PATCH] refactor: generate asset extensions --- src/constants/supportExtension/asset.ts | 16 +++- .../presentations/items/AssetUpload.tsx | 95 ++++++++++--------- 2 files changed, 63 insertions(+), 48 deletions(-) diff --git a/src/constants/supportExtension/asset.ts b/src/constants/supportExtension/asset.ts index 7c15a0c..0e6f42b 100644 --- a/src/constants/supportExtension/asset.ts +++ b/src/constants/supportExtension/asset.ts @@ -21,5 +21,17 @@ export const ASSET_EXTENSIONS = [ }, ]; -export const ASSET_ACCEPT_EXTENSIONS = - 'image/png, image/jpeg, image/jpg, image/bmp, image/gif, video/mp4, video/mov, audio/mp3, audio/wav, audio/m4a, model/gltf, model/fbx, application/zip'; +const categoryToPrefixMap: { [key: string]: string } = { + 画像: 'image', + 動画: 'video', + 音源: 'audio', + モデル: 'model', + zip: 'application', +}; + +export const ASSET_ACCEPT_EXTENSIONS = ASSET_EXTENSIONS.flatMap((category) => + category.exts.map((ext) => { + const prefix = categoryToPrefixMap[category.category]; + return `${prefix}/${ext}`; + }) +).join(', '); diff --git a/src/domains/Work/components/WorkEdit/presentations/items/AssetUpload.tsx b/src/domains/Work/components/WorkEdit/presentations/items/AssetUpload.tsx index 4a5d098..107070f 100644 --- a/src/domains/Work/components/WorkEdit/presentations/items/AssetUpload.tsx +++ b/src/domains/Work/components/WorkEdit/presentations/items/AssetUpload.tsx @@ -21,51 +21,54 @@ type Props = { handleUploadAssets: (files: FileList) => Promise; assets: Asset[]; }; -export const AssetUpload: FC = ({ handleUploadAssets, assets }) => ( - <> - - アセット - - 必須 - - - - - {assets.map((asset) => AssetRender(asset, 'w-24 p-0'))} - - { - void handleUploadAssets(e); - }} - className="rounded-md relative w-full h-64 border-2 border-orange-pop" - > -
-
0, - })} - /> - - クリック または ドラッグ&ドロップ - - - {assets.length > 0 - ? `${assets.length}件のアセットをアップロード済み` - : 'アセットをアップロードしてください'} +export const AssetUpload: FC = ({ handleUploadAssets, assets }) => { + console.log('asset: ', ASSET_ACCEPT_EXTENSIONS); + return ( + <> + + アセット + + 必須 -
- { - if (!e.target.files?.length || !e.target.files[0]) { - return; - } - void handleUploadAssets(e.target.files); + + + + {assets.map((asset) => AssetRender(asset, 'w-24 p-0'))} + + { + void handleUploadAssets(e); }} - multiple - accept={ASSET_ACCEPT_EXTENSIONS} - type="file" - /> - - -); + className="rounded-md relative w-full h-64 border-2 border-orange-pop" + > +
+
0, + })} + /> + + クリック または ドラッグ&ドロップ + + + {assets.length > 0 + ? `${assets.length}件のアセットをアップロード済み` + : 'アセットをアップロードしてください'} + +
+ { + if (!e.target.files?.length || !e.target.files[0]) { + return; + } + void handleUploadAssets(e.target.files); + }} + multiple + accept={ASSET_ACCEPT_EXTENSIONS} + type="file" + /> +
+ + ); +};