git ssb

0+

alanz / patchwork



forked from Matt McKegg / patchwork

Commit b4f7e1f1954f0a78cb2756b3c39fe7d58881dc43

open sheet displaying list of likes when "liked by" clicked

Matt McKegg committed on 4/23/2017, 11:39:15 PM
Parent: 45a926949dc7ae72b90ae8fcc4bd39a796355669

Files changed

main-window.jschanged
modules/message/sheet/likes.jsadded
plugs/message/html/meta/likes.jschanged
styles/message.mcsschanged
main-window.jsView
@@ -15,8 +15,9 @@
1515
1616 module.exports = function (config) {
1717 var sockets = combine(
1818 overrideConfig(config),
19+ addCommand('app.navigate', setView),
1920 require('./modules'),
2021 require('./plugs'),
2122 require('patchcore'),
2223 require('./overrides')
@@ -31,9 +32,10 @@
3132 'app.html.search': 'first',
3233 'app.views': 'first',
3334 'app.sync.externalHandler': 'first',
3435 'app.html.progressNotifier': 'first',
35- 'profile.sheet.edit': 'first'
36+ 'profile.sheet.edit': 'first',
37+ 'app.navigate': 'first'
3638 }))
3739
3840 var id = api.keys.sync.id()
3941 var latestUpdate = LatestUpdate()
@@ -69,9 +71,9 @@
6971 tab('Public', '/public'),
7072 tab('Private', '/private')
7173 ]),
7274 h('span.appTitle', ['Patchwork']),
73- h('span', [ api.app.html.search(views.setView) ]),
75+ h('span', [ api.app.html.search(api.app.navigate) ]),
7476 h('span.nav', [
7577 tab('Profile', id),
7678 tab('Mentions', '/mentions')
7779 ])
@@ -97,20 +99,24 @@
9799 if (err) throw err
98100 if (handler) {
99101 handler(href)
100102 } else {
101- views.setView(href)
103+ api.app.navigate(href)
102104 }
103105 })
104106 } else {
105- views.setView(href)
107+ api.app.navigate(href)
106108 }
107109 })
108110
109111 return container
110112
111113 // scoped
112114
115+ function setView (href) {
116+ views.setView(href)
117+ }
118+
113119 function getExternalHandler (key, cb) {
114120 api.sbot.async.get(key, function (err, value) {
115121 if (err) return cb(err)
116122 cb(null, api.app.sync.externalHandler({key, value}))
@@ -144,11 +150,24 @@
144150 }
145151 }
146152
147153 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+ }
152160 }
153- }]
161+ }
154162 }
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.jsView
@@ -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.jsView
@@ -1,9 +1,10 @@
11 var nest = require('depnest')
2-var { h, computed, map } = require('mutant')
2+var { h, computed, map, send } = require('mutant')
33 exports.gives = nest('message.html.meta')
44 exports.needs = nest({
55 'message.obs.likes': 'first',
6+ 'message.sheet.likes': 'first',
67 'about.obs.name': 'first'
78 })
89
910 exports.create = function (api) {
@@ -14,10 +15,12 @@
1415 })
1516
1617 function likeCount (likes) {
1718 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)
2023 }, [`${likes.length} ${likes.length === 1 ? 'like' : 'likes'}`])]
2124 }
2225 }
2326
styles/message.mcssView
@@ -35,9 +35,9 @@
3535 -mini {
3636 header {
3737 margin-bottom: 15px
3838 div.meta {
39- span.likes {
39+ a.likes {
4040 margin-top: -5px
4141 }
4242 a {
4343 display: inline-block
@@ -138,9 +138,9 @@
138138 a.channel {
139139 font-weight: bold;
140140 }
141141
142- span.likes {
142+ a.likes {
143143 color: #286bc3;
144144 font-size:90%;
145145 }
146146

Built with git-ssb-web