Files: 2b05be8ee023fdd9580d6a845ba074a425756685 / app / html / settings / friend-hops.js
2617 bytesRaw
1 | const nest = require('depnest') |
2 | const { h, computed, Value, watch } = require('mutant') |
3 | const merge = require('lodash/merge') |
4 | const fs = require('fs') |
5 | const { join } = require('path') |
6 | |
7 | exports.gives = nest({ |
8 | 'app.html.settings': true |
9 | }) |
10 | |
11 | exports.needs = nest({ |
12 | 'app.html.settings': 'map', |
13 | 'config.sync.get': 'first', |
14 | 'config.sync.getCustom': 'first', |
15 | 'config.sync.setCustom': 'first' |
16 | }) |
17 | |
18 | const friendsHops = 2 |
19 | exports.create = function (api) { |
20 | return nest({ |
21 | 'app.html.settings': friendHopsConnections |
22 | }) |
23 | |
24 | function friendHopsConnections () { |
25 | let hops = Value(api.config.sync.get('friends.hops', friendsHops)) |
26 | hops.initial = hops() |
27 | |
28 | watch(hops, hops => { |
29 | updateConfig(hops) |
30 | }) |
31 | |
32 | return { |
33 | group: 'replication', |
34 | title: 'Friend Hops', |
35 | body: h('FriendHops', [ |
36 | h('div.description', [ |
37 | 'What you replicate (store a local copy of) is based on how many "hops" you replicate. If you replicate out to 1 hop, you are replicating the people you follow, at 2 hops, it is your follows and people they follow. Play with the slider to see this visualised in the graphic below!' |
38 | ]), |
39 | h('div.slider', [ |
40 | h('datalist', { id: 'friends-hop-datalist' }, [ |
41 | h('option', { value: 0, label: '0' }), |
42 | h('option', { value: 1, label: '1' }), |
43 | h('option', { value: 2, label: '2' }), |
44 | h('option', { value: 3, label: '3' }) |
45 | ]), |
46 | h('input', { |
47 | type: 'range', |
48 | attributes: { list: 'friends-hop-datalist' }, |
49 | min: 0, |
50 | max: 3, |
51 | value: hops, |
52 | 'ev-change': (ev) => hops.set(parseInt(ev.target.value)) |
53 | }) |
54 | ]), |
55 | h('div.alert', |
56 | { |
57 | style: { |
58 | opacity: computed(hops, (_hops) => (_hops === hops.initial) ? 0 : 1) |
59 | } |
60 | }, |
61 | [ |
62 | h('i.fa.fa-warning'), |
63 | ' please restart patchbay for this to take effect' |
64 | ] |
65 | ), |
66 | h('FollowGraph', { |
67 | className: computed(hops, hops => { |
68 | switch (hops) { |
69 | case 0: return '-zero' |
70 | case 1: return '-one' |
71 | case 2: return '-two' |
72 | default: return '-three' |
73 | } |
74 | }), |
75 | innerHTML: fs.readFileSync(join(__dirname, 'friend-hops-graph.svg'), 'utf8') |
76 | }) |
77 | ]) |
78 | } |
79 | } |
80 | |
81 | function updateConfig (hops) { |
82 | const configCustom = api.config.sync.getCustom() |
83 | |
84 | const next = merge({}, configCustom, { |
85 | friends: { hops } |
86 | }) |
87 | |
88 | api.config.sync.setCustom(next) |
89 | } |
90 | } |
91 |
Built with git-ssb-web