UX: Timeline lookup on mega topics should use date of current post.
This commit is contained in:
parent
b4e1388f9b
commit
8f4cb1a742
|
@ -716,8 +716,9 @@ export default RestModel.extend({
|
|||
closestDaysAgoFor(postNumber) {
|
||||
const timelineLookup = this.get("timelineLookup") || [];
|
||||
|
||||
let low = 0,
|
||||
high = timelineLookup.length - 1;
|
||||
let low = 0;
|
||||
let high = timelineLookup.length - 1;
|
||||
|
||||
while (low <= high) {
|
||||
const mid = Math.floor(low + (high - low) / 2);
|
||||
const midValue = timelineLookup[mid][0];
|
||||
|
@ -732,9 +733,7 @@ export default RestModel.extend({
|
|||
}
|
||||
|
||||
const val = timelineLookup[high] || timelineLookup[low];
|
||||
if (val) {
|
||||
return val[1];
|
||||
}
|
||||
if (val) return val[1];
|
||||
},
|
||||
|
||||
// Find a postId for a postNumber, respecting gaps
|
||||
|
|
|
@ -153,7 +153,13 @@ createWidget("timeline-scrollarea", {
|
|||
const daysAgo = postStream.closestDaysAgoFor(current);
|
||||
let date;
|
||||
|
||||
if (daysAgo !== null) {
|
||||
if (daysAgo === undefined) {
|
||||
const post = postStream
|
||||
.get("posts")
|
||||
.findBy("id", postStream.get("stream")[current]);
|
||||
|
||||
if (post) date = new Date(post.get("created_at"));
|
||||
} else if (daysAgo !== null) {
|
||||
date = new Date();
|
||||
date.setDate(date.getDate() - daysAgo || 0);
|
||||
} else {
|
||||
|
|
|
@ -151,6 +151,9 @@ QUnit.test("closestDaysAgoFor", assert => {
|
|||
assert.equal(postStream.closestDaysAgoFor(-1), 10);
|
||||
assert.equal(postStream.closestDaysAgoFor(0), 10);
|
||||
assert.equal(postStream.closestDaysAgoFor(10), 1);
|
||||
|
||||
postStream.set("timelineLookup", []);
|
||||
assert.equal(postStream.closestDaysAgoFor(1), undefined);
|
||||
});
|
||||
|
||||
QUnit.test("closestDaysAgoFor - empty", assert => {
|
||||
|
|
Loading…
Reference in New Issue