Files: a5f9e9c80b3948d0c40559bef2b6be37e82fcd6d / modules / app / html / progress-notifier.js
1898 bytesRaw
1 | var {computed, when, h} = require('mutant') |
2 | var nest = require('depnest') |
3 | var sustained = require('../../../lib/sustained') |
4 | |
5 | exports.gives = nest('app.html.progressNotifier') |
6 | |
7 | exports.needs = nest({ |
8 | 'progress.html.render': 'first', |
9 | 'progress.obs': { |
10 | global: 'first', |
11 | query: 'first', |
12 | private: 'first' |
13 | } |
14 | }) |
15 | |
16 | exports.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 = computed([progress.incompleteFeeds, 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.incompleteFeeds, (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 | |
64 | function clamp (value) { |
65 | return Math.min(1, Math.max(0, value)) || 0 |
66 | } |
67 |
Built with git-ssb-web