git ssb

0+

alanz / patchwork



forked from Matt McKegg / patchwork

Tree: d2a64eaa0249b9f9b937741f6bb64eae15d044bd

Files: d2a64eaa0249b9f9b937741f6bb64eae15d044bd / modules / app / html / progress-notifier.js

1987 bytesRaw
1var {computed, when, h, throttle} = 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.global': 'first',
10 'progress.obs.query': 'first'
11})
12
13exports.create = function (api) {
14 return nest('app.html.progressNotifier', function (id) {
15 var progress = api.progress.obs.global()
16 var queryProgress = api.progress.obs.query()
17
18 var maxQueryPending = 0
19
20 var indexProgress = computed([queryProgress.pending], (pending) => {
21 if (pending === 0 || pending > maxQueryPending) {
22 maxQueryPending = pending
23 }
24 if (pending === 0) {
25 return 1
26 } else {
27 return (maxQueryPending - pending) / maxQueryPending
28 }
29 })
30
31 var downloadProgress = computed([progress.feeds, progress.incomplete], (feeds, incomplete) => {
32 if (feeds) {
33 return clamp((incomplete - feeds) / feeds)
34 } else {
35 return 1
36 }
37 })
38
39 var hidden = computed([progress.incomplete, queryProgress.pending], (incomplete, indexing) => {
40 return incomplete <= 10 && indexing <= 10
41 })
42
43 var hasDownloadProgress = computed([progress.feeds, progress.incomplete], (feeds, incomplete) => {
44 if (feeds) {
45 return incomplete > 10
46 }
47 })
48
49 return h('div.info', { hidden: sustained(hidden, 1000) }, [
50 h('div.status', [
51 h('Loading -small', [
52 when(hasDownloadProgress,
53 ['Downloading new messages', h('progress', { style: {'margin-left': '10px'}, min: 0, max: 1, value: downloadProgress })],
54 when(queryProgress.pending, [
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