git ssb

10+

Matt McKegg / patchwork



Commit 35ca2d9446f15b90de0ece30391868c2761a1247

use patchcore thread for resolving blog body instead of doing it render

Matt McKegg committed on 4/10/2018, 9:22:22 AM
Parent: 6751afc5d0191f821b49e0ccfa83176f9218b282

Files changed

package.jsonchanged
plugs/message/html/render/blog.jschanged
package.jsonView
@@ -42,9 +42,9 @@
4242 "mutant": "^3.21.2",
4343 "mutant-pull-reduce": "^1.1.0",
4444 "obv": "0.0.1",
4545 "patch-settings": "~1.1.0",
46- "patchcore": "^1.23.6",
46+ "patchcore": "github:ssbc/patchcore#blogs",
4747 "pull-abortable": "^4.1.0",
4848 "pull-cat": "^1.1.11",
4949 "pull-defer": "^0.2.2",
5050 "pull-file": "~1.0.0",
plugs/message/html/render/blog.jsView
@@ -1,11 +1,14 @@
11 const nest = require('depnest')
2-const Blog = require('scuttle-blog')
32 const isBlog = require('scuttle-blog/isBlog')
43 const { h, Value, computed, when, resolve } = require('mutant')
54
6-exports.gives = nest('message.html.render')
75
6+exports.gives = nest('message.html', {
7+ canRender: true,
8+ render: true
9+})
10+
811 exports.needs = nest({
912 'about.obs.color': 'first',
1013 'app.navigate': 'first',
1114 'blob.sync.url': 'first',
@@ -15,23 +18,36 @@
1518 'sbot.obs.connection': 'first'
1619 })
1720
1821 exports.create = function (api) {
22+
23+ return nest('message.html', {
24+ render: blogRenderer,
25+ canRender
26+ })
27+
1928 return nest('message.html.render', blogRenderer)
2029
2130 function blogRenderer (msg, opts) {
22- if (!isBlog(msg)) return
31+ if (!canRender(msg)) return
2332
24- var blog = Blog(api.sbot.obs.connection).obs.get(msg)
25- var content = opts.renderAsCard
26- ? BlogCard({
27- blog,
33+ var content = null
34+
35+ // only render the message body if it is available (only in thread view), otherwise show card
36+ if (msg.body) {
37+ content = h('BlogFull.Markdown', [
38+ h('h1', msg.value.content.title),
39+ api.message.html.markdown(msg.body)
40+ ])
41+ } else {
42+ content = BlogCard({
43+ blog: msg.value.content,
2844 onClick: () => api.app.navigate(msg.key),
2945 color: api.about.obs.color,
3046 blobUrl: api.blob.sync.url
3147 })
32- : BlogFull(blog, api.message.html.markdown)
33-
48+ }
49+
3450 const element = api.message.html.layout(msg, Object.assign({}, {
3551 content,
3652 layout: 'default'
3753 }, opts))
@@ -39,25 +55,8 @@
3955 return api.message.html.decorate(element, { msg })
4056 }
4157 }
4258
43-function BlogFull (blog, renderMd) {
44- return computed(blog.body, body => {
45- if (body && body.length) {
46- return h('BlogFull.Markdown', [
47- h('h1', blog.title),
48- renderMd(body)
49- ])
50- }
51-
52- return h('BlogFull.Markdown', [
53- h('h1', blog.title),
54- blog.summary,
55- h('p', 'loading...')
56- ])
57- })
58-}
59-
6059 function BlogCard ({ blog, blobUrl, onClick, color }) {
6160 const thumbnail = when(blog.thumbnail,
6261 h('Thumbnail', {
6362 style: {
@@ -91,4 +90,8 @@
9190 ])
9291
9392 return b
9493 }
94+
95+function canRender (msg) {
96+ return msg.value && msg.value.content && msg.value.content.type === 'blog' && isBlog(msg)
97+}

Built with git-ssb-web