git ssb

16+

Dominic / patchbay



Commit 627bb1ceef39b5cccd4915b82591d2b085d4716e

Merge remote-tracking branch 'dt/master' into git

Charles Lehner committed on 7/24/2016, 3:40:48 PM
Parent: e3d280e0a83dd60d5e5880b996b30782d4a68f67
Parent: bf5b79d17d7fcf89a7cb0ad35bff87d0c66f184a

Files changed

README.mdchanged
modules/avatar-profile.jschanged
modules/index.jschanged
modules/avatar-edit.jsadded
package.jsonchanged
sbot-api.jschanged
style.csschanged
.gitignoreadded
bundle.jsdeleted
index.htmldeleted
README.mdView
@@ -69,8 +69,9 @@
6969 now clone and run patchboard.
7070 ```
7171 git clone https://github.com/dominictarr/patchbay.git
7272 cd patchbay
73+npm intsall
7374 npm install electro electron-prebuilt -g
7475 electro index.js
7576 ```
7677
modules/avatar-profile.jsView
@@ -1,13 +1,19 @@
11 var h = require('hyperscript')
22 var plugs = require('../plugs')
33
4+
45 var avatar_image = plugs.first(exports.avatar_image = [])
6+var avatar_name = plugs.first(exports.avatar_name = [])
57 var avatar_action = plugs.map(exports.avatar_action = [])
8+var avatar_edit = plugs.first(exports.avatar_edit = [])
69
710 exports.avatar_profile = function (id) {
11+ return avatar_edit(id)
812
913 return h('div.row.profile',
1014 avatar_image(id),
11- h('div.column', avatar_action(id))
15+ h('div.profile__info',
16+ h('strong', avatar_name(id)),
17+ avatar_action(id))
1218 )
1319 }
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,110 @@
1+var dataurl = require('dataurl')
2+var hyperfile = require('hyperfile')
3+var hypercrop = require('hypercrop')
4+var hyperlightbox = require('hyperlightbox')
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')
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+var avatar_name = plugs.first(exports.avatar_name = [])
19+
20+function crop (d, cb) {
21+ var data
22+ var canvas = hypercrop(h('img', {src: d}))
23+
24+ return h('div.column.avatar_pic',
25+ canvas,
26+ //canvas.selection,
27+ h('div.row.avatar_pic__controls',
28+ h('button', 'okay', {onclick: function () {
29+ cb(null, canvas.selection.toDataURL())
30+ }}),
31+ h('button', 'cancel', {onclick: function () {
32+ cb(new Error('canceled'))
33+ }})
34+ )
35+ )
36+}
37+
38+exports.avatar_edit = function (id) {
39+
40+ var img = h('img', {src: blob_url(default_avatar)})
41+ var lb = hyperlightbox()
42+ var name_input = h('input', {placeholder: 'rename'})
43+ var name = avatar_name(id)
44+ var selected = null
45+
46+ getAvatar({links: sbot_links}, self_id, id, function (err, avatar) {
47+ if (err) return console.error(err)
48+ //don't show user has already selected an avatar.
49+ if(selected) return
50+ if(ref.isBlob(avatar.image))
51+ img.src = blob_url(avatar.image)
52+ })
53+
54+ return h('div.row.profile',
55+ lb,
56+ img,
57+ h('div.column.profile__info',
58+ h('strong', name),
59+ name_input,
60+
61+ hyperfile.asDataURL(function (data) {
62+ var el = crop(data, function (err, data) {
63+ if(data) {
64+ img.src = data
65+ selected = dataurl.parse(data)
66+ }
67+ lb.close()
68+ })
69+ lb.show(el)
70+ }),
71+ h('button', 'update', {onclick: function () {
72+ if(name_input.value)
73+ name.textContent = name_input.value
74+
75+ if(selected) {
76+ pull(
77+ pull.once(selected.data),
78+ sbot_blobs_add(function (err, hash) {
79+ //TODO. Alerts are EVIL.
80+ //I use them only in a moment of weakness.
81+ if(err) return alert(err.stack)
82+ confirm({
83+ type: 'about',
84+ about: id,
85+ name: name_input.value || undefined,
86+ image: {
87+ link: hash,
88+ size: selected.data.length,
89+ type: selected.mimetype,
90+ width: 512,
91+ height: 512
92+ }
93+ })
94+ })
95+ )
96+ }
97+ else if(input.value) //name only
98+ confirm({
99+ type: 'about',
100+ about: id,
101+ name: name_input.value || undefined,
102+ })
103+ else
104+ //another moment of weakness
105+ alert('must select a name or image')
106+ }})
107+ )
108+ )
109+}
110+
package.jsonView
@@ -1,17 +1,20 @@
11 {
22 "name": "patchbay",
33 "description": "a pluggable patchwork",
4- "version": "1.8.4",
4+ "version": "1.9.1",
55 "homepage": "https://github.com/dominictarr/patchbay",
66 "repository": {
77 "type": "git",
88 "url": "git://github.com/dominictarr/patchbay.git"
99 },
1010 "dependencies": {
1111 "cont": "^1.0.3",
12+ "dataurl": "^0.1.0",
1213 "depject": "^1.0.1",
13- "hyperlightbox": "^0.1.0",
14+ "hypercrop": "^1.0.1",
15+ "hyperfile": "^1.1.0",
16+ "hyperlightbox": "^0.1.1",
1417 "hyperscript": "^1.4.7",
1518 "hypertabs": "^1.2.0",
1619 "mime-types": "^2.1.11",
1720 "moment": "^2.13.0",
@@ -37,9 +40,9 @@
3740 "brfs": "^1.4.3",
3841 "indexhtmlify": "^1.2.1"
3942 },
4043 "scripts": {
41- "build": "node build.js > modules/index.js && browserify -t brfs index.js > bundle.js && indexhtmlify < bundle.js > index.html",
44+ "build": "node build.js > modules/index.js && mkdir -p build && browserify -t brfs index.js > build/bundle.js && indexhtmlify < build/bundle.js > build/index.html",
4245 "graph": "node index.js | dot -Tsvg > graph.svg",
4346 "test": "set -e; for t in test/*.js; do node $t; done"
4447 },
4548 "author": "Dominic Tarr <dominic.tarr@gmail.com> (http://dominictarr.com)",
sbot-api.jsView
@@ -68,9 +68,22 @@
6868
6969 return {
7070 sbot_blobs_add: rec.sink(function (cb) {
7171 return pull(
72- Hash(cb),
72+ Hash(function (err, id) {
73+ if(err) return cb(err)
74+ //completely UGLY hack to tell when the blob has been sucessfully written...
75+ var start = Date.now(), n = 5
76+ ;(function next () {
77+ setTimeout(function () {
78+ sbot.blobs.has(id, function (err, has) {
79+ if(has) return cb(null, id)
80+ if(n--) next()
81+ else cb(new Error('write failed'))
82+ })
83+ }, Date.now() - start)
84+ })()
85+ }),
7386 sbot.blobs.add()
7487 )
7588 }),
7689 sbot_links: rec.source(function (query) {
@@ -108,4 +121,6 @@
108121 })
109122 }
110123 }
111124
125+
126+
style.cssView
@@ -1,8 +1,10 @@
11 body {
22 font-family: "Source Sans Pro", sans-serif;
33 }
44
5+p { margin-top: .35ex;}
6+
57 .screen {
68 position: absolute;
79 top: 0px; bottom: 0px;
810 left: 0px; right: 0px;
@@ -125,9 +127,9 @@
125127 /* messages */
126128
127129 .message {
128130 border: 1px solid #eee;
129- padding: 5px;
131+ padding: 7px;
130132 margin-top: .5em;
131133 background: white;
132134 display: block;
133135 flex-basis: 0;
@@ -212,19 +214,22 @@
212214 }
213215
214216 .profile {
215217 background: #fff;
218+ padding: .5em;
216219 border: 1px solid #eee;
217220 }
218221
219222 .profile img {
220- width: 150px;
221- height: 150px;
222- margin-right: 1em;
223- margin-bottom: 1em;
224- border: 1px solid #ccc;
223+ width: 256px;
224+ height: 256px;
225+ border: 1px solid #eee;
225226 }
226227
228+.profile__info {
229+ margin-left: .5em;
230+}
231+
227232 /* lightbox - used in message-confirm */
228233
229234 .lightbox {
230235 overflow: auto;
@@ -263,4 +268,9 @@
263268 highlight {
264269 background: yellow;
265270 }
266271
272+/* avatar editor */
273+
274+.hypercrop__canvas {
275+ width: 100%;
276+}
.gitignoreView
@@ -1,0 +1,5 @@
1+node_modules
2+npm-debug.log
3+.npmignore
4+build
5+
bundle.jsView
The diff is too large to show. Use a local git client to view these changes.
Old file size: 2054582 bytes
New file size: 0 bytes
index.htmlView
The diff is too large to show. Use a local git client to view these changes.
Old file size: 2054809 bytes
New file size: 0 bytes

Built with git-ssb-web