Files: ebcfe76e37f1f3c733650bd4f5c54d7a6d199e9c / modules / invite / sheet.js
2287 bytesRaw
1 | var {h, when, Value, Proxy} = require('mutant') |
2 | var nest = require('depnest') |
3 | var electron = require('electron') |
4 | |
5 | exports.needs = nest({ |
6 | 'sheet.display': 'first', |
7 | 'invite.async.accept': 'first', |
8 | 'intl.sync.i18n': 'first' |
9 | }) |
10 | |
11 | exports.gives = nest('invite.sheet') |
12 | |
13 | exports.create = function (api) { |
14 | const i18n = api.intl.sync.i18n |
15 | return nest('invite.sheet', function () { |
16 | api.sheet.display(close => { |
17 | var publishing = Value() |
18 | var publishStatus = Proxy() |
19 | |
20 | var input = h('input', { |
21 | style: { |
22 | 'font-size': '200%', |
23 | 'margin-top': '20px', |
24 | 'width': '100%' |
25 | }, |
26 | placeholder: i18n('paste invite code here') |
27 | }) |
28 | setTimeout(() => { |
29 | input.focus() |
30 | input.select() |
31 | }, 5) |
32 | return { |
33 | content: h('div', { |
34 | style: { |
35 | padding: '20px' |
36 | } |
37 | }, [ |
38 | h('h2', { |
39 | style: { |
40 | 'font-weight': 'normal' |
41 | } |
42 | }, [i18n('By default, Patchwork will only see other users that are on the same local area network as you.')]), |
43 | h('div', [ |
44 | i18n('In order to share with users on the internet, you need to be invited to a pub server.') |
45 | ]), |
46 | input |
47 | ]), |
48 | footer: [ |
49 | h('button -save', { |
50 | disabled: publishing, |
51 | 'ev-click': () => { |
52 | publishing.set(true) |
53 | publishStatus.set(api.invite.async.accept(input.value.trim(), (err) => { |
54 | if (err) { |
55 | publishing.set(false) |
56 | showDialog({ |
57 | type: 'error', |
58 | title: i18n('Error'), |
59 | buttons: [i18n('OK')], |
60 | message: i18n('An error occurred while attempting to redeem invite.'), |
61 | detail: err.message |
62 | }) |
63 | } else { |
64 | close() |
65 | } |
66 | })) |
67 | } |
68 | }, [ when(publishing, publishStatus, i18n('Redeem Invite')) ]), |
69 | h('button -cancel', { |
70 | 'ev-click': close |
71 | }, i18n('Cancel')) |
72 | ] |
73 | } |
74 | }) |
75 | }) |
76 | } |
77 | |
78 | function showDialog (opts) { |
79 | electron.remote.dialog.showMessageBox(electron.remote.getCurrentWindow(), opts) |
80 | } |
81 |
Built with git-ssb-web