@@ -15,6 +15,7 @@ const $connectButton = document.querySelector('#peer-btn')
15
15
const $multihashInput = document . querySelector ( '#multihash-input' )
16
16
const $fetchButton = document . querySelector ( '#fetch-btn' )
17
17
const $dragContainer = document . querySelector ( '#drag-container' )
18
+ const $progressBar = document . querySelector ( '#progress-bar' )
18
19
const $fileHistory = document . querySelector ( '#file-history tbody' )
19
20
const $emptyRow = document . querySelector ( '.empty-row' )
20
21
// Misc
@@ -25,6 +26,8 @@ const $allDisabledElements = document.querySelectorAll('.disabled')
25
26
const FILES = [ ]
26
27
const workspace = location . hash
27
28
29
+ let fileSize = 0
30
+
28
31
let node
29
32
let info
30
33
let Buffer
@@ -103,6 +106,14 @@ const isFileInList = (hash) => FILES.indexOf(hash) !== -1
103
106
104
107
const sendFileList = ( ) => FILES . forEach ( ( hash ) => publishHash ( hash ) )
105
108
109
+ const updateProgress = ( bytesLoaded ) => {
110
+ let percent = 100 - ( ( bytesLoaded / fileSize ) * 100 )
111
+
112
+ $progressBar . style . transform = `translateX(${ - percent } %)`
113
+ }
114
+
115
+ const resetProgress = ( ) => $progressBar . style . transform = 'translateX(-100%)'
116
+
106
117
function appendFile ( name , hash , size , data ) {
107
118
const file = new window . Blob ( [ data ] , { type : 'application/octet-binary' } )
108
119
const url = window . URL . createObjectURL ( file )
@@ -190,10 +201,12 @@ function onDrop (event) {
190
201
files . forEach ( ( file ) => {
191
202
readFileContents ( file )
192
203
. then ( ( buffer ) => {
204
+ fileSize = file . size
205
+
193
206
node . files . add ( {
194
207
path : file . name ,
195
208
content : Buffer . from ( buffer )
196
- } , { wrap : true } , ( err , filesAdded ) => {
209
+ } , { wrap : true , progress : updateProgress } , ( err , filesAdded ) => {
197
210
if ( err ) {
198
211
return onError ( err )
199
212
}
@@ -202,6 +215,7 @@ function onDrop (event) {
202
215
// the original file name when adding it to the table
203
216
$multihashInput . value = filesAdded [ 1 ] . hash
204
217
218
+ resetProgress ( )
205
219
getFile ( )
206
220
} )
207
221
} )
0 commit comments