git ssb

16+

Dominic / patchbay



Tree: f3abfca785a8f7b93cc0240027581e4dbe4385d9

Files: f3abfca785a8f7b93cc0240027581e4dbe4385d9 / modules_core / message-confirm.js

1484 bytesRaw
1const fs = require('fs')
2const lightbox = require('hyperlightbox')
3const h = require('../h')
4const u = require('../util')
5const self_id = require('../keys').id
6//publish or add
7
8const plugs = require('../plugs')
9
10exports.needs = {
11 publish: 'first',
12 message_render: 'first',
13 avatar: 'first',
14 message_meta: 'map'
15}
16
17exports.gives = {
18 message_confirm: 'true',
19 mcss: 'true'
20}
21
22exports.create = function (api) {
23 return {
24 message_confirm,
25 mcss: () => fs.readFileSync(__filename.replace(/js$/, 'mcss'), 'utf8')
26 }
27
28 function message_confirm (content, cb) {
29
30 cb = cb || function () {}
31
32 var lb = lightbox()
33 document.body.appendChild(lb)
34
35 var msg = {
36 key: "DRAFT",
37 value: {
38 author: self_id,
39 previous: null,
40 sequence: null,
41 timestamp: Date.now(),
42 content: content
43 }
44 }
45
46 var okay = h('button', {
47 'ev-click': () => {
48 lb.remove()
49 api.publish(content, cb)
50 }},
51 'okay'
52 )
53
54 var cancel = h('button', {
55 'ev-click': () => {
56 lb.remove()
57 cb(null)
58 }},
59 'Cancel'
60 )
61
62 okay.addEventListener('keydown', function (ev) {
63 if(ev.keyCode === 27) cancel.click() //escape
64 })
65
66 lb.show(h('MessageConfirm', [
67 h('header -preview_description', h('h1', 'Preview')),
68 h('section -message_preview', api.message_render(msg)),
69 h('section -actions', [okay, cancel])
70 ]
71 ))
72
73 okay.focus()
74 }
75}
76
77

Built with git-ssb-web