mirror of
https://github.com/oceanprotocol/commons.git
synced 2023-03-15 18:03:00 +01:00
make showing received file size more reliable
This commit is contained in:
parent
1813207772
commit
483cc35de3
@ -25,14 +25,15 @@ export default function Ipfs({ addFile }: { addFile(url: string): void }) {
|
|||||||
|
|
||||||
const [loading, setLoading] = useState(false)
|
const [loading, setLoading] = useState(false)
|
||||||
const [message, setMessage] = useState('')
|
const [message, setMessage] = useState('')
|
||||||
const [received, setReceived] = useState(0)
|
const [fileSize, setFileSize] = useState('')
|
||||||
|
const [fileSizeReceived, setFileSizeReceived] = useState('')
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setMessage(
|
setMessage(
|
||||||
`Adding to IPFS<br />
|
`Adding to IPFS<br />
|
||||||
<small>${formatBytes(received, 0)}</small><br />`
|
<small>${fileSizeReceived || 0}/${fileSize}</small><br />`
|
||||||
)
|
)
|
||||||
}, [received])
|
})
|
||||||
|
|
||||||
async function addToIpfs(data: any) {
|
async function addToIpfs(data: any) {
|
||||||
try {
|
try {
|
||||||
@ -40,7 +41,7 @@ export default function Ipfs({ addFile }: { addFile(url: string): void }) {
|
|||||||
wrapWithDirectory: true,
|
wrapWithDirectory: true,
|
||||||
progress: (length: number) => {
|
progress: (length: number) => {
|
||||||
console.log(`Received: ${formatBytes(length, 0)}`)
|
console.log(`Received: ${formatBytes(length, 0)}`)
|
||||||
setReceived(length)
|
setFileSizeReceived(formatBytes(length, 0))
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -61,7 +62,7 @@ export default function Ipfs({ addFile }: { addFile(url: string): void }) {
|
|||||||
const totalSize = formatBytes(size, 0)
|
const totalSize = formatBytes(size, 0)
|
||||||
|
|
||||||
setLoading(true)
|
setLoading(true)
|
||||||
setMessage(`Adding to IPFS<br /><small>0/${totalSize}</small><br />`)
|
setFileSize(totalSize)
|
||||||
|
|
||||||
// Add file to IPFS node
|
// Add file to IPFS node
|
||||||
const content: any = await readFileAsync(acceptedFiles[0])
|
const content: any = await readFileAsync(acceptedFiles[0])
|
||||||
|
@ -4,8 +4,9 @@
|
|||||||
font-size: $font-size-small;
|
font-size: $font-size-small;
|
||||||
display: block;
|
display: block;
|
||||||
margin-bottom: $spacer / 8;
|
margin-bottom: $spacer / 8;
|
||||||
|
overflow-wrap: break-word;
|
||||||
// TODO: truncate long urls with ellipsis
|
word-wrap: break-word;
|
||||||
|
word-break: break-all;
|
||||||
}
|
}
|
||||||
|
|
||||||
.remove {
|
.remove {
|
||||||
|
@ -5,7 +5,7 @@ import Dotdotdot from 'react-dotdotdot'
|
|||||||
|
|
||||||
const Item = ({
|
const Item = ({
|
||||||
item,
|
item,
|
||||||
removeItem
|
removeFile
|
||||||
}: {
|
}: {
|
||||||
item: {
|
item: {
|
||||||
url: string
|
url: string
|
||||||
@ -13,7 +13,7 @@ const Item = ({
|
|||||||
contentType: string
|
contentType: string
|
||||||
contentLength: number
|
contentLength: number
|
||||||
}
|
}
|
||||||
removeItem(): void
|
removeFile(): void
|
||||||
}) => (
|
}) => (
|
||||||
<li>
|
<li>
|
||||||
<a href={item.url} className={styles.linkUrl} title={item.url}>
|
<a href={item.url} className={styles.linkUrl} title={item.url}>
|
||||||
@ -36,7 +36,7 @@ const Item = ({
|
|||||||
type="button"
|
type="button"
|
||||||
className={styles.remove}
|
className={styles.remove}
|
||||||
title="Remove item"
|
title="Remove item"
|
||||||
onClick={removeItem}
|
onClick={removeFile}
|
||||||
>
|
>
|
||||||
×
|
×
|
||||||
</button>
|
</button>
|
||||||
|
@ -169,9 +169,9 @@ export default class Files extends PureComponent<FilesProps, FilesStates> {
|
|||||||
<ul className={styles.itemsList}>
|
<ul className={styles.itemsList}>
|
||||||
{files.map((item: any, index: number) => (
|
{files.map((item: any, index: number) => (
|
||||||
<Item
|
<Item
|
||||||
key={item.url}
|
key={shortid.generate()}
|
||||||
item={item}
|
item={item}
|
||||||
removeItem={() => this.removeFile(index)}
|
removeFile={() => this.removeFile(index)}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
</ul>
|
</ul>
|
||||||
|
@ -32,12 +32,7 @@ describe('Publish', () => {
|
|||||||
<MemoryRouter>
|
<MemoryRouter>
|
||||||
<Publish
|
<Publish
|
||||||
history={history}
|
history={history}
|
||||||
location={{
|
location={location}
|
||||||
pathname: '/publish',
|
|
||||||
search: '',
|
|
||||||
hash: '',
|
|
||||||
state: ''
|
|
||||||
}}
|
|
||||||
match={{ params: '', path: '', url: '', isExact: true }}
|
match={{ params: '', path: '', url: '', isExact: true }}
|
||||||
/>
|
/>
|
||||||
</MemoryRouter>
|
</MemoryRouter>
|
||||||
|
Loading…
Reference in New Issue
Block a user