git ssb

10+

Matt McKegg / patchwork



Commit 9a819a51f9e714d07b90b34130d7c67671c60e38

profile: allow picking existing names/images and adding new ones

Matt McKegg committed on 2/17/2017, 12:43:45 PM
Parent: 265c3f6951545f5768f03154d5c6890be9aa8771

Files changed

modules/page/html/render/profile.jschanged
styles/picker.mcsschanged
modules/page/html/render/profile.jsView
@@ -1,7 +1,7 @@
11 var nest = require('depnest')
22 var ref = require('ssb-ref')
3-var {Value, h, when, computed, map, send, dictToCollection} = require('mutant')
3 +var {h, when, computed, map, send, dictToCollection, resolve} = require('mutant')
44 var extend = require('xtend')
55
66 exports.needs = nest({
77 'about.obs': {
@@ -10,13 +10,16 @@
1010 images: 'first',
1111 color: 'first'
1212 },
1313 'blob.sync.url': 'first',
14 + 'blob.html.input': 'first',
15 + 'message.async.publish': 'first',
1416 'about.html.image': 'first',
1517 'feed.html.rollup': 'first',
1618 'sbot.pull.userFeed': 'first',
1719 'sbot.async.publish': 'first',
1820 'keys.sync.id': 'first',
21 + 'sheet.display': 'first',
1922 'contact.obs': {
2023 followers: 'first',
2124 following: 'first'
2225 }
@@ -65,24 +68,42 @@
6568 map(dictToCollection(names), (item) => {
6669 var isSelf = computed(item.value, (ids) => ids.includes(id))
6770 var isAssigned = computed(item.value, (ids) => ids.includes(yourId))
6871 return h('a.name', {
72 + 'ev-click': () => {
73 + if (!isAssigned()) {
74 + assignName(id, resolve(item.key))
75 + }
76 + },
77 + href: '#',
6978 classList: [
7079 when(isSelf, '-self'),
7180 when(isAssigned, '-assigned')
7281 ],
7382 title: nameList(when(isSelf, 'Self Assigned', 'Assigned By'), item.value)
7483 }, [
7584 item.key
7685 ])
77- })
86 + }),
87 + h('a -add', {
88 + 'ev-click': () => {
89 + rename(id)
90 + },
91 + href: '#',
92 + }, ['+'])
7893 ])
7994
8095 var imagePicker = h('div', {className: 'Picker'}, [
8196 map(dictToCollection(images), (item) => {
8297 var isSelf = computed(item.value, (ids) => ids.includes(id))
8398 var isAssigned = computed(item.value, (ids) => ids.includes(yourId))
8499 return h('a.name', {
100 + 'ev-click': () => {
101 + if (!isAssigned()) {
102 + assignImage(id, resolve(item.key))
103 + }
104 + },
105 + href: '#',
85106 classList: [
86107 when(isSelf, '-self'),
87108 when(isAssigned, '-assigned')
88109 ],
@@ -93,9 +114,17 @@
93114 style: { 'background-color': api.about.obs.color(id) },
94115 src: computed(item.key, api.blob.sync.url)
95116 })
96117 ])
97- })
118 + }),
119 + h('span.add', [
120 + api.blob.html.input(file => {
121 + assignImage(id, file.link)
122 + }, {
123 + accept: 'image/*',
124 + resize: { width: 500, height: 500 }
125 + })
126 + ])
98127 ])
99128
100129 var prepend = h('header', {className: 'ProfileHeader'}, [
101130 h('div.image', api.about.html.image(id)),
@@ -180,8 +209,71 @@
180209 following: false
181210 })
182211 }
183212
213 + function assignImage (id, image) {
214 + api.message.async.publish({
215 + type: 'about',
216 + about: id,
217 + image
218 + })
219 + }
220 +
221 + function assignName (id, name) {
222 + api.message.async.publish({
223 + type: 'about',
224 + about: id,
225 + name
226 + })
227 + }
228 +
229 + function rename (id) {
230 + api.sheet.display(close => {
231 + var currentName = api.about.obs.name(id)
232 + var input = h('input', {
233 + style: {'font-size': '150%'},
234 + value: currentName()
235 + })
236 + setTimeout(() => {
237 + input.focus()
238 + input.select()
239 + }, 5)
240 + return {
241 + content: h('div', {
242 + style: {
243 + padding: '20px',
244 + 'text-align': 'center'
245 + }
246 + }, [
247 + h('h2', {
248 + style: {
249 + 'font-weight': 'normal'
250 + }
251 + }, ['What whould you like to call ', h('strong', ['@', currentName]), '?']),
252 + input
253 + ]),
254 + footer: [
255 + h('button -save', {
256 + 'ev-click': () => {
257 + if (input.value.trim() && input.value !== currentName()) {
258 + // no confirm
259 + api.sbot.async.publish({
260 + type: 'about',
261 + about: id,
262 + name: input.value.trim()
263 + })
264 + }
265 + close()
266 + }
267 + }, 'Confirm'),
268 + h('button -cancel', {
269 + 'ev-click': close
270 + }, 'Cancel')
271 + ]
272 + }
273 + })
274 + }
275 +
184276 function nameList (prefix, ids) {
185277 var items = map(ids, api.about.obs.name)
186278 return computed([prefix, items], (prefix, names) => {
187279 return (prefix ? (prefix + '\n') : '') + names.map((n) => `- ${n}`).join('\n')
styles/picker.mcssView
@@ -5,9 +5,24 @@
55 background: #fff;
66 margin: 3px;
77 border: 1px solid #EEE;
88 color: #222;
9 + vertical-align: top;
910
11 + -add {
12 + padding: 0 5px
13 + font-size: 20px
14 + border-color: #DDD
15 + background: #EEE
16 + }
17 +
18 + :hover {
19 + border-color: #deb250;
20 + color: #deb250;
21 + background: #faf3e8;
22 + text-decoration: none
23 + }
24 +
1025 img {
1126 width: 50px
1227 height: 50px
1328 display: block
@@ -26,5 +41,38 @@
2641 color: #a8702a;
2742 font-weight: bold;
2843 }
2944 }
45 +
46 + span.add {
47 + position: relative
48 + display: inline-block;
49 + border: 1px solid #DDD
50 + background: #EEE
51 + margin: 3px;
52 + color: #222;
53 + vertical-align: top;
54 + :hover {
55 + border-color: #deb250;
56 + color: #deb250;
57 + background: #faf3e8;
58 + }
59 + ::before {
60 + font-size: 30px;
61 + content: '+';
62 + position: absolute;
63 + top: 13px;
64 + left: 0;
65 + right: 0;
66 + text-align: center;
67 + }
68 + input[type="file"] {
69 + height: 62px
70 + width: 62px
71 + display: block
72 + cursor: pointer
73 + opacity: 0
74 + }
75 + }
76 +
77 +
3078 }

Built with git-ssb-web