Skip to content

Commit

Permalink
fix: Display Uploader error in console, as promised (#635)
Browse files Browse the repository at this point in the history
The `Errored` component says `Check the browser console for details`,
but then doesn't put the error in the console. Now it does. πŸ˜„
  • Loading branch information
Peeja authored Sep 6, 2024
1 parent 1b6d135 commit 15da8ee
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion eslint.packages.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module.exports = {
extends: ['./node_modules/hd-scripts/eslint/ts.js'],
parserOptions: {
project: ['./tsconfig.json', 'packages/*/tsconfig.json'],
project: ['./tsconfig.json', 'packages/*/tsconfig.json', 'examples/*/*/tsconfig.json'],
ecmaFeatures: {
jsx: true,
},
Expand Down
11 changes: 9 additions & 2 deletions examples/react/components/src/Uploader.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { ReactNode } from 'react'
import React, { ReactNode, useEffect } from 'react'
import { Uploader, useUploader, UploadStatus, CARMetadata, UploadProgress, AnyLink } from '@w3ui/react'
import { UploadLoader } from './Loader'

Expand Down Expand Up @@ -30,6 +30,13 @@ function Uploading ({ file, files, storedDAGShards, uploadProgress }: UploadingP
}

function Errored ({ error }: { error?: Error }): ReactNode {
useEffect(() => {
if (error != null) {
// eslint-disable-next-line no-console
console.error('Uploader Error:', error)
}
}, [error])

return (
<div className='flex flex-col items-center'>
<h1>
Expand Down Expand Up @@ -136,7 +143,7 @@ export function UploaderForm ({ multiple, allowDirectory }: UploaderFormProps):
return (
<Uploader.Form className="m-12">
<div className='relative shadow h-52 p-8 rounded-md bg-white/5 hover:bg-white/20 border-2 border-dotted border-zinc-950 flex flex-col justify-center items-center text-center'>
<label className={`${hasFile ? 'hidden' : 'block h-px w-px overflow-hidden absolute whitespace-nowrap'}`}>File:</label>
<label className={`${hasFile ? 'hidden' : 'block h-px w-px overflow-hidden absolute whitespace-nowrap'}`}>File:</label>
<Uploader.Input multiple={multiple} allowDirectory={allowDirectory} className={`${hasFile ? 'hidden' : 'block absolute inset-0 cursor-pointer w-full opacity-0'}`} />
<UploaderContents />
{hasFile ? '' : <span>Drag files or Click to Browse</span>}
Expand Down
3 changes: 3 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
},
{
"path": "packages/react"
},
{
"path": "examples/react/components"
}
]
}

0 comments on commit 15da8ee

Please sign in to comment.