modules/page/html/render/profile.jsView |
---|
1 | 1 | var nest = require('depnest') |
2 | 2 | var ref = require('ssb-ref') |
3 | | -var {Value, h, when, computed, map, send} = require('mutant') |
| 3 | +var {Value, h, when, computed, map, send, dictToCollection} = require('mutant') |
4 | 4 | var extend = require('xtend') |
5 | 5 | |
6 | 6 | exports.needs = nest({ |
7 | | - 'about.obs.name': 'first', |
| 7 | + 'about.obs': { |
| 8 | + name: 'first', |
| 9 | + names: 'first', |
| 10 | + images: 'first', |
| 11 | + color: 'first' |
| 12 | + }, |
| 13 | + 'blob.sync.url': 'first', |
8 | 14 | 'about.html.image': 'first', |
9 | 15 | 'feed.html.rollup': 'first', |
10 | 16 | 'sbot.pull.userFeed': 'first', |
11 | 17 | 'sbot.async.publish': 'first', |
12 | 18 | 'keys.sync.id': 'first', |
13 | 19 | 'profile.obs': { |
14 | 20 | followers: 'first', |
15 | | - following: 'first' |
| 21 | + following: 'first', |
| 22 | + names: 'first' |
16 | 23 | } |
17 | 24 | }) |
18 | 25 | exports.gives = nest('page.html.render') |
19 | 26 | |
53 | 60 | var youFollow = computed([yourFollows], function (youFollow) { |
54 | 61 | return youFollow.has(id) |
55 | 62 | }) |
56 | 63 | |
| 64 | + var names = api.about.obs.names(id) |
| 65 | + var images = api.about.obs.images(id) |
| 66 | + |
| 67 | + var namePicker = h('div', {className: 'Picker'}, [ |
| 68 | + map(dictToCollection(names), (item) => { |
| 69 | + var isSelf = computed(item.value, (ids) => ids.includes(id)) |
| 70 | + var isAssigned = computed(item.value, (ids) => ids.includes(yourId)) |
| 71 | + return h('a.name', { |
| 72 | + classList: [ |
| 73 | + when(isSelf, '-self'), |
| 74 | + when(isAssigned, '-assigned') |
| 75 | + ], |
| 76 | + title: nameList(when(isSelf, 'Self Assigned', 'Assigned By'), item.value) |
| 77 | + }, [ |
| 78 | + item.key |
| 79 | + ]) |
| 80 | + }) |
| 81 | + ]) |
| 82 | + |
| 83 | + var imagePicker = h('div', {className: 'Picker'}, [ |
| 84 | + map(dictToCollection(images), (item) => { |
| 85 | + var isSelf = computed(item.value, (ids) => ids.includes(id)) |
| 86 | + var isAssigned = computed(item.value, (ids) => ids.includes(yourId)) |
| 87 | + return h('a.name', { |
| 88 | + classList: [ |
| 89 | + when(isSelf, '-self'), |
| 90 | + when(isAssigned, '-assigned') |
| 91 | + ], |
| 92 | + title: nameList(when(isSelf, 'Self Assigned', 'Assigned By'), item.value) |
| 93 | + }, [ |
| 94 | + h('img', { |
| 95 | + className: 'Avatar', |
| 96 | + style: { 'background-color': api.about.obs.color(id) }, |
| 97 | + src: computed(item.key, api.blob.sync.url) |
| 98 | + }) |
| 99 | + ]) |
| 100 | + }) |
| 101 | + ]) |
| 102 | + |
57 | 103 | var prepend = h('header', {className: 'ProfileHeader'}, [ |
58 | 104 | h('div.image', api.about.html.image(id)), |
59 | | - h('div.title', [ |
60 | | - h('h1', ['@', name]) |
61 | | - ]), |
62 | | - h('div.meta', [ |
63 | | - when(id === yourId, [ |
64 | | - h('a.-disabled', 'This is you!') |
65 | | - ], [ |
66 | | - when(youFollow, |
67 | | - h('a.ToggleButton.-unsubscribe', { |
68 | | - 'href': '#', |
69 | | - 'title': 'Click to unfollow', |
70 | | - 'ev-click': send(unfollow, id) |
71 | | - }, when(isFriends, 'Friends', 'Following')), |
72 | | - h('a.ToggleButton.-subscribe', { |
73 | | - 'href': '#', |
74 | | - 'ev-click': send(follow, id) |
75 | | - }, when(followsYou, 'Follow Back', 'Follow')) |
76 | | - ) |
77 | | - ]) |
78 | | - |
| 105 | + h('div.main', [ |
| 106 | + h('div.title', [ |
| 107 | + h('h1', ['@', name]), |
| 108 | + h('div.meta', [ |
| 109 | + when(id === yourId, [ |
| 110 | + h('a.-disabled', 'This is you!') |
| 111 | + ], [ |
| 112 | + when(youFollow, |
| 113 | + h('a.ToggleButton.-unsubscribe', { |
| 114 | + 'href': '#', |
| 115 | + 'title': 'Click to unfollow', |
| 116 | + 'ev-click': send(unfollow, id) |
| 117 | + }, when(isFriends, 'Friends', 'Following')), |
| 118 | + h('a.ToggleButton.-subscribe', { |
| 119 | + 'href': '#', |
| 120 | + 'ev-click': send(follow, id) |
| 121 | + }, when(followsYou, 'Follow Back', 'Follow')) |
| 122 | + ) |
| 123 | + ]) |
| 124 | + ]) |
| 125 | + ]), |
| 126 | + h('section', [ namePicker, imagePicker ]) |
79 | 127 | ]) |
80 | 128 | ]) |
81 | 129 | |
82 | 130 | return h('div', {className: 'SplitView'}, [ |
109 | 157 | href: id |
110 | 158 | }, [ |
111 | 159 | h('div.avatar', [api.about.html.image(id)]), |
112 | 160 | h('div.main', [ |
113 | | - h('div.name', [ api.about.obs.name(id) ]) |
| 161 | + h('div.name', [ '@', api.about.obs.name(id) ]) |
114 | 162 | ]) |
115 | 163 | ]) |
116 | 164 | }, { |
117 | 165 | idle: true |
134 | 182 | contact: id, |
135 | 183 | following: false |
136 | 184 | }) |
137 | 185 | } |
| 186 | + |
| 187 | + function nameList (prefix, ids) { |
| 188 | + var items = map(ids, api.about.obs.name) |
| 189 | + return computed([prefix, items], (prefix, names) => { |
| 190 | + return (prefix ? (prefix + '\n') : '') + names.map((n) => `- ${n}`).join('\n') |
| 191 | + }) |
| 192 | + } |
138 | 193 | } |