git ssb

16+

Dominic / patchbay



Tree: e9b818a585383638585d4b571a3c8ce262874218

Files: e9b818a585383638585d4b571a3c8ce262874218 / app / html / settings / friend-hops.js

2132 bytesRaw
1const nest = require('depnest')
2const { h, computed, onceTrue, Value, watch } = require('mutant')
3const merge = require('lodash/merge')
4
5exports.gives = nest({
6 'app.html.settings': true
7})
8
9exports.needs = nest({
10 'app.html.settings': 'map',
11 'config.sync.get': 'first',
12 'config.sync.getCustom': 'first',
13 'config.sync.setCustom': 'first'
14})
15
16const friendsHops = 2
17exports.create = function (api) {
18 return nest({
19 'app.html.settings': friendHopsConnections
20 })
21
22 function friendHopsConnections () {
23 let hops = Value(api.config.sync.get('friends.hops', friendsHops))
24 hops.initial = hops()
25
26 watch(hops, hops => {
27 const intHops = parseInt(hops)
28 updateConfig(intHops)
29 })
30
31 return {
32 title: 'Friend Hops',
33 body: h('FriendHops', [
34 h('div.description', [
35 'Specify whose content you replicate, and thus the size and shape of your network.'
36 ]),
37 h('div.slider', [
38 h('datalist', { id: 'friends-hop-datalist' }, [
39 h('option', { value: 0, label: '0 - Only your messages' }),
40 h('option', { value: 1, label: '1 - You and your friend\'s messages' }),
41 h('option', { value: 2, label: '2 - You, your friend\'s, and your friend\'s friend\'s messages' }),
42 h('option', { value: 3, label: '3 - You, your friend\'s, your friend\'s friend\'s, and their friend\'s messages' })
43 ]),
44 h('input', {
45 type: 'range',
46 attributes: { list: 'friends-hop-datalist' },
47 min: 0,
48 max: 3,
49 value: hops,
50 'ev-change': (ev) => hops.set(ev.target.value)
51 })
52 ]),
53 computed(hops, (_hops) => {
54 if (_hops === hops.initial) return
55 return h('div.alert', [
56 h('i.fa.fa-warning'),
57 ' please restart patchbay for this to take effect'
58 ])
59 }),
60 ])
61 }
62 }
63
64 function updateConfig (hops) {
65 const configCustom = api.config.sync.getCustom()
66
67 const next = merge({}, configCustom, {
68 friends: { hops }
69 })
70
71 api.config.sync.setCustom(next)
72 }
73}
74

Built with git-ssb-web