git ssb

16+

Dominic / patchbay



Commit 18a5b4472dfb76e7d1e466eaa61ca02676049225

add invite.accept input to /network page

mixmix committed on 4/15/2019, 4:55:11 AM
Parent: 46869ffe4f40685e2fc3bfc01a8d84496403e4af

Files changed

app/page/network.jschanged
app/page/network.mcsschanged
app/page/network.jsView
@@ -1,8 +1,9 @@
11 const nest = require('depnest')
2-const { h, Value, Dict, dictToCollection, onceTrue, computed, watch, watchAll, throttle } = require('mutant')
2 +const { h, Value, Dict, dictToCollection, onceTrue, computed, watch, watchAll, throttle, resolve } = require('mutant')
33 const Chart = require('chart.js')
44 const pull = require('pull-stream')
5 +const { isInvite } = require('ssb-ref')
56
67 const MINUTE = 60 * 1000
78 const DAY = 24 * 60 * MINUTE
89
@@ -41,8 +42,38 @@
4142
4243 const state = buildState({ api, minsPerStep, scale })
4344 const canvas = h('canvas', { height: 500, width: 1200, style: { height: '500px', width: '1200px' } })
4445
46 + const inputInvite = ev => {
47 + state.inviteResult.set(null)
48 + const invite = ev.target.value.replace(/^\s*"?/, '').replace(/"?\s*$/, '')
49 + if (!isInvite(invite)) {
50 + state.invite.set()
51 + return
52 + }
53 +
54 + ev.target.value = invite
55 + state.invite.set(invite)
56 + }
57 + const useInvite = () => {
58 + state.inviteProcessing.set(true)
59 +
60 + onceTrue(api.sbot.obs.connection, server => {
61 + server.invite.accept(resolve(state.invite), (err, data) => {
62 + state.inviteProcessing.set(false)
63 + state.invite.set()
64 +
65 + if (err) {
66 + state.inviteResult.set(false)
67 + console.error(err)
68 + return
69 + }
70 + state.inviteResult.set(true)
71 + console.log(data)
72 + })
73 + })
74 + }
75 +
4576 const page = h('NetworkPage', [
4677 h('div.container', [
4778 h('h1', 'Network'),
4879 h('section', [
@@ -64,9 +95,28 @@
6495 computed(state.remotePeers, peers => {
6596 if (!peers.length) return h('p', 'No remote peers connected')
6697
6798 return peers.map(peer => api.about.html.avatar(peer))
68- })
99 + }),
100 + h('div.invite', [
101 + h('input', {
102 + 'placeholder': 'invite code for a remote peer (pub)',
103 + 'ev-input': inputInvite
104 + }),
105 + computed([state.invite, state.inviteProcessing], (invite, processing) => {
106 + if (processing) return h('i.fa.fa-spinner.fa-pulse')
107 + if (invite) return h('button -primary', { 'ev-click': useInvite }, 'use invite')
108 +
109 + return h('button', { disabled: 'disabled', title: 'not a valid invite code' }, 'use invite')
110 + }),
111 + computed(state.inviteResult, result => {
112 + if (result === null) return
113 +
114 + return result
115 + ? h('i.fa.fa-check')
116 + : h('i.fa.fa-times')
117 + })
118 + ])
69119 ]),
70120 h('section', [
71121 h('h2', 'My state'),
72122 // mix: hello friend, this area is a total Work In Progress. It's a mess but useful diagnostics.
@@ -210,9 +260,12 @@
210260 remotePeers,
211261 seq,
212262 replication,
213263 data, // TODO rename this !!
214- range
264 + range,
265 + invite: Value(),
266 + inviteProcessing: Value(false),
267 + inviteResult: Value(null)
215268 }
216269 }
217270
218271 function getData ({ data, server, minsPerStep, scale }) {
app/page/network.mcssView
@@ -16,7 +16,25 @@
1616 color: #666
1717 margin-left: .5rem
1818 }
1919 }
20 +
21 + div.invite {
22 + margin-top: 1rem
23 +
24 + display: grid
25 + grid-template-columns: 55rem 8rem 2rem
26 + grid-gap: 1rem
27 +
28 + input {
29 + padding-left: .5rem
30 + }
31 +
32 + i.fa {
33 + color: fuchsia
34 + justify-self: center
35 + align-self: center
36 + }
37 + }
2038 }
2139 }
2240 }

Built with git-ssb-web