git ssb

16+

Dominic / patchbay



Tree: c50d342b5fb946f181fcee2b8be330d21f37c752

Files: c50d342b5fb946f181fcee2b8be330d21f37c752 / message / html / confirm.js

1423 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 // about: { image_name_link: 'first' },
10 message: {
11 'async.publish': 'first',
12 'html.render': 'first'
13 },
14 'keys.sync.id': 'first',
15})
16
17
18exports.create = function (api) {
19 return nest({
20 'message.html': { confirm }
21 })
22
23 function confirm (content, cb) {
24
25 cb = cb || function () {}
26
27 var lb = lightbox()
28 document.body.appendChild(lb)
29
30 var msg = {
31 key: "DRAFT",
32 value: {
33 author: api.keys.sync.id(),
34 previous: null,
35 sequence: null,
36 timestamp: Date.now(),
37 content: content
38 }
39 }
40
41 var okay = h('button.okay', {
42 'ev-click': () => {
43 lb.remove()
44 api.message.async.publish(content, cb)
45 }},
46 'okay'
47 )
48
49 var cancel = h('button.cancel', {
50 'ev-click': () => {
51 lb.remove()
52 cb(null)
53 }},
54 'cancel'
55 )
56
57 okay.addEventListener('keydown', function (ev) {
58 if(ev.keyCode === 27) cancel.click() //escape
59 })
60
61 lb.show(h('MessageConfirm', [
62 h('header -preview_description', [
63 h('h1', 'Preview')
64 ]),
65 h('section -message_preview', api.message.html.render(msg)),
66 h('section -actions', [cancel, okay])
67 ]))
68
69 okay.focus()
70 }
71}
72
73
74

Built with git-ssb-web