git ssb

16+

Dominic / patchbay



Tree: dd6a5bf5f2c82fb52a866d1576c7f04a83e9678e

Files: dd6a5bf5f2c82fb52a866d1576c7f04a83e9678e / message / html / confirm.js

1372 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
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

Built with git-ssb-web