Files: e722641cbffa14a6c07ea99bba8dccb1a15c78c1 / message / html / confirm.js
1368 bytesRaw
1 | const nest = require('depnest') |
2 | const lightbox = require('hyperlightbox') |
3 | const { h } = require('mutant') |
4 | // publish or add |
5 | |
6 | exports.gives = nest('message.html.confirm') |
7 | |
8 | exports.needs = nest({ |
9 | message: { |
10 | 'async.publish': 'first', |
11 | 'html.render': 'first' |
12 | }, |
13 | 'keys.sync.id': 'first' |
14 | }) |
15 | |
16 | exports.create = function (api) { |
17 | return nest({ |
18 | 'message.html': { confirm } |
19 | }) |
20 | |
21 | function confirm (content, cb) { |
22 | cb = cb || function () {} |
23 | |
24 | var lb = lightbox() |
25 | document.body.appendChild(lb) |
26 | |
27 | var msg = { |
28 | key: 'DRAFT', |
29 | value: { |
30 | author: api.keys.sync.id(), |
31 | previous: null, |
32 | sequence: null, |
33 | timestamp: Date.now(), |
34 | content: content |
35 | } |
36 | } |
37 | |
38 | var okay = h('button.okay', { |
39 | 'ev-click': () => { |
40 | lb.remove() |
41 | api.message.async.publish(content, cb) |
42 | } |
43 | }, 'okay') |
44 | |
45 | var cancel = h('button.cancel.-subtle', { |
46 | 'ev-click': () => { |
47 | lb.remove() |
48 | cb(null) |
49 | } |
50 | }, 'cancel') |
51 | |
52 | okay.addEventListener('keydown', (ev) => { |
53 | if (ev.keyCode === 27) cancel.click() // escape |
54 | }) |
55 | |
56 | lb.show(h('MessageConfirm', [ |
57 | h('header -preview_description', [ |
58 | h('h1', 'Preview') |
59 | ]), |
60 | h('section -message_preview', api.message.html.render(msg)), |
61 | h('section -actions', [cancel, okay]) |
62 | ])) |
63 | |
64 | okay.focus() |
65 | } |
66 | } |
67 |
Built with git-ssb-web