Commit 6200cdd535433e85ea74c0c9b081b40ecfadc318
show current avatar before editing
Dominic Tarr committed on 7/24/2016, 2:22:42 AMParent: e6ce2dce581a71e5f842aebd7db2ce276259e39e
Files changed
modules/avatar-edit.js | changed |
modules/avatar-edit.js | ||
---|---|---|
@@ -1,12 +1,22 @@ | ||
1 | 1 | var dataurl = require('dataurl') |
2 | - | |
3 | 2 | var hyperfile = require('hyperfile') |
4 | - | |
5 | 3 | var hypercrop = require('hypercrop') |
6 | 4 | var hyperlightbox = require('hyperlightbox') |
7 | 5 | 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') | |
8 | 10 | |
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 | + | |
9 | 19 | function crop (d, cb) { |
10 | 20 | var data |
11 | 21 | var canvas = hypercrop(h('img', {src: d})) |
12 | 22 | |
@@ -23,25 +33,31 @@ | ||
23 | 33 | ) |
24 | 34 | ) |
25 | 35 | } |
26 | 36 | |
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) { | |
30 | 38 | |
31 | -var pull = require('pull-stream') | |
32 | - | |
33 | -exports.avatar_edit = function (id) { | |
39 | + var img = h('img', {src: blob_url(default_avatar)}) | |
34 | 40 | 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') | |
38 | 43 | var selected = null |
39 | 44 | |
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 | + | |
40 | 55 | return h('div', |
41 | 56 | lb, |
57 | + name, | |
42 | 58 | img, |
43 | - name, | |
59 | + name_input, | |
44 | 60 | hyperfile.asDataURL(function (data) { |
45 | 61 | var el = crop(data, function (err, data) { |
46 | 62 | if(data) { |
47 | 63 | img.src = data |
@@ -51,8 +67,11 @@ | ||
51 | 67 | }) |
52 | 68 | lb.show(el) |
53 | 69 | }), |
54 | 70 | h('button', 'update', {onclick: function () { |
71 | + if(name_input.value) | |
72 | + name.textContent = name_input.value | |
73 | + | |
55 | 74 | if(selected) { |
56 | 75 | pull( |
57 | 76 | pull.once(selected.data), |
58 | 77 | sbot_blobs_add(function (err, hash) { |
@@ -61,9 +80,9 @@ | ||
61 | 80 | if(err) return alert(err.stack) |
62 | 81 | confirm({ |
63 | 82 | type: 'about', |
64 | 83 | about: id, |
65 | - name: name.value || undefined, | |
84 | + name: name_input.value || undefined, | |
66 | 85 | image: { |
67 | 86 | link: hash, |
68 | 87 | size: selected.data.length, |
69 | 88 | type: selected.mimetype, |
@@ -77,20 +96,13 @@ | ||
77 | 96 | else if(input.value) //name only |
78 | 97 | confirm({ |
79 | 98 | type: 'about', |
80 | 99 | about: id, |
81 | - name: name.value || undefined, | |
100 | + name: name_input.value || undefined, | |
82 | 101 | }) |
83 | 102 | else |
84 | 103 | //another moment of weakness |
85 | 104 | alert('must select a name or image') |
86 | 105 | }}) |
87 | 106 | ) |
88 | 107 | } |
89 | 108 | |
90 | - | |
91 | - | |
92 | - | |
93 | - | |
94 | - | |
95 | - | |
96 | - |
Built with git-ssb-web