Toasts an error when no attritubutes atribute in a metadata file (#13)

* Toasts an error when no attritubutes atribute in a metadata file

* Update MetadataModal.tsx

Co-authored-by: name-user1 <eray@deuslabs.fi>
Co-authored-by: findolor <anakisci@gmail.com>
Co-authored-by: Serkan Reis <serkanreis@gmail.com>
This commit is contained in:
name-user1 2022-08-01 16:37:16 +03:00 committed by GitHub
parent f06aafcd86
commit 6816d79d64
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -80,9 +80,11 @@ const UploadPage: NextPage = () => {
if (event.target.files === null) return toast.error('No files selected.')
for (let i = 0; i < event.target.files.length; i++) {
reader = new FileReader()
reader.onload = function (e) {
reader.onload = async function (e) {
if (!e.target?.result) return toast.error('Error parsing file.')
if (!event.target.files) return toast.error('No files selected.')
if (!JSON.parse(await event.target.files[i].text()).attributes)
return toast.error(`The file with name '${event.target.files[i].name}' doesn't have attributes list!`)
const metadataFile = new File([e.target.result], event.target.files[i].name, { type: 'application/json' })
setMetadataFilesArray((prev) => [...prev, metadataFile])
}
@ -422,7 +424,7 @@ const UploadPage: NextPage = () => {
metadataFile={metadataFilesArray[metadataFileArrayIndex]}
refresher={refreshMetadata}
updateMetadata={updateMetadataFileArray}
updatedMetadataFile={updatedMetadataFilesArray[metadataFileArrayIndex]}
updatedMetadataFile={updatedMetadataFilesArray[0]}
/>
</div>
{imageFilesArray.length > 0 && (