Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6166b1b

Browse files
author
Antonio Scandurra
committed
Show progress
1 parent e8b73a9 commit 6166b1b

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

lib/git/push-pull/push-pull-component.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export default class PushPullComponent {
6767

6868
return (
6969
<div className='git-Progress'>
70-
<progress className='git-Progress-bar'/>
70+
<progress className='git-Progress-bar' value={this.viewModel.getProgressPercentage()}/>
7171
</div>
7272
)
7373
}

lib/git/push-pull/push-pull-view-model.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export default class PushPullViewModel {
1212
token: ?string;
1313
inFlightRequests: number;
1414
emitter: Emitter;
15+
progress: number;
1516

1617
constructor (gitStore: GitStore) {
1718
this.inFlightRequests = 0
@@ -36,7 +37,8 @@ export default class PushPullViewModel {
3637
let index = 0
3738
for (const remote of remotes) {
3839
await this.gitService.fetch(remote, creds, localProgress => { // eslint-disable-line babel/no-await-in-loop
39-
console.log('fetch progress', (localProgress + index) / remotes.length)
40+
this.progress = (localProgress + index) / remotes.length
41+
this.emitter.emit('did-update')
4042
})
4143
index++
4244
}
@@ -46,27 +48,35 @@ export default class PushPullViewModel {
4648
pull (): Promise<void> {
4749
return this.performNetworkAction(() => {
4850
return this.gitService.pull(this.gitStore.branchName, this.getCreds(), progress => {
49-
console.log('pull progress', progress)
51+
this.progress = progress
52+
this.emitter.emit('did-update')
5053
})
5154
})
5255
}
5356

5457
push (): Promise<void> {
5558
return this.performNetworkAction(() => {
5659
return this.gitService.push(this.gitStore.branchName, this.getCreds(), progress => {
57-
console.log('push progress', progress)
60+
this.progress = progress
61+
this.emitter.emit('did-update')
5862
})
5963
})
6064
}
6165

66+
getProgressPercentage (): number {
67+
return this.progress * 100
68+
}
69+
6270
async performNetworkAction (fn: () => Promise<void>): Promise<void> {
71+
this.progress = 0
6372
this.inFlightRequests++
6473
this.emitter.emit('did-update')
6574

6675
try {
6776
await fn()
6877
} finally {
6978
this.inFlightRequests--
79+
this.progress = 0
7080
this.emitter.emit('did-update')
7181
}
7282
}

0 commit comments

Comments
 (0)