git ssb

16+

Dominic / patchbay



Tree: e44d1090738a1f2de11a91d4eb82926eeb8dcb86

Files: e44d1090738a1f2de11a91d4eb82926eeb8dcb86 / modules / setup.js

3800 bytesRaw
1
2var h = require('hyperscript')
3var pull = require('pull-stream')
4
5var plugs = require('../plugs')
6
7var avatar_edit = plugs.first(exports.avatar_edit = [])
8var invite_parse = plugs.first(exports.invite_parse = [])
9var invite_accept = plugs.first(exports.invite_accept = [])
10var sbot_progress = plugs.first(exports.sbot_progress = [])
11var sbot_query = plugs.first(exports.sbot_query = [])
12var avatar = plugs.first(exports.avatar = [])
13
14//maybe this could show the pubs, or
15//if someone locally follows you,
16//it could show the second degree pubs?
17
18//maybe show the network as animated graph?
19
20function followers_query (id) {
21 return [{$filter: {
22 value: {content: {
23 type: "contact",
24 contact: id,
25 following: true,
26// autofollow: true
27 }}
28 }}]
29}
30
31//test whether we are connected to the ssb network.
32exports.setup_is_fresh_install = function (cb) {
33 //test by checking whether you have any friends following you?
34 pull(
35 sbot_query({query: followers_query(id), limit: 1, live: false}),
36 pull.collect(function (err, ary) {
37 cb(err, !!ary.length)
38 })
39 )
40}
41
42function invite_form () {
43 var accept = h('button', 'enter code', {disabled: true, onclick: function () {
44 invite_accept(input.value, function (msg) {
45 status.textContent = msg
46 }, function (err) {
47 if(err) {
48 accept.textContent = 'error:'+(err.message || err.stack || error.type)
49 console.error(err)
50 }
51 else {
52 input.value = ''
53 accept.textContent = 'success!'
54 }
55 })
56 }})
57
58 function parseInput () {
59 if(!input.value) {
60 accept.disabled = true
61 accept.textContent = 'enter code'
62 }
63 else if(!invite_parse(input.value)) {
64 accept.disabled = true
65 accept.textContent = 'invalid code'
66 }
67 else {
68 accept.disabled = false
69 accept.textContent = 'accept'
70 }
71 }
72
73 var input = h('input.wide', {placeholder: 'invite code', oninput: parseInput, onchange: parseInput})
74
75 return h('div.invite-form.row', input, accept)
76}
77
78exports.progress_bar = function () {
79 var liquid = h('div.hyperprogress__liquid', '.')
80 var bar = h('div.hyperprogress__bar', liquid)
81 liquid.style.width = '0%'
82
83 pull(
84 sbot_progress(),
85 pull.drain(function (e) {
86 liquid.style.width = Math.round((e.progress/e.total)*100)+'%'
87 })
88 )
89
90 return bar
91}
92
93//show the first 5 followers, and how they join you to the network.
94//so this will show if a local peer follows you.
95
96//when you join the network, I want this to show as people follow you.
97//that could be when a pub accepts the invite, or when a local peer accepts.
98
99exports.setup_joined_network = function (id) {
100 var followers = h('div.column')
101 var label = h('label', 'not connected to a network')
102 var joined = h('div.setup__joined', label,followers)
103
104 pull(
105 sbot_query({query: followers_query(id), limit: 5, live: true, sync: false}),
106 pull.drain(function (follower) {
107 if(follower.sync) return
108 label.textContent = 'connected to network via...'
109 followers.appendChild(
110 avatar(follower.value.author, 'thumbnail')
111 )
112 })
113 )
114
115 return joined
116}
117
118exports.screen_view = function (path) {
119
120 if(path !== '/setup') return
121
122 var id = require('../keys').id
123
124 //set up an avatar
125
126
127 var status = h('span')
128 var invite = h('input', {placeholder: 'invite code'})
129 return h('div.scroller', h('div.scroller__wrapper',
130 h('h1', 'welcome to patchbay!'),
131 h('div',
132 'please choose avatar image and name',
133 avatar_edit(id)
134 ),
135 h('h2', 'join network'),
136 invite_form(),
137 //show avatars of anyone on the same local network.
138 //show realtime changes in your followers, especially for local.
139
140 exports.progress_bar(),
141 exports.setup_joined_network(require('../keys').id)
142 ))
143}
144
145
146

Built with git-ssb-web