Commit 5a9fd871c7f581b104a466ff3ce3d199b38541f5
threadCard: tweak subject for leading mentions, modify morphdom id
mix irving committed on 8/17/2017, 12:00:06 AMParent: f61a6365dcfa4962dd501e41f3afb98a390c9947
Files changed
app/html/thread-card.js | changed |
app/html/thread-card.js | ||
---|---|---|
@@ -20,19 +20,20 @@ | ||
20 | 20 | //get the first non-empty line |
21 | 21 | var line = text.trim().split('\n').shift().trim() |
22 | 22 | |
23 | 23 | //always break on a space, so that links are preserved. |
24 | - var i = line.indexOf(' ', 80) | |
24 | + const leadingMentionsLength = countLeadingMentions(line) | |
25 | + const i = line.indexOf(' ', leadingMentionsLength + 80) | |
25 | 26 | var sample = line.substring(0, ~i ? i : line.length) |
26 | 27 | |
27 | 28 | const ellipsis = (sample.length < line.length) ? '...' : '' |
28 | 29 | return sample + ellipsis |
29 | 30 | } |
30 | 31 | |
31 | -// function trimLeadingMentions (str) { | |
32 | -// return str.replace(/^(\s*\[@[^\)]+\)\s*)*/, '') | |
33 | -// // deletes any number of pattern " [@...) " from start of line | |
34 | -// } | |
32 | +function countLeadingMentions (str) { | |
33 | + return str.match(/^(\s*\[@[^\)]+\)\s*)*/)[0].length | |
34 | + // matches any number of pattern " [@...) " from start of line | |
35 | +} | |
35 | 36 | |
36 | 37 | exports.create = function (api) { |
37 | 38 | |
38 | 39 | //render the icon for a thread. |
@@ -85,9 +86,9 @@ | ||
85 | 86 | const lastReply = thread.replies && maxBy(thread.replies, r => r.timestamp) |
86 | 87 | const replySample = lastReply ? subject(lastReply) : null |
87 | 88 | |
88 | 89 | const onClick = opts.onClick || function () { api.history.sync.push(thread) } |
89 | - const id = `${thread.key}-${JSON.stringify(opts)}` | |
90 | + const id = `${thread.key.replace(/[^a-z0-9]/gi, '')}` //-${JSON.stringify(opts)}` | |
90 | 91 | // id is only here to help morphdom morph accurately |
91 | 92 | |
92 | 93 | return h('ThreadCard', { 'ev-click': onClick, id }, [ |
93 | 94 | h('div.context', threadIcon(thread)), |
Built with git-ssb-web