Commit 7f4a4d5b90c62d06c0bfcd39e29051e47d4f4fef
Add super-short bio summary to mouseover popup.
This addresses #780 (Mouseover of profiles should include some of the user bio) in a relatively hap-hazard way.Daan Wynen committed on 4/28/2020, 11:56:31 AM
Parent: e5dcb55e879c8b04584b7aa08bf803220ff08d42
Files changed
lib/depject/profile/html/preview.js | changed |
package-lock.json | changed |
package.json | changed |
lib/depject/profile/html/preview.js | ||
---|---|---|
@@ -3,11 +3,13 @@ | ||
3 | 3 … | const map = require('mutant/map') |
4 | 4 … | const when = require('mutant/when') |
5 | 5 … | const computed = require('mutant/computed') |
6 | 6 … | const send = require('mutant/send') |
7 … | +const removeMd = require('remove-markdown') | |
7 | 8 … | |
8 | 9 … | exports.needs = nest({ |
9 | 10 … | 'about.obs.name': 'first', |
11 … | + 'about.obs.description': 'first', | |
10 | 12 … | 'about.html.image': 'first', |
11 | 13 … | 'keys.sync.id': 'first', |
12 | 14 … | 'sheet.display': 'first', |
13 | 15 … | 'app.navigate': 'first', |
@@ -24,10 +26,12 @@ | ||
24 | 26 … | const i18n = api.intl.sync.i18n |
25 | 27 … | const plural = api.intl.sync.i18n_n |
26 | 28 … | |
27 | 29 … | return nest('profile.html.preview', function (id) { |
30 … | + const idLen = id.length | |
28 | 31 … | const name = api.about.obs.name(id) |
29 | 32 … | const contact = api.profile.obs.contact(id) |
33 … | + const description = api.about.obs.description(id) | |
30 | 34 … | |
31 | 35 … | return h('ProfilePreview', [ |
32 | 36 … | h('header', [ |
33 | 37 … | h('div.image', api.about.html.image(id)), |
@@ -41,9 +45,17 @@ | ||
41 | 45 … | ]) |
42 | 46 … | ]), |
43 | 47 … | h('section -publicKey', [ |
44 | 48 … | h('pre', { title: i18n('Public key for this profile') }, id) |
45 | - ]) | |
49 … | + ]), | |
50 … | + h( | |
51 … | + 'section -profile', [ | |
52 … | + computed(description, (description) => { | |
53 … | + const txt = removeMd(description) | |
54 … | + const summary = shortenDescription(txt, idLen) | |
55 … | + return summary | |
56 … | + })] | |
57 … | + ) | |
46 | 58 … | ]) |
47 | 59 … | ]), |
48 | 60 … | |
49 | 61 … | when(contact.isYou, h('section -you', [ |
@@ -94,8 +106,33 @@ | ||
94 | 106 … | ]) |
95 | 107 … | ]) |
96 | 108 … | }) |
97 | 109 … | |
110 … | + function shortenDescription (txt, len) { | |
111 … | + if (txt == null) { | |
112 … | + return '' | |
113 … | + } | |
114 … | + const line1 = txt.trim().split('\n', 1)[0] | |
115 … | + if (line1.length <= len) { | |
116 … | + return line1 | |
117 … | + } | |
118 … | + const words = line1.split(' ') | |
119 … | + let result = words.shift() | |
120 … | + if (result.length > len) { | |
121 … | + return result.splice(0, len - 1) + ' …' | |
122 … | + } | |
123 … | + for (let i = 0; i < len; i++) { | |
124 … | + const currentWord = words.shift() | |
125 … | + // + 1 for the joining space, and +2 for the final ellipsis | |
126 … | + if (result.length + 1 + currentWord.length + 2 <= len) { | |
127 … | + result += ` ${currentWord}` | |
128 … | + } else { | |
129 … | + break | |
130 … | + } | |
131 … | + } | |
132 … | + return result + ' …' | |
133 … | + } | |
134 … | + | |
98 | 135 … | function displayMutualFriends (profiles) { |
99 | 136 … | api.sheet.profiles(profiles, i18n('Mutual Friends')) |
100 | 137 … | } |
101 | 138 … |
package-lock.json | ||
---|---|---|
The diff is too large to show. Use a local git client to view these changes. Old file size: 370667 bytes New file size: 370913 bytes |
package.json | ||
---|---|---|
@@ -57,8 +57,9 @@ | ||
57 | 57 … | "pull-pause": "~0.0.2", |
58 | 58 … | "pull-pushable": "^2.2.0", |
59 | 59 … | "pull-reconnect": "0.0.3", |
60 | 60 … | "pull-stream": "^3.6.14", |
61 … | + "remove-markdown": "^0.3.0", | |
61 | 62 … | "require-style": "^1.1.0", |
62 | 63 … | "run-parallel": "^1.1.9", |
63 | 64 … | "scuttle-blog": "^1.0.1", |
64 | 65 … | "scuttle-tag": "^0.4.0", |
Built with git-ssb-web