From f912149e04b398ac17483ca268e12609f94e5052 Mon Sep 17 00:00:00 2001 From: Jose Date: Mon, 12 Apr 2021 21:57:56 -0500 Subject: [PATCH] Cover file for audio category (#60) * MainAuctionCard * trending auctions * fix scroll, reduce padding * fixing errors/warnings and formatting * formatting & sold auctions * artists cards * initial presale banner. move sample data to own file * new home layout * presale banner image fix * countdown implementation * initial artwork implementation * getCountdown * presale card * fix presale banner image * fix width. show preview. load only 1 file * remove preview/keep filename. url id for steps * slider > input number * upload step for every category * fix file handling * hashrouter Co-authored-by: B <264380+bartosz-lipinski@users.noreply.github.com> --- .../metavinci/src/views/artCreate/index.tsx | 101 ++++++++++++++---- 1 file changed, 80 insertions(+), 21 deletions(-) diff --git a/packages/metavinci/src/views/artCreate/index.tsx b/packages/metavinci/src/views/artCreate/index.tsx index a34edef..1963779 100644 --- a/packages/metavinci/src/views/artCreate/index.tsx +++ b/packages/metavinci/src/views/artCreate/index.tsx @@ -12,7 +12,6 @@ import { Spin, InputNumber, } from 'antd'; -import { InboxOutlined } from '@ant-design/icons'; import { ArtCard } from './../../components/ArtCard'; import './styles.less'; import { mintNFT } from '../../models'; @@ -197,13 +196,35 @@ const UploadStep = (props: { setAttributes: (attr: IMetadataExtension) => void; confirm: () => void; }) => { - const [fileList, setFileList] = useState(props.attributes.files ?? []) + const [mainFile, setMainFile] = useState() + const [coverFile, setCoverFile] = useState() + const [image, setImage] = useState("") + + useEffect(() => { + props.setAttributes({ + ...props.attributes, + files: [] + }) + }, []) + + const uploadMsg = (category: MetadataCategory) => { + switch (category) { + case MetadataCategory.Audio: + return "Upload your audio creation (MP3, FLAC, WAV)" + case MetadataCategory.Image: + return "Upload your image creation (PNG, JPG, GIF)" + case MetadataCategory.Video: + return "Upload your video creation (MP4)" + default: + return "Please go back and choose a category" + } + } return ( <>

Now, let's upload your creation

-

+

Your file will be uploaded to the decentralized web via Arweave. Depending on file type, can take up to 1 minute. Arweave is a new type of storage that backs data with sustainable and perpetual endowments, @@ -212,41 +233,79 @@ const UploadStep = (props: {

+

{uploadMsg(props.attributes.category)}

{ // dont upload files here, handled outside of the control - info?.onSuccess?.({}, null as any); + info?.onSuccess?.({}, null as any) }} - fileList={fileList} + fileList={mainFile ? [mainFile] : []} onChange={async info => { const file = info.file.originFileObj; - const reader = new FileReader(); - reader.onload = function (event) { - props.setAttributes({ - ...props.attributes, - files: [file], - image: (event.target?.result as string) || '', - }) - }; - if (file) reader.readAsDataURL(file); - setFileList(info.fileList?.slice(-1) ?? []) // Keep only the last dropped file + if (file) setMainFile(file) + if (props.attributes.category != MetadataCategory.Audio) { + const reader = new FileReader(); + reader.onload = function (event) { + setImage((event.target?.result as string) || '') + } + if (file) reader.readAsDataURL(file) + } }} > -

- -

+
+

Upload your creation

+

- Click or drag file to this area to upload + Drag and drop, or click to browse

+ {props.attributes.category == MetadataCategory.Audio && + +

Optionally, you can upload a cover image or video (PNG, JPG, GIF, MP4)

+ { + // dont upload files here, handled outside of the control + info?.onSuccess?.({}, null as any) + }} + fileList={coverFile ? [coverFile] : []} + onChange={async info => { + const file = info.file.originFileObj; + if (file) setCoverFile(file) + if (props.attributes.category == MetadataCategory.Audio) { + const reader = new FileReader(); + reader.onload = function (event) { + setImage((event.target?.result as string) || '') + } + if (file) reader.readAsDataURL(file) + } + }} + > +
+

Upload your cover image or video

+
+

+ Drag and drop, or click to browse +

+
+
+ }