git ssb

16+

Dominic / patchbay



Commit 7754e4bdfb8538b548c655b761a8a4f9603381e3

add avatar-edit

Dominic Tarr committed on 7/24/2016, 2:12:09 AM
Parent: 55b4b4ef06d51a129609282f85186a3f2a6e3237

Files changed

modules/index.jschanged
modules/avatar-edit.jsadded
modules/index.jsView
@@ -1,7 +1,8 @@
11 module.exports = {
22 "_screen_view.js": require('./_screen_view.js'),
33 "about.js": require('./about.js'),
4+ "avatar-edit.js": require('./avatar-edit.js'),
45 "avatar-image.js": require('./avatar-image.js'),
56 "avatar-profile.js": require('./avatar-profile.js'),
67 "avatar.js": require('./avatar.js'),
78 "blob-url.js": require('./blob-url.js'),
modules/avatar-edit.jsView
@@ -1,0 +1,95 @@
1+var dataurl = require('dataurl')
2+
3+var hyperfile = require('hyperfile')
4+
5+var hypercrop = require('hypercrop')
6+var hyperlightbox = require('hyperlightbox')
7+var h = require('hyperscript')
8+
9+function crop (d, cb) {
10+ var data
11+ var canvas = hypercrop(h('img', {src: d}))
12+
13+ return h('div.avatar_pic',
14+ canvas, canvas.selection,
15+ h('div.avatar_pic__controls',
16+ h('button', 'okay', {onclick: function () {
17+ cb(null, canvas.selection.toDataURL())
18+ }}),
19+ h('button', 'cancel', {onclick: function () {
20+ cb(new Error('canceled'))
21+ }})
22+ )
23+ )
24+}
25+
26+var plugs = require('../plugs')
27+var confirm = plugs.first(exports.message_confirm = [])
28+var sbot_blobs_add = plugs.first(exports.sbot_blobs_add = [])
29+
30+var pull = require('pull-stream')
31+
32+exports.avatar_edit = function (id) {
33+ var lb = hyperlightbox()
34+ var img = h('img', {src: ''}) //TODO, show current image.
35+ var name = h('input', {placeholder: 'rename'})
36+
37+ var selected = null
38+
39+ return h('div',
40+ lb,
41+ img,
42+ name,
43+ hyperfile.asDataURL(function (data) {
44+ var el = crop(data, function (err, data) {
45+ if(data) {
46+ img.src = data
47+ selected = dataurl.parse(data)
48+ }
49+ lb.close()
50+ })
51+ lb.show(el)
52+ }),
53+ h('button', 'update', {onclick: function () {
54+ if(selected) {
55+ pull(
56+ pull.once(selected.data),
57+ sbot_blobs_add(function (err, hash) {
58+ //TODO. Alerts are EVIL.
59+ //I use them only in a moment of weakness.
60+ if(err) return alert(err.stack)
61+ confirm({
62+ type: 'about',
63+ about: id,
64+ name: name.value || undefined,
65+ image: {
66+ link: hash,
67+ size: selected.data.length,
68+ type: selected.mimetype,
69+ width: 512,
70+ height: 512
71+ }
72+ })
73+ })
74+ )
75+ }
76+ else if(input.value) //name only
77+ confirm({
78+ type: 'about',
79+ about: id,
80+ name: name.value || undefined,
81+ })
82+ else
83+ //another moment of weakness
84+ alert('must select a name or image')
85+ }})
86+ )
87+}
88+
89+
90+
91+
92+
93+
94+
95+

Built with git-ssb-web