git ssb

16+

Dominic / patchbay



Tree: 8ad5e376187b24a5f42a2374f8236c5919e8b796

Files: 8ad5e376187b24a5f42a2374f8236c5919e8b796 / modules / setup.js

3634 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 status = h('span')
44 var accept = h('button', 'enter code', {disabled: true, onclick: function () {
45 invite_accept(input.value, function (msg) {
46 status.textContent = msg
47 }, function (err) {
48 if(err) {
49 status.textContent = 'error:'+err.message
50 console.error(err)
51 }
52 else
53 status.textContent = 'success!'
54 })
55 }})
56 var input = h('input', {placeholder: 'invite code', oninput: function () {
57 console.log(invite_parse(input.value))
58 if(!invite_parse(input.value)) {
59 accept.disabled = true
60 accept.textContent = 'invalid code'
61 }
62 else {
63 accept.disabled = false
64 accept.textContent = 'accept'
65 }
66 }})
67
68 return h('div.invite-form', status, input, accept)
69}
70
71exports.progress_bar = function () {
72 var liquid = h('div.hyperprogress__liquid', '.')
73 var bar = h('div.hyperprogress__bar', liquid)
74 liquid.style.width = '0%'
75
76 pull(
77 sbot_progress(),
78 pull.drain(function (e) {
79 liquid.style.width = Math.round((e.progress/e.total)*100)+'%'
80 })
81 )
82
83 return bar
84}
85
86//show the first 5 followers, and how they join you to the network.
87//so this will show if a local peer follows you.
88
89//when you join the network, I want this to show as people follow you.
90//that could be when a pub accepts the invite, or when a local peer accepts.
91
92exports.setup_joined_network = function (id) {
93 var followers = h('div')
94 var label = h('label', 'not connected to a network')
95 var joined = h('div.setup__joined', label,followers)
96
97 pull(
98 sbot_query({query: followers_query(id), limit: 5, live: true, sync: false}),
99 pull.drain(function (follower) {
100 if(follower.sync) return
101 label.textContent = 'connected to network via...'
102 followers.appendChild(
103 avatar(follower.value.author, 'thumbnail')
104 )
105 })
106 )
107
108 return joined
109}
110
111exports.screen_view = function (path) {
112
113 if(path !== '/setup') return
114
115 var id = require('../keys').id
116
117 //set up an avatar
118
119
120 var status = h('span')
121 var invite = h('input', {placeholder: 'invite code'})
122 return h('div.column',
123 h('h1', 'welcome to patchbay!'),
124 h('div',
125 'please choose avatar image and name',
126 avatar_edit(id)
127 ),
128 h('h2', 'join network'),
129 'invite code',
130 invite_form(),
131 //show avatars of anyone on the same local network.
132 //show realtime changes in your followers, especially for local.
133
134 exports.progress_bar(),
135 exports.setup_joined_network(require('../keys').id)
136 )
137}
138
139
140

Built with git-ssb-web