-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgressDialog.ts
More file actions
46 lines (36 loc) · 1.19 KB
/
ProgressDialog.ts
File metadata and controls
46 lines (36 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import { Publication } from '../../publication'
import { publish } from '../../publish.js'
import { subscribe } from '../../subscribe.js'
import { FileService } from './FileService.js'
export class ProgressDialog extends HTMLElement {
pub: Publication<number> = null
pub2: Publication<number> = null
root: ShadowRoot
constructor() {
super()
this.root = this.attachShadow({mode: 'open'})
this.pub = publish(this.root).create('percent', 0)
this.root.innerHTML = `
<h1>CHUNK DOWNLOAD</h1>
<h2 class="name">???</h2>
<h3 class="size">###</h3>
<div class="counter">${this.pub.value}</div>
<slot></slot>
`
}
connectedCallback() {
subscribe(this)
.to<FileService>('file-service')
.map((srv: FileService) => {
// set file name and size
this.root.querySelector('.name').innerHTML = srv.getName()
this.root.querySelector('.size').innerHTML = srv.getSize() + ' MB'
// listen to download percent updates
srv.download(p => {
this.root.querySelector('.counter').innerHTML = `${p}%`
this.pub.update(p)
})
})
}
}
customElements.define('progress-dialog', ProgressDialog)