git ssb

16+

Dominic / patchbay



Tree: 9c5fb9afa9248c901294db9eac5e350da9bc055d

Files: 9c5fb9afa9248c901294db9eac5e350da9bc055d / message / html / confirm.js

1473 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 ev.preventDefault()
54 ev.stopPropagation()
55
56 if (ev.keyCode === 27) cancel.click() // escape
57 if (ev.keyCode === 13) okay.click() // enter
58 })
59
60 lb.show(h('MessageConfirm', [
61 h('header -preview_description', [
62 h('h1', 'Preview')
63 ]),
64 h('section -message_preview', api.message.html.render(msg)),
65 h('section -actions', [cancel, okay])
66 ]))
67
68 okay.focus()
69 }
70}
71

Built with git-ssb-web