Files: 13868e1aa6a7204af20406c760dac884fd24fdf1 / join-pub-window.js
2300 bytesRaw
1 | var h = require('./lib/h') |
2 | var when = require('@mmckegg/mutant/when') |
3 | var Value = require('@mmckegg/mutant/value') |
4 | var electron = require('electron') |
5 | var ref = require('ssb-ref') |
6 | var markdown = require('./lib/markdown') |
7 | |
8 | var info = ` |
9 | ## By default, **Ferment** will only see other users that are on the same local area network as you. |
10 | |
11 | In order to share with users on the internet, you need to be [invited to a pub server](https://github.com/mmckegg/ferment#joining-pub-server). |
12 | `.trim() |
13 | |
14 | module.exports = function (client, config, data) { |
15 | var waiting = Value(false) |
16 | var inviteCode = h('input -name', { |
17 | placeholder: 'paste invite code here' |
18 | }) |
19 | |
20 | setTimeout(() => { |
21 | inviteCode.focus() |
22 | }, 50) |
23 | |
24 | return h('Dialog', [ |
25 | h('section JoinPub', [ |
26 | h('div.info', [ |
27 | markdown(info) |
28 | ]), |
29 | h('div', [ |
30 | inviteCode |
31 | ]) |
32 | ]), |
33 | h('footer', [ |
34 | when(waiting, |
35 | h('button', { 'disabled': true }, ['Please wait...']), |
36 | [ h('button -save', {'ev-click': save}, ['Redeem Invite']), |
37 | h('button -cancel', {'ev-click': close}, ['Cancel']) |
38 | ] |
39 | ) |
40 | ]) |
41 | ]) |
42 | |
43 | // scoped |
44 | |
45 | function save () { |
46 | if (!inviteCode.value) { |
47 | showDialog({ |
48 | type: 'info', |
49 | buttons: ['OK'], |
50 | message: 'You must specify an invite code.' |
51 | }) |
52 | } else if (!ref.isInvite(inviteCode.value)) { |
53 | showDialog({ |
54 | type: 'info', |
55 | buttons: ['OK'], |
56 | message: 'The invite code specified is not valid. Please check to make sure it was copied correctly.' |
57 | }) |
58 | } else { |
59 | waiting.set(true) |
60 | client.invite.accept(inviteCode.value, (err) => { |
61 | if (err) { |
62 | waiting.set(false) |
63 | showDialog({ |
64 | type: 'error', |
65 | title: 'Error', |
66 | buttons: ['OK'], |
67 | message: 'An error occured while attempting to redeem invite. The pub server may be unavailable or the invite code may have expired.', |
68 | detail: err.message |
69 | }) |
70 | console.log(err) |
71 | } else { |
72 | close() |
73 | } |
74 | }) |
75 | } |
76 | } |
77 | |
78 | function close () { |
79 | var window = electron.remote.getCurrentWindow() |
80 | window.close() |
81 | } |
82 | } |
83 | |
84 | function showDialog (opts) { |
85 | electron.remote.dialog.showMessageBox(electron.remote.getCurrentWindow(), opts) |
86 | } |
87 |
Built with git-ssb-web