git ssb

16+

Dominic / patchbay



Commit c50d342b5fb946f181fcee2b8be330d21f37c752

add confirm message to profile about edit

mix irving committed on 2/28/2017, 2:00:09 AM
Parent: acb782ead8eee531515234e53a11d33a3968a10f

Files changed

about/html/edit.jschanged
message/html/confirm.jsadded
message/html/confirm.mcssadded
about/html/edit.jsView
@@ -11,35 +11,21 @@
1111 const getAvatar = require('ssb-avatar')
1212 const ref = require('ssb-ref')
1313 const visualize = require('visualize-buffer')
1414
15-function crop (d, cb) {
16- var canvas = hypercrop(h('img', {src: d}))
15+exports.gives = nest('about.html.edit')
1716
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-
2917 exports.needs = nest({
3018 'about.obs.name': 'first',
19+ 'blob.sync.url': 'first',
3120 'keys.sync.id': 'first',
32- 'blob.sync.url': 'first',
21+ 'message.html.confirm': 'first',
3322 sbot: {
3423 'async.addBlob': 'first',
3524 'pull.links': 'first'
3625 }
37- // 'message.confirm': 'first',
3826 })
3927
40-exports.gives = nest('about.html.edit')
41-
4228 exports.create = function (api) {
4329 return nest({
4430 'about.html.edit': edit
4531 })
@@ -60,9 +46,9 @@
6046 }
6147 })
6248
6349 var name = Struct({
64- original: computed(api.about.obs.name(id), name => '@' + name),
50+ original: Value('@' + api.about.obs.name(id)()),
6551 new: Value()
6652 })
6753
6854 var images = MutantArray()
@@ -191,9 +177,9 @@
191177
192178 if (newName) msg.name = newName
193179 if (newAvatar.link) msg.image = newAvatar
194180
195- api.message.confirm(msg, (err, data) => {
181+ api.message.html.confirm(msg, (err, data) => {
196182 if (err) return console.error(err)
197183
198184 if (newName) name.original.set('@' + newName)
199185 if (newAvatar.link) avatar.original.set(api.blob.sync.url(newAvatar.link))
@@ -205,4 +191,18 @@
205191 }
206192 }
207193 }
208194
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.jsView
@@ -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.mcssView
@@ -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