git ssb

0+

alanz / patchwork



forked from Matt McKegg / patchwork

Tree: 94b765368db8e50cb70bf7e12cff49e51cb226aa

Files: 94b765368db8e50cb70bf7e12cff49e51cb226aa / modules / app / html / progress-notifier.js

2074 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.incompleteFeeds], (feeds, incomplete) => {
38 if (feeds) {
39 return clamp((feeds - incomplete) / feeds)
40 } else {
41 return 1
42 }
43 })
44
45 var hidden = sustained(computed([progress.incompleteFeeds, indexing], (incomplete, indexing) => {
46 return incomplete < 5 && !indexing
47 }), 2000)
48
49 // HACK: css animations take up WAY TO MUCH cpu, remove from dom when inactive
50 var displaying = computed(sustained(hidden, 500, x => !x), hidden => !hidden)
51
52 return h('div.info', { hidden }, [
53 h('div.status', [
54 when(displaying, h('Loading -small', [
55 when(computed(progress.incompleteFeeds, (v) => v > 5),
56 ['Downloading new messages', h('progress', { style: {'margin-left': '10px'}, min: 0, max: 1, value: downloadProgress })],
57 when(indexing, [
58 ['Indexing database', h('progress', { style: {'margin-left': '10px'}, min: 0, max: 1, value: indexProgress })]
59 ], 'Scuttling...')
60 )
61 ]))
62 ])
63 ])
64 })
65}
66
67function clamp (value) {
68 return Math.min(1, Math.max(0, value)) || 0
69}
70

Built with git-ssb-web