git ssb

16+

Dominic / patchbay



Commit 9559b880d14951aa95c73f0af2844ebf330d389a

refactor profile editing to use more beautiful observables

mix irving committed on 2/28/2017, 5:22:47 AM
Parent: c50d342b5fb946f181fcee2b8be330d21f37c752

Files changed

about/html/edit.jschanged
message/html/confirm.jschanged
package.jsonchanged
about/html/edit.jsView
@@ -7,16 +7,14 @@
77 h, Value, Array: MutantArray, Dict: MutantObject, Struct,
88 map, computed, when, dictToCollection
99 } = require('mutant')
1010 const pull = require('pull-stream')
11-const getAvatar = require('ssb-avatar')
12-const ref = require('ssb-ref')
13-const visualize = require('visualize-buffer')
1411
1512 exports.gives = nest('about.html.edit')
1613
1714 exports.needs = nest({
1815 'about.obs.name': 'first',
16+ 'about.obs.imageUrl': 'first',
1917 'blob.sync.url': 'first',
2018 'keys.sync.id': 'first',
2119 'message.html.confirm': 'first',
2220 sbot: {
@@ -29,29 +27,23 @@
2927 return nest({
3028 'about.html.edit': edit
3129 })
3230
31+ // TODO refactor this to use obs better
3332 function edit (id) {
3433 var avatar = Struct({
35- original: Value(visualize(new Buffer(id.substring(1), 'base64'), 256).src),
34+ current: api.about.obs.imageUrl(id),
3635 new: MutantObject()
3736 })
3837
3938 const links = api.sbot.pull.links
4039
41- getAvatar({ links }, api.keys.sync.id(), id, (err, _avatar) => {
42- if (err) return console.error(err)
43- // don't show user has already selected an avatar.
44- if (ref.isBlob(_avatar.image)) {
45- avatar.original.set(api.blob.sync.url(_avatar.image))
46- }
47- })
48-
4940 var name = Struct({
50- original: Value('@' + api.about.obs.name(id)()),
41+ current: api.about.obs.name(id),
5142 new: Value()
5243 })
5344
45+ // TODO use patchcores observable images + names
5446 var images = MutantArray()
5547 pull(
5648 links({dest: id, rel: 'about', values: true}),
5749 pull.map(e => e.value.content.image),
@@ -83,14 +75,14 @@
8375 })
8476
8577 var avatarSrc = computed([avatar], avatar => {
8678 if (avatar.new.link) return api.blob.sync.url(avatar.new.link)
87- else return avatar.original
79+ else return avatar.current
8880 })
8981
9082 var displayedName = computed([name], name => {
9183 if (name.new) return '@' + name.new
92- else return name.original
84+ else return '@' + name.current
9385 })
9486
9587 return h('AboutEditor', [
9688 h('section.lightbox', lb),
@@ -180,11 +172,8 @@
180172
181173 api.message.html.confirm(msg, (err, data) => {
182174 if (err) return console.error(err)
183175
184- if (newName) name.original.set('@' + newName)
185- if (newAvatar.link) avatar.original.set(api.blob.sync.url(newAvatar.link))
186-
187176 clearNewSelections()
188177
189178 // TODO - update aliases displayed
190179 })
message/html/confirm.jsView
@@ -1,35 +1,32 @@
11 const nest = require('depnest')
22 const lightbox = require('hyperlightbox')
33 const { h } = require('mutant')
4-//publish or add
4+// publish or add
55
66 exports.gives = nest('message.html.confirm')
77
88 exports.needs = nest({
9- // about: { image_name_link: 'first' },
109 message: {
1110 'async.publish': 'first',
1211 'html.render': 'first'
1312 },
14- 'keys.sync.id': 'first',
13+ 'keys.sync.id': 'first'
1514 })
1615
17-
1816 exports.create = function (api) {
1917 return nest({
2018 'message.html': { confirm }
2119 })
2220
2321 function confirm (content, cb) {
24-
2522 cb = cb || function () {}
2623
2724 var lb = lightbox()
2825 document.body.appendChild(lb)
2926
3027 var msg = {
31- key: "DRAFT",
28+ key: 'DRAFT',
3229 value: {
3330 author: api.keys.sync.id(),
3431 previous: null,
3532 sequence: null,
@@ -37,9 +34,9 @@
3734 content: content
3835 }
3936 }
4037
41- var okay = h('button.okay', {
38+ var okay = h('button.okay', {
4239 'ev-click': () => {
4340 lb.remove()
4441 api.message.async.publish(content, cb)
4542 }},
@@ -54,9 +51,9 @@
5451 'cancel'
5552 )
5653
5754 okay.addEventListener('keydown', function (ev) {
58- if(ev.keyCode === 27) cancel.click() //escape
55+ if (ev.keyCode === 27) cancel.click() // escape
5956 })
6057
6158 lb.show(h('MessageConfirm', [
6259 h('header -preview_description', [
@@ -69,5 +66,4 @@
6966 okay.focus()
7067 }
7168 }
7269
73-
package.jsonView
@@ -41,12 +41,10 @@
4141 "pull-scroll": "^1.0.3",
4242 "pull-stream": "^3.5.0",
4343 "read-directory": "^2.0.0",
4444 "setimmediate": "^1.0.5",
45- "ssb-avatar": "^0.2.0",
4645 "ssb-mentions": "^0.1.1",
4746 "suggest-box": "^2.2.3",
48- "visualize-buffer": "0.0.1",
4947 "xtend": "^4.0.1"
5048 },
5149 "devDependencies": {
5250 "standard": "^8.6.0"

Built with git-ssb-web