Files: 04c385c3b68e8f6a953b37f9f099b1116e22c8b5 / message / html / confirm.js
1373 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 | |
46 | var cancel = h('button.cancel', { |
47 | 'ev-click': () => { |
48 | lb.remove() |
49 | cb(null) |
50 | }}, |
51 | 'cancel' |
52 | ) |
53 | |
54 | okay.addEventListener('keydown', (ev) => { |
55 | if (ev.keyCode === 27) cancel.click() // escape |
56 | }) |
57 | |
58 | lb.show(h('MessageConfirm', [ |
59 | h('header -preview_description', [ |
60 | h('h1', 'Preview') |
61 | ]), |
62 | h('section -message_preview', api.message.html.render(msg)), |
63 | h('section -actions', [cancel, okay]) |
64 | ])) |
65 | |
66 | okay.focus() |
67 | } |
68 | } |
69 | |
70 |
Built with git-ssb-web