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