git ssb

0+

ev / microbay



forked from Dominic / patchbay

Commit 6200cdd535433e85ea74c0c9b081b40ecfadc318

show current avatar before editing

Dominic Tarr committed on 7/24/2016, 2:22:42 AM
Parent: e6ce2dce581a71e5f842aebd7db2ce276259e39e

Files changed

modules/avatar-edit.jschanged
modules/avatar-edit.jsView
@@ -1,12 +1,22 @@
11 var dataurl = require('dataurl')
2-
32 var hyperfile = require('hyperfile')
4-
53 var hypercrop = require('hypercrop')
64 var hyperlightbox = require('hyperlightbox')
75 var h = require('hyperscript')
6+var pull = require('pull-stream')
7+var getAvatar = require('ssb-avatar')
8+var plugs = require('../plugs')
9+var ref = require('ssb-ref')
810
11+var self_id = require('../keys').id
12+var default_avatar = '&qjeAs8+uMXLlyovT4JnEpMwTNDx/QXHfOl2nv2u0VCM=.sha256'
13+
14+var confirm = plugs.first(exports.message_confirm = [])
15+var sbot_blobs_add = plugs.first(exports.sbot_blobs_add = [])
16+var blob_url = plugs.first(exports.blob_url = [])
17+var sbot_links = plugs.first(exports.sbot_links = [])
18+
919 function crop (d, cb) {
1020 var data
1121 var canvas = hypercrop(h('img', {src: d}))
1222
@@ -23,25 +33,31 @@
2333 )
2434 )
2535 }
2636
27-var plugs = require('../plugs')
28-var confirm = plugs.first(exports.message_confirm = [])
29-var sbot_blobs_add = plugs.first(exports.sbot_blobs_add = [])
37+exports.avatar_edit = function (id) {
3038
31-var pull = require('pull-stream')
32-
33-exports.avatar_edit = function (id) {
39+ var img = h('img', {src: blob_url(default_avatar)})
3440 var lb = hyperlightbox()
35- var img = h('img', {src: ''}) //TODO, show current image.
36- var name = h('input', {placeholder: 'rename'})
37-
41+ var name_input = h('input', {placeholder: 'rename'})
42+ var name = h('h2.avatar__name')
3843 var selected = null
3944
45+ getAvatar({links: sbot_links}, self_id, id, function (err, avatar) {
46+ if (err) return console.error(err)
47+ //don't show user has already selected an avatar.
48+ if(selected) return
49+ if(ref.isBlob(avatar.image))
50+ img.src = blob_url(avatar.image)
51+ name.textContent = avatar.name
52+ })
53+
54+
4055 return h('div',
4156 lb,
57+ name,
4258 img,
43- name,
59+ name_input,
4460 hyperfile.asDataURL(function (data) {
4561 var el = crop(data, function (err, data) {
4662 if(data) {
4763 img.src = data
@@ -51,8 +67,11 @@
5167 })
5268 lb.show(el)
5369 }),
5470 h('button', 'update', {onclick: function () {
71+ if(name_input.value)
72+ name.textContent = name_input.value
73+
5574 if(selected) {
5675 pull(
5776 pull.once(selected.data),
5877 sbot_blobs_add(function (err, hash) {
@@ -61,9 +80,9 @@
6180 if(err) return alert(err.stack)
6281 confirm({
6382 type: 'about',
6483 about: id,
65- name: name.value || undefined,
84+ name: name_input.value || undefined,
6685 image: {
6786 link: hash,
6887 size: selected.data.length,
6988 type: selected.mimetype,
@@ -77,20 +96,13 @@
7796 else if(input.value) //name only
7897 confirm({
7998 type: 'about',
8099 about: id,
81- name: name.value || undefined,
100+ name: name_input.value || undefined,
82101 })
83102 else
84103 //another moment of weakness
85104 alert('must select a name or image')
86105 }})
87106 )
88107 }
89108
90-
91-
92-
93-
94-
95-
96-

Built with git-ssb-web