Commit 26eb63b836af90470db4e83dd22d952a85c08061
only load threads once, and use the correct branch for them
Dominic Tarr committed on 12/8/2017, 6:49:09 AMParent: b02d5837685a7fb8e42751b875db010b8ec801c6
Files changed
app/html/comments.js | changed |
app/html/thread.js | changed |
app/page/blogShow.js | changed |
app/page/threadShow.js | changed |
app/html/comments.js | ||
---|---|---|
@@ -19,10 +19,10 @@ | ||
19 | 19 | |
20 | 20 | exports.create = (api) => { |
21 | 21 | return nest('app.html.comments', comments) |
22 | 22 | |
23 | - function comments (root) { | |
24 | - const { messages, channel, lastId: branch } = api.feed.obs.thread(root) | |
23 | + function comments (thread) { | |
24 | + const { messages, channel, lastId: branch } = thread | |
25 | 25 | |
26 | 26 | // TODO - move this up into Patchcore |
27 | 27 | var debouncer = null |
28 | 28 | const messagesTree = computed(throttle(messages, 200), msgs => { |
app/html/thread.js | ||
---|---|---|
@@ -15,13 +15,12 @@ | ||
15 | 15 | 'unread.sync.isUnread': 'first' |
16 | 16 | }) |
17 | 17 | |
18 | 18 | exports.create = (api) => { |
19 | - return nest('app.html.thread', thread) | |
20 | - | |
21 | - function thread (root) { | |
19 | + return nest('app.html.thread', function (thread) { | |
20 | + //catch any code that still uses this the old way... | |
21 | + if('string' === typeof thread) throw new Error('thread should be observable') | |
22 | 22 | const myId = api.keys.sync.id() |
23 | - const thread = api.feed.obs.thread(root) | |
24 | 23 | const chunkedMessages = buildChunkedMessages(thread.messages) |
25 | 24 | |
26 | 25 | const threadView = h('Thread', |
27 | 26 | map(chunkedMessages, chunk => { |
@@ -61,9 +60,9 @@ | ||
61 | 60 | threadView.subject = computed(thread.messages, msgs => { |
62 | 61 | return get(msgs, '[0].value.content.subject') |
63 | 62 | }) |
64 | 63 | return threadView |
65 | - } | |
64 | + }) | |
66 | 65 | } |
67 | 66 | |
68 | 67 | function buildChunkedMessages (messagesObs) { |
69 | 68 | return computed(throttle(messagesObs, 200), msgs => { |
@@ -100,4 +99,7 @@ | ||
100 | 99 | // TODO (mix) use lodash/get |
101 | 100 | return msgA.value.author === msgB.value.author |
102 | 101 | } |
103 | 102 | |
103 | + | |
104 | + | |
105 | + |
app/page/blogShow.js | ||
---|---|---|
@@ -34,14 +34,12 @@ | ||
34 | 34 | |
35 | 35 | const blog = api.blog.html.content(blogMsg) |
36 | 36 | const title = api.blog.html.title(blogMsg) |
37 | 37 | |
38 | - //app.html.comments also loads the thread obs. | |
39 | - const comments = api.app.html.comments(blogMsg.key) | |
38 | + const thread = api.feed.obs.thread(blogMsg.key) | |
39 | + const comments = api.app.html.comments(thread) | |
40 | + const branch = thread.lastId | |
40 | 41 | |
41 | - //loads entire thread, just to get the branch. | |
42 | - const { lastId: branch } = api.feed.obs.thread(blogMsg.key) | |
43 | - | |
44 | 42 | const { timeago, channel, markdown, compose } = api.message.html |
45 | 43 | |
46 | 44 | return h('Page -blogShow', [ |
47 | 45 | api.app.html.context({ page: 'discover' }), // HACK to highlight discover |
@@ -74,4 +72,7 @@ | ||
74 | 72 | } |
75 | 73 | } |
76 | 74 | |
77 | 75 | |
76 | + | |
77 | + | |
78 | + |
app/page/threadShow.js | ||
---|---|---|
@@ -8,9 +8,10 @@ | ||
8 | 8 | exports.needs = nest({ |
9 | 9 | 'app.html.context': 'first', |
10 | 10 | 'app.html.thread': 'first', |
11 | 11 | 'message.html.compose': 'first', |
12 | - 'unread.sync.markRead': 'first' | |
12 | + 'unread.sync.markRead': 'first', | |
13 | + 'feed.obs.thread': 'first' | |
13 | 14 | }) |
14 | 15 | |
15 | 16 | exports.create = (api) => { |
16 | 17 | return nest('app.page.threadShow', threadShow) |
@@ -21,16 +22,14 @@ | ||
21 | 22 | const root = get(value, 'content.root', key) |
22 | 23 | const channel = get(value, 'content.channel') |
23 | 24 | |
24 | 25 | //unread state is set in here... |
25 | - const thread = api.app.html.thread(root) | |
26 | + const thread = api.feed.obs.thread(root) | |
26 | 27 | |
27 | 28 | const meta = { |
28 | 29 | type: 'post', |
29 | 30 | root, |
30 | - //XXX incorrect branch | |
31 | - branch: get(last(location.replies), 'key'), | |
32 | - // >> lastId? CHECK THIS LOGIC | |
31 | + branch: thread.lastId, | |
33 | 32 | channel, |
34 | 33 | recps: get(location, 'value.content.recps') |
35 | 34 | } |
36 | 35 | const composer = api.message.html.compose({ meta, shrink: false }) |
@@ -38,9 +37,9 @@ | ||
38 | 37 | return h('Page -threadShow', [ |
39 | 38 | api.app.html.context(location), |
40 | 39 | h('div.content', [ |
41 | 40 | when(thread.subject, h('h1', thread.subject)), |
42 | - thread, | |
41 | + api.app.html.thread(thread), | |
43 | 42 | composer |
44 | 43 | ]), |
45 | 44 | ]) |
46 | 45 | } |
@@ -50,4 +49,8 @@ | ||
50 | 49 | |
51 | 50 | |
52 | 51 | |
53 | 52 | |
53 | + | |
54 | + | |
55 | + | |
56 | + |
Built with git-ssb-web