git ssb

2+

mixmix / ticktack



Commit 626eee95a35f216215f604c646c666097ef64c50

thread-card renders blobs (roughly like the mockups)

Dominic Tarr committed on 9/28/2017, 7:31:58 AM
Parent: d9b28f22d6e79e5f61bb2429560dc5d45d8d3756

Files changed

app/html/thread-card.jschanged
app/html/thread-card.mcsschanged
app/html/thread-card.jsView
@@ -1,23 +1,57 @@
11 var nest = require('depnest')
22 var h = require('mutant/h')
33 var isString= require('lodash/isString')
44 var maxBy= require('lodash/maxBy')
5+var humanTime = require('human-time')
6+var marksum = require('markdown-summary')
7+var markdown = require('ssb-markdown')
8+var ref = require('ssb-ref')
9+var htmlEscape = require('html-escape')
510
11+function renderEmoji (emoji, url) {
12+ if (!url) return ':' + emoji + ':'
13+ return `
14+ <img
15+ src="${htmlEscape(url)}"
16+ alt=":${htmlEscape(emoji)}:"
17+ title=":${htmlEscape(emoji)}:"
18+ class="emoji"
19+ >
20+ `
21+}
22+
623 exports.gives = nest('app.html.threadCard', true)
724
825 exports.needs = nest({
926 'keys.sync.id': 'first',
1027 'history.sync.push': 'first',
1128 'about.obs.name': 'first',
1229 'about.html.avatar': 'first',
13- 'message.html.subject': 'first',
1430 'translations.sync.strings': 'first',
15- 'unread.sync.isUnread': 'first'
31+ 'unread.sync.isUnread': 'first',
32+ 'message.html.markdown': 'first',
33+ 'blob.sync.url': 'first',
34+ 'emoji.sync.url': 'first'
1635 })
1736
1837 exports.create = function (api) {
1938
39+ //render markdown, but don't support patchwork@2 style mentions or custom emoji right now.
40+ function render (source) {
41+ return markdown.block(source, {
42+ emoji: (emoji) => {
43+ return renderEmoji(emoji, api.emoji.sync.url(emoji))
44+ },
45+ toUrl: (id) => {
46+ if (ref.isBlob(id)) return api.blob.sync.url(id)
47+ return id
48+ },
49+ imageLink: (id) => id
50+ })
51+ }
52+
53+
2054 //render the icon for a thread.
2155 //it would be more depjecty to split this
2256 //into two methods, one in a private plugin
2357 //one in a channel plugin
@@ -51,34 +85,82 @@
5185
5286 if(!thread.value) return
5387 if(!thread.value.content.text) return
5488
55- const subjectEl = h('div.subject', [
56- opts.nameRecipients
57- ? h('div.recps', buildRecipientNames(thread).map(recp => h('div.recp', recp)))
58- : null,
59- subject(thread)
60- ])
89+// const subjectEl = h('div.subject', [
90+// opts.nameRecipients
91+// ? h('div.recps', buildRecipientNames(thread).map(recp => h('div.recp', recp)))
92+// : null,
93+// subject(thread)
94+// ])
6195
6296 const lastReply = thread.replies && maxBy(thread.replies, r => r.timestamp)
63- const replySample = lastReply ? subject(lastReply) : null
97+// const replySample = lastReply ? subject(lastReply) : null
6498
6599 const onClick = opts.onClick || function () { api.history.sync.push(thread) }
66100 const id = `${thread.key.replace(/[^a-z0-9]/gi, '')}` //-${JSON.stringify(opts)}`
67101 // id is only here to help morphdom morph accurately
68102
103+ var img = marksum.image(thread.value.content.text)
104+ var m = /\!\[[^]+\]\(([^\)]+)\)/.exec(img)
105+ console.log(m, img)
106+ if(m) {
107+ //hey this works! fit an image into a specific size (see thread-card.mcss)
108+ //centered, and scaled to fit the square (works with both landscape and portrait!)
109+ img = h('Thumbnail')
110+ img.style = 'background-image: url("'+api.blob.sync.url(m[1])+'"); background-position:center; background-size: cover;'
111+ }
112+ else img = ''
113+ var title = render(marksum.title(thread.value.content.text))
114+ var summary = render(marksum.summary(thread.value.content.text))
115+
69116 var className = thread.unread ? '-unread': ''
70-
71117 return h('ThreadCard', { id, className }, [
72- h('div.context', threadIcon(thread)),
118+ h('div.context', [
119+ api.about.html.avatar(thread.value.author),
120+ ' ',
121+ api.about.obs.name(thread.value.author),
122+ ' ',
123+ humanTime(new Date(thread.value.timestamp)),
124+ ' ',
125+ thread.value.content.channel ? '#'+thread.value.content.channel : null
126+ ]),
73127 h('div.content', {'ev-click': onClick}, [
74- subjectEl,
75- replySample ? h('div.reply', [
76- h('i.fa.fa-caret-left'),
77- replySample
78- ]) : null
128+ img,
129+ h('Text', [
130+ h('h2', {innerHTML: title}),
131+ h('Summary', {innerHTML: summary})
132+ ])
79133 ])
80134 ])
81135 })
82136 }
83137
84138
139+
140+
141+
142+
143+
144+
145+
146+
147+
148+
149+
150+
151+
152+
153+
154+
155+
156+
157+
158+
159+
160+
161+
162+
163+
164+
165+
166+
app/html/thread-card.mcssView
@@ -1,8 +1,8 @@
11 ThreadCard {
22 display: flex
3- align-items: center
4-
3+// align-items: center
4+ flex-direction: column
55 margin-bottom: .5rem
66
77 div.context {
88 display: flex
@@ -10,8 +10,10 @@
1010 font-weight: inherit
1111 }
1212
1313 div.content {
14+ display: flex
15+ flex-direction: row
1416 flex-grow: 1
1517
1618 cursor: pointer
1719 padding: 1rem
@@ -23,8 +25,11 @@
2325 :hover {
2426 background-color: #fff
2527 border: 1px solid #fff
2628 }
29+ div.text {
30+ flow-direction: column
31+ }
2732
2833 div.subject {
2934 font-size: 1.2rem
3035 margin-bottom: .3rem
@@ -56,8 +61,11 @@
5661 }
5762 }
5863 }
5964
60-
61-
62-
63-
65+Thumbnail {
66+ border-radius: 5px
67+ min-width: 100px
68+ min-height: 100px
69+ width: 100px
70+ height: 100px
71+}

Built with git-ssb-web