git ssb

16+

Dominic / patchbay



Tree: fbcc653a737540377581d8ad192c343352ae4818

Files: fbcc653a737540377581d8ad192c343352ae4818 / message / html / confirm.js

1368 bytesRaw
1const nest = require('depnest')
2const lightbox = require('hyperlightbox')
3const { h } = require('mutant')
4// publish or add
5
6exports.gives = nest('message.html.confirm')
7
8exports.needs = nest({
9 message: {
10 'async.publish': 'first',
11 'html.render': 'first'
12 },
13 'keys.sync.id': 'first'
14})
15
16exports.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