git ssb

10+

Matt McKegg / patchwork



Tree: 6fd3ee341a376214993d0363c4c72161700b7fbc

Files: 6fd3ee341a376214993d0363c4c72161700b7fbc / modules / app / html / progress-notifier.js

1883 bytesRaw
1var {computed, when, h} = require('mutant')
2var nest = require('depnest')
3var sustained = require('../../../lib/sustained')
4
5exports.gives = nest('app.html.progressNotifier')
6
7exports.needs = nest({
8 'progress.html.render': 'first',
9 'progress.obs': {
10 global: 'first',
11 query: 'first',
12 private: 'first'
13 }
14})
15
16exports.create = function (api) {
17 return nest('app.html.progressNotifier', function (id) {
18 var progress = api.progress.obs.global()
19 var indexing = computed([
20 api.progress.obs.query().pending,
21 api.progress.obs.private().pending
22 ], Math.max)
23
24 var maxQueryPending = 0
25
26 var indexProgress = computed(indexing, (pending) => {
27 if (pending === 0 || pending > maxQueryPending) {
28 maxQueryPending = pending
29 }
30 if (pending === 0) {
31 return 1
32 } else {
33 return (maxQueryPending - pending) / maxQueryPending
34 }
35 })
36
37 var downloadProgress = computed([progress.feeds, progress.incomplete], (feeds, incomplete) => {
38 if (feeds) {
39 return clamp((feeds - incomplete) / feeds)
40 } else {
41 return 1
42 }
43 })
44
45 var hidden = computed([progress.incomplete, indexing], (incomplete, indexing) => {
46 return incomplete < 5 && !indexing
47 })
48
49 return h('div.info', { hidden: sustained(hidden, 2000) }, [
50 h('div.status', [
51 h('Loading -small', [
52 when(computed(progress.incomplete, (v) => v > 5),
53 ['Downloading new messages', h('progress', { style: {'margin-left': '10px'}, min: 0, max: 1, value: downloadProgress })],
54 when(indexing, [
55 ['Indexing database', h('progress', { style: {'margin-left': '10px'}, min: 0, max: 1, value: indexProgress })]
56 ], 'Scuttling...')
57 )
58 ])
59 ])
60 ])
61 })
62}
63
64function clamp (value) {
65 return Math.min(1, Math.max(0, value)) || 0
66}
67

Built with git-ssb-web