Commit b4f7e1f1954f0a78cb2756b3c39fe7d58881dc43
open sheet displaying list of likes when "liked by" clicked
Matt McKegg committed on 4/23/2017, 11:39:15 PMParent: 45a926949dc7ae72b90ae8fcc4bd39a796355669
Files changed
main-window.js | changed |
modules/message/sheet/likes.js | added |
plugs/message/html/meta/likes.js | changed |
styles/message.mcss | changed |
main-window.js | ||
---|---|---|
@@ -15,8 +15,9 @@ | ||
15 | 15 | |
16 | 16 | module.exports = function (config) { |
17 | 17 | var sockets = combine( |
18 | 18 | overrideConfig(config), |
19 | + addCommand('app.navigate', setView), | |
19 | 20 | require('./modules'), |
20 | 21 | require('./plugs'), |
21 | 22 | require('patchcore'), |
22 | 23 | require('./overrides') |
@@ -31,9 +32,10 @@ | ||
31 | 32 | 'app.html.search': 'first', |
32 | 33 | 'app.views': 'first', |
33 | 34 | 'app.sync.externalHandler': 'first', |
34 | 35 | 'app.html.progressNotifier': 'first', |
35 | - 'profile.sheet.edit': 'first' | |
36 | + 'profile.sheet.edit': 'first', | |
37 | + 'app.navigate': 'first' | |
36 | 38 | })) |
37 | 39 | |
38 | 40 | var id = api.keys.sync.id() |
39 | 41 | var latestUpdate = LatestUpdate() |
@@ -69,9 +71,9 @@ | ||
69 | 71 | tab('Public', '/public'), |
70 | 72 | tab('Private', '/private') |
71 | 73 | ]), |
72 | 74 | h('span.appTitle', ['Patchwork']), |
73 | - h('span', [ api.app.html.search(views.setView) ]), | |
75 | + h('span', [ api.app.html.search(api.app.navigate) ]), | |
74 | 76 | h('span.nav', [ |
75 | 77 | tab('Profile', id), |
76 | 78 | tab('Mentions', '/mentions') |
77 | 79 | ]) |
@@ -97,20 +99,24 @@ | ||
97 | 99 | if (err) throw err |
98 | 100 | if (handler) { |
99 | 101 | handler(href) |
100 | 102 | } else { |
101 | - views.setView(href) | |
103 | + api.app.navigate(href) | |
102 | 104 | } |
103 | 105 | }) |
104 | 106 | } else { |
105 | - views.setView(href) | |
107 | + api.app.navigate(href) | |
106 | 108 | } |
107 | 109 | }) |
108 | 110 | |
109 | 111 | return container |
110 | 112 | |
111 | 113 | // scoped |
112 | 114 | |
115 | + function setView (href) { | |
116 | + views.setView(href) | |
117 | + } | |
118 | + | |
113 | 119 | function getExternalHandler (key, cb) { |
114 | 120 | api.sbot.async.get(key, function (err, value) { |
115 | 121 | if (err) return cb(err) |
116 | 122 | cb(null, api.app.sync.externalHandler({key, value})) |
@@ -144,11 +150,24 @@ | ||
144 | 150 | } |
145 | 151 | } |
146 | 152 | |
147 | 153 | function overrideConfig (config) { |
148 | - return [{ | |
149 | - gives: nest('config.sync.load'), | |
150 | - create: function (api) { | |
151 | - return nest('config.sync.load', () => config) | |
154 | + return { | |
155 | + 'patchwork/config': { | |
156 | + gives: nest('config.sync.load'), | |
157 | + create: function (api) { | |
158 | + return nest('config.sync.load', () => config) | |
159 | + } | |
152 | 160 | } |
153 | - }] | |
161 | + } | |
154 | 162 | } |
163 | + | |
164 | +function addCommand (id, cb) { | |
165 | + return { | |
166 | + [`patchwork/command/${id}`]: { | |
167 | + gives: nest(id), | |
168 | + create: function (api) { | |
169 | + return nest(id, cb) | |
170 | + } | |
171 | + } | |
172 | + } | |
173 | +} |
modules/message/sheet/likes.js | ||
---|---|---|
@@ -1,0 +1,72 @@ | ||
1 | +var {h, when, map, computed} = require('mutant') | |
2 | +var nest = require('depnest') | |
3 | +var catchLinks = require('../../../lib/catch-links') | |
4 | + | |
5 | +exports.needs = nest({ | |
6 | + 'sheet.display': 'first', | |
7 | + 'keys.sync.id': 'first', | |
8 | + 'contact.obs.following': 'first', | |
9 | + 'profile.obs.rank': 'first', | |
10 | + 'about.html.image': 'first', | |
11 | + 'about.obs.name': 'first', | |
12 | + 'app.navigate': 'first' | |
13 | +}) | |
14 | + | |
15 | +exports.gives = nest('message.sheet.likes') | |
16 | + | |
17 | +exports.create = function (api) { | |
18 | + return nest('message.sheet.likes', function (ids) { | |
19 | + api.sheet.display(close => { | |
20 | + var content = h('div', { | |
21 | + style: { padding: '20px' } | |
22 | + }, [ | |
23 | + h('h2', { | |
24 | + style: { 'font-weight': 'normal' } | |
25 | + }, ['Liked by']), | |
26 | + renderContactBlock(ids) | |
27 | + ]) | |
28 | + | |
29 | + catchLinks(content, (href, external) => { | |
30 | + if (!external) { | |
31 | + api.app.navigate(href) | |
32 | + close() | |
33 | + } | |
34 | + }) | |
35 | + | |
36 | + return { | |
37 | + content, | |
38 | + footer: [ | |
39 | + h('button -close', { | |
40 | + 'ev-click': close | |
41 | + }, 'Close') | |
42 | + ] | |
43 | + } | |
44 | + }) | |
45 | + }) | |
46 | + | |
47 | + function renderContactBlock (profiles) { | |
48 | + var yourId = api.keys.sync.id() | |
49 | + var yourFollows = api.contact.obs.following(yourId) | |
50 | + profiles = api.profile.obs.rank(profiles) | |
51 | + return [ | |
52 | + h('div', { | |
53 | + classList: 'ProfileList' | |
54 | + }, [ | |
55 | + map(profiles, (id) => { | |
56 | + var following = computed(yourFollows, f => f.has(id)) | |
57 | + return h('a.profile', { | |
58 | + href: id, | |
59 | + classList: [ | |
60 | + when(following, '-following') | |
61 | + ] | |
62 | + }, [ | |
63 | + h('div.avatar', [api.about.html.image(id)]), | |
64 | + h('div.main', [ | |
65 | + h('div.name', [ api.about.obs.name(id) ]) | |
66 | + ]) | |
67 | + ]) | |
68 | + }, { idle: true }) | |
69 | + ]) | |
70 | + ] | |
71 | + } | |
72 | +} |
plugs/message/html/meta/likes.js | ||
---|---|---|
@@ -1,9 +1,10 @@ | ||
1 | 1 | var nest = require('depnest') |
2 | -var { h, computed, map } = require('mutant') | |
2 | +var { h, computed, map, send } = require('mutant') | |
3 | 3 | exports.gives = nest('message.html.meta') |
4 | 4 | exports.needs = nest({ |
5 | 5 | 'message.obs.likes': 'first', |
6 | + 'message.sheet.likes': 'first', | |
6 | 7 | 'about.obs.name': 'first' |
7 | 8 | }) |
8 | 9 | |
9 | 10 | exports.create = function (api) { |
@@ -14,10 +15,12 @@ | ||
14 | 15 | }) |
15 | 16 | |
16 | 17 | function likeCount (likes) { |
17 | 18 | if (likes.length) { |
18 | - return [' ', h('span.likes', { | |
19 | - title: names(likes) | |
19 | + return [' ', h('a.likes', { | |
20 | + title: names(likes), | |
21 | + href: '#', | |
22 | + 'ev-click': send(api.message.sheet.likes, likes) | |
20 | 23 | }, [`${likes.length} ${likes.length === 1 ? 'like' : 'likes'}`])] |
21 | 24 | } |
22 | 25 | } |
23 | 26 |
styles/message.mcss | ||
---|---|---|
@@ -35,9 +35,9 @@ | ||
35 | 35 | -mini { |
36 | 36 | header { |
37 | 37 | margin-bottom: 15px |
38 | 38 | div.meta { |
39 | - span.likes { | |
39 | + a.likes { | |
40 | 40 | margin-top: -5px |
41 | 41 | } |
42 | 42 | a { |
43 | 43 | display: inline-block |
@@ -138,9 +138,9 @@ | ||
138 | 138 | a.channel { |
139 | 139 | font-weight: bold; |
140 | 140 | } |
141 | 141 | |
142 | - span.likes { | |
142 | + a.likes { | |
143 | 143 | color: #286bc3; |
144 | 144 | font-size:90%; |
145 | 145 | } |
146 | 146 |
Built with git-ssb-web