Commit dd1d12954ae9c549f848026f96a4d9320f69e9e2
simpler way to group posts to a channel
Dominic Tarr committed on 8/14/2017, 4:21:25 AMParent: 0752def91e23dd89d4a282c49488d79aaf7caa21
Files changed
app/page/home.js | changed |
app/page/home.js | ||
---|---|---|
@@ -71,41 +71,73 @@ | ||
71 | 71 | morePlease = false |
72 | 72 | }) |
73 | 73 | threadsObsDebounced.more = function () { |
74 | 74 | morePlease = true |
75 | - threadsObs.more() | |
75 | + requestIdleCallback(threadsObs.more) | |
76 | 76 | } |
77 | 77 | |
78 | 78 | var threadsHtmlObs = More( |
79 | 79 | threadsObsDebounced, |
80 | 80 | function render (threads) { |
81 | + | |
82 | + var groupedThreads = | |
83 | + roots(threads.private) | |
84 | + .concat(roots(threads.channels)) | |
85 | + .concat(roots(threads.groups)) | |
86 | + .sort(function (a, b) { | |
87 | + return latestUpdate(b) - latestUpdate(a) | |
88 | + }) | |
89 | + | |
90 | + function latestUpdate(thread) { | |
91 | + var m = thread.timestamp | |
92 | + if(!thread.replies) return m | |
93 | + | |
94 | + for(var i = 0; i < thread.replies.length; i++) | |
95 | + m = Math.max(thread.replies[i].timestamp, m) | |
96 | + return m | |
97 | + } | |
98 | + | |
99 | + function roots (r) { | |
100 | + return Object.keys(r || {}).map(function (k) { | |
101 | + return threads.roots[r[k]] | |
102 | + }).filter(function (e) { | |
103 | + return e && e.value | |
104 | + }) | |
105 | + } | |
106 | + | |
107 | + | |
81 | 108 | morphdom(container, |
82 | 109 | // LEGACY: some of these containers could be removed |
83 | 110 | // but they are here to be compatible with the old MCSS. |
84 | 111 | h('div.container', [ |
85 | 112 | //private section |
86 | 113 | h('section.updates -directMessage', [ |
87 | 114 | h('div.threads', |
88 | - Object.keys(threads.roots) | |
89 | - .map(function (id) { | |
90 | - return threads.roots[id] | |
91 | - }) | |
92 | - .filter(function (thread) { | |
93 | - return filter(location.filter, thread) | |
94 | - }) | |
115 | +// Object.keys(threads.roots) | |
116 | +// .map(function (id) { | |
117 | +// return threads.roots[id] | |
118 | +// }) | |
119 | +// .filter(function (thread) { | |
120 | +// return filter(location.filter, thread) | |
121 | +// }) | |
122 | + groupedThreads | |
95 | 123 | .map(function (thread) { |
96 | 124 | var el = api.app.html |
97 | 125 | .threadCard(thread, opts) |
98 | - if(!location.filter && el) | |
99 | - el.onclick = function () { | |
100 | - api.history.sync.push({page: 'home', filter: filterForThread(thread)}) | |
101 | - } | |
126 | +//DISABLE: rethinking pages | |
127 | +// if(!location.filter && el) | |
128 | +// el.onclick = function () { | |
129 | +// if(!filterForThread(thread)) | |
130 | +// api.history.sync.push({key: thread.key}) | |
131 | +// else | |
132 | +// api.history.sync.push({page: 'home', filter: filterForThread(thread)}) | |
133 | +// } | |
102 | 134 | return el |
103 | 135 | }) |
104 | 136 | ) |
105 | 137 | ]), |
106 | 138 | ]) |
107 | - ) | |
139 | + ) | |
108 | 140 | return container |
109 | 141 | } |
110 | 142 | ) |
111 | 143 | |
@@ -118,4 +150,13 @@ | ||
118 | 150 | }) |
119 | 151 | } |
120 | 152 | |
121 | 153 | |
154 | + | |
155 | + | |
156 | + | |
157 | + | |
158 | + | |
159 | + | |
160 | + | |
161 | + | |
162 | + |
Built with git-ssb-web