Commit 98a2107f7a6f0dc6ea2ca1a3e86d1b830cfb74ff
add ability to publish avatar images
Ev Bogue committed on 6/30/2018, 2:08:10 PMParent: e123126e7f263e8ab6840196d1ed0666c79c1bcc
Files changed
package-lock.json | changed |
package.json | changed |
views.js | changed |
package-lock.json | ||
---|---|---|
The diff is too large to show. Use a local git client to view these changes. Old file size: 205304 bytes New file size: 205908 bytes |
package.json | ||
---|---|---|
@@ -16,12 +16,14 @@ | ||
16 | 16 | }, |
17 | 17 | "author": "Ev Bogue <ev@evbogue.com>", |
18 | 18 | "license": "MIT", |
19 | 19 | "dependencies": { |
20 | + "dataurl-": "^0.1.0", | |
20 | 21 | "decent-ws": "1.0.4", |
21 | 22 | "deep-extend": "^0.6.0", |
22 | 23 | "emoji-server": "^1.0.0", |
23 | 24 | "human-time": "0.0.1", |
25 | + "hyperfile": "^2.0.0", | |
24 | 26 | "hyperloadmore": "^1.1.0", |
25 | 27 | "hyperscript": "^2.0.2", |
26 | 28 | "hyperscroll": "^1.0.0", |
27 | 29 | "muxrpcli": "^1.1.0", |
views.js | ||
---|---|---|
@@ -1,8 +1,10 @@ | ||
1 | 1 | var pull = require('pull-stream') |
2 | 2 | var human = require('human-time') |
3 | 3 | var sbot = require('./scuttlebot') |
4 | 4 | var hyperscroll = require('hyperscroll') |
5 | +var hyperfile = require('hyperfile') | |
6 | +var dataurl = require('dataurl-') | |
5 | 7 | var More = require('pull-more') |
6 | 8 | var stream = require('hyperloadmore/stream') |
7 | 9 | var h = require('hyperscript') |
8 | 10 | var render = require('./render') |
@@ -139,13 +141,14 @@ | ||
139 | 141 | screen.firstChild.insertBefore(profile, screen.firstChild.firstChild) |
140 | 142 | } else { |
141 | 143 | screen.firstChild.appendChild(profile) |
142 | 144 | } |
145 | + | |
143 | 146 | var name = avatar.name(src) |
144 | 147 | |
145 | 148 | var editname = h('span', |
146 | 149 | avatar.name(src), |
147 | - h('button.btn', 'Edit', { | |
150 | + h('button.btn', 'New name', { | |
148 | 151 | onclick: function () { |
149 | 152 | var nameput = h('input', {placeholder: name.textContent}) |
150 | 153 | var nameedit = |
151 | 154 | h('span', nameput, |
@@ -171,12 +174,73 @@ | ||
171 | 174 | } |
172 | 175 | }) |
173 | 176 | ) |
174 | 177 | |
178 | + var editimage = h('span', | |
179 | + h('button.btn', 'New image', { | |
180 | + onclick: function () { | |
181 | + var upload = | |
182 | + h('span', | |
183 | + hyperfile.asDataURL(function (data) { | |
184 | + if(data) { | |
185 | + //img.src = data | |
186 | + var _data = dataurl.parse(data) | |
187 | + pull( | |
188 | + pull.once(_data.data), | |
189 | + sbot.addblob(function (err, hash) { | |
190 | + if(err) return alert(err.stack) | |
191 | + selected = { | |
192 | + link: hash, | |
193 | + size: _data.data.length, | |
194 | + type: _data.mimetype, | |
195 | + width: 512, | |
196 | + height: 512 | |
197 | + } | |
198 | + }) | |
199 | + ) | |
200 | + } | |
201 | + }), | |
202 | + h('button.btn', 'Preview image', { | |
203 | + onclick: function() { | |
204 | + if (selected) { | |
205 | + console.log(selected) | |
206 | + var oldImage = document.getElementById('profileImage') | |
207 | + var newImage = h('span.avatar--medium', h('img', {src: config.blobsUrl + selected.link})) | |
208 | + var publish = h('button.btn', 'Publish image', { | |
209 | + onclick: function () { | |
210 | + sbot.publish({ | |
211 | + type: 'about', | |
212 | + about: src, | |
213 | + image: selected | |
214 | + }, function (err, published) { | |
215 | + console.log(published) | |
216 | + }) | |
217 | + } | |
218 | + }) | |
219 | + upload.parentNode.replaceChild(publish, upload) | |
220 | + oldImage.parentNode.replaceChild(newImage, oldImage) | |
221 | + } | |
222 | + /*if(selected) { | |
223 | + api.message_confirm({ | |
224 | + type: 'about', | |
225 | + about: id, | |
226 | + image: selected | |
227 | + }) | |
228 | + } else { alert('select an image before hitting preview')}*/ | |
229 | + } | |
230 | + }) | |
231 | + ) | |
232 | + editimage.parentNode.replaceChild(upload, editimage) | |
233 | + } | |
234 | + }) | |
235 | + ) | |
236 | + | |
175 | 237 | var avatars = h('div.avatars', |
176 | 238 | h('a', {href: '#' + src}, |
177 | - h('span.avatar--medium', avatar.image(src)), | |
178 | - editname | |
239 | + h('span.avatar--medium#profileImage', avatar.image(src)), | |
240 | + editname, | |
241 | + h('br'), | |
242 | + editimage | |
179 | 243 | ) |
180 | 244 | ) |
181 | 245 | |
182 | 246 | pull( |
Built with git-ssb-web