forked from storacha/w3up
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: upload progress (storacha#499)
Use the new `onUploadProgress` callback in `@web3-storage/upload-client` to add upload progress bars to w3console and the example apps. This PR also includes a decent amount of bugfixing in the example apps to get them working. https://user-images.githubusercontent.com/1113/230191386-f0f635f2-1008-4e1f-91e2-517a65b66e31.mov --------- Co-authored-by: Benjamin Goering <171782+gobengo@users.noreply.github.com>
- Loading branch information
Showing
28 changed files
with
480 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
function StatusLoader ({ progressStatus }) { | ||
const { total, loaded, lengthComputable } = progressStatus | ||
if (lengthComputable) { | ||
const percentComplete = Math.floor((loaded / total) * 100) | ||
return ( | ||
<div className='relative w2 h5 ba b--white flex flex-column justify-end'> | ||
<div className='bg-white w100' style={{ height: `${percentComplete}%` }}> | ||
</div> | ||
</div> | ||
) | ||
} else { | ||
return <ArrowPathIcon className='animate-spin h-4 w-4' /> | ||
} | ||
} | ||
|
||
export default function Loader ({ uploadProgress, className = '' }) { | ||
return ( | ||
<div className={`${className} flex flex-row`}> | ||
{Object.values(uploadProgress).map( | ||
status => <StatusLoader progressStatus={status} key={status.url} /> | ||
)} | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
examples/react/multi-file-upload/src/components/Loader.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
function StatusLoader ({ progressStatus }) { | ||
const { total, loaded, lengthComputable } = progressStatus | ||
if (lengthComputable) { | ||
const percentComplete = Math.floor((loaded / total) * 100) | ||
return ( | ||
<div className='relative w2 h5 ba b--white flex flex-column justify-end'> | ||
<div className='bg-white w100' style={{ height: `${percentComplete}%` }}> | ||
</div> | ||
</div> | ||
) | ||
} else { | ||
return <ArrowPathIcon className='animate-spin h-4 w-4' /> | ||
} | ||
} | ||
|
||
export default function Loader ({ uploadProgress, className = '' }) { | ||
return ( | ||
<div className={`${className} flex flex-row`}> | ||
{Object.values(uploadProgress).map( | ||
status => <StatusLoader progressStatus={status} key={status.url} /> | ||
)} | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { For, Show } from "solid-js" | ||
|
||
function StatusLoader ({ progressStatus }) { | ||
const { total, loaded, lengthComputable } = progressStatus | ||
return ( | ||
<Show | ||
when={lengthComputable} | ||
fallback={<div className='spinner mr3 flex-none' />}> | ||
<div className='relative w2 h5 ba b--white flex flex-column justify-end'> | ||
<div className='bg-white w100' style={{ height: `${Math.floor((loaded / total) * 100)}%` }}> | ||
</div> | ||
</div> | ||
</Show> | ||
) | ||
} | ||
|
||
export default function Loader ({ progress, className = '' }) { | ||
return ( | ||
<div className={`${className} flex flex-row`}> | ||
<For each={Object.values(progress.uploadProgress)}> | ||
{(status) => <StatusLoader progressStatus={status} key={status.url} />} | ||
</For> | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
examples/solid/multi-file-upload/src/components/Loader.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { For, Show } from "solid-js" | ||
|
||
function StatusLoader ({ progressStatus }) { | ||
const { total, loaded, lengthComputable } = progressStatus | ||
return ( | ||
<Show | ||
when={lengthComputable} | ||
fallback={<div className='spinner mr3 flex-none' />}> | ||
<div className='relative w2 h5 ba b--white flex flex-column justify-end'> | ||
<div className='bg-white w100' style={{ height: `${Math.floor((loaded / total) * 100)}%` }}> | ||
</div> | ||
</div> | ||
</Show> | ||
) | ||
} | ||
|
||
export default function Loader ({ progress, className = '' }) { | ||
return ( | ||
<div className={`${className} flex flex-row`}> | ||
<For each={Object.values(progress.uploadProgress)}> | ||
{(status) => <StatusLoader progressStatus={status} key={status.url} />} | ||
</For> | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<script> | ||
export default { | ||
props: ['uploadProgress'] | ||
} | ||
</script> | ||
|
||
<template> | ||
<div> | ||
<div v-for="status in Object.values(uploadProgress)"> | ||
<div v-if="status.lengthComputable" className='relative w2 h5 ba b--white flex flex-column justify-end'> | ||
<div className='bg-white w100' :style='{ height: Math.floor((status.loaded / status.total) * 100) + "%" }'> | ||
</div> | ||
</div> | ||
<div v-else className='spinner' /> | ||
</div> | ||
</div> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.