Commit c50d342b5fb946f181fcee2b8be330d21f37c752
add confirm message to profile about edit
mix irving committed on 2/28/2017, 2:00:09 AMParent: acb782ead8eee531515234e53a11d33a3968a10f
Files changed
about/html/edit.js | changed |
message/html/confirm.js | added |
message/html/confirm.mcss | added |
about/html/edit.js | ||
---|---|---|
@@ -11,35 +11,21 @@ | ||
11 | 11 | const getAvatar = require('ssb-avatar') |
12 | 12 | const ref = require('ssb-ref') |
13 | 13 | const visualize = require('visualize-buffer') |
14 | 14 | |
15 | -function crop (d, cb) { | |
16 | - var canvas = hypercrop(h('img', {src: d})) | |
15 | +exports.gives = nest('about.html.edit') | |
17 | 16 | |
18 | - return h('AboutImageEditor', [ | |
19 | - h('header', 'Click and drag to crop your avatar.'), | |
20 | - canvas, | |
21 | - // canvas.selection, | |
22 | - h('section.actions', [ | |
23 | - h('button.cancel', { 'ev-click': () => cb(new Error('canceled')) }, 'cancel'), | |
24 | - h('button.okay', { 'ev-click': () => cb(null, canvas.selection.toDataURL()) }, 'okay') | |
25 | - ]) | |
26 | - ]) | |
27 | -} | |
28 | - | |
29 | 17 | exports.needs = nest({ |
30 | 18 | 'about.obs.name': 'first', |
19 | + 'blob.sync.url': 'first', | |
31 | 20 | 'keys.sync.id': 'first', |
32 | - 'blob.sync.url': 'first', | |
21 | + 'message.html.confirm': 'first', | |
33 | 22 | sbot: { |
34 | 23 | 'async.addBlob': 'first', |
35 | 24 | 'pull.links': 'first' |
36 | 25 | } |
37 | - // 'message.confirm': 'first', | |
38 | 26 | }) |
39 | 27 | |
40 | -exports.gives = nest('about.html.edit') | |
41 | - | |
42 | 28 | exports.create = function (api) { |
43 | 29 | return nest({ |
44 | 30 | 'about.html.edit': edit |
45 | 31 | }) |
@@ -60,9 +46,9 @@ | ||
60 | 46 | } |
61 | 47 | }) |
62 | 48 | |
63 | 49 | var name = Struct({ |
64 | - original: computed(api.about.obs.name(id), name => '@' + name), | |
50 | + original: Value('@' + api.about.obs.name(id)()), | |
65 | 51 | new: Value() |
66 | 52 | }) |
67 | 53 | |
68 | 54 | var images = MutantArray() |
@@ -191,9 +177,9 @@ | ||
191 | 177 | |
192 | 178 | if (newName) msg.name = newName |
193 | 179 | if (newAvatar.link) msg.image = newAvatar |
194 | 180 | |
195 | - api.message.confirm(msg, (err, data) => { | |
181 | + api.message.html.confirm(msg, (err, data) => { | |
196 | 182 | if (err) return console.error(err) |
197 | 183 | |
198 | 184 | if (newName) name.original.set('@' + newName) |
199 | 185 | if (newAvatar.link) avatar.original.set(api.blob.sync.url(newAvatar.link)) |
@@ -205,4 +191,18 @@ | ||
205 | 191 | } |
206 | 192 | } |
207 | 193 | } |
208 | 194 | |
195 | +function crop (d, cb) { | |
196 | + var canvas = hypercrop(h('img', {src: d})) | |
197 | + | |
198 | + return h('AboutImageEditor', [ | |
199 | + h('header', 'Click and drag to crop your avatar.'), | |
200 | + canvas, | |
201 | + // canvas.selection, | |
202 | + h('section.actions', [ | |
203 | + h('button.cancel', { 'ev-click': () => cb(new Error('canceled')) }, 'cancel'), | |
204 | + h('button.okay', { 'ev-click': () => cb(null, canvas.selection.toDataURL()) }, 'okay') | |
205 | + ]) | |
206 | + ]) | |
207 | +} | |
208 | + |
message/html/confirm.js | ||
---|---|---|
@@ -1,0 +1,73 @@ | ||
1 | +const nest = require('depnest') | |
2 | +const lightbox = require('hyperlightbox') | |
3 | +const { h } = require('mutant') | |
4 | +//publish or add | |
5 | + | |
6 | +exports.gives = nest('message.html.confirm') | |
7 | + | |
8 | +exports.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 | + | |
18 | +exports.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 | + |
message/html/confirm.mcss | ||
---|---|---|
@@ -1,0 +1,41 @@ | ||
1 | +MessageConfirm { | |
2 | + section { | |
3 | + -preview_description { | |
4 | + } | |
5 | + | |
6 | + -message_preview { | |
7 | + max-height: 70vh | |
8 | + overflow-y: auto | |
9 | + | |
10 | + background-color: white | |
11 | + | |
12 | + div { | |
13 | + header.author { | |
14 | + div { | |
15 | + section { | |
16 | + -timestamp { | |
17 | + display: none | |
18 | + } | |
19 | + } | |
20 | + } | |
21 | + } | |
22 | + | |
23 | + section.action { | |
24 | + display: none | |
25 | + } | |
26 | + } | |
27 | + } | |
28 | + | |
29 | + -actions { | |
30 | + margin-top: 1rem | |
31 | + display: flex | |
32 | + justify-content: flex-end | |
33 | + | |
34 | + button { | |
35 | + margin: 0 0 0 1rem | |
36 | + } | |
37 | + } | |
38 | + } | |
39 | +} | |
40 | + | |
41 | + |
Built with git-ssb-web