mirror of
https://github.com/discourse/discourse.git
synced 2025-05-24 14:12:10 +08:00
UX: Timeline lookup on mega topics should use date of current post.
This commit is contained in:
@ -716,8 +716,9 @@ export default RestModel.extend({
|
|||||||
closestDaysAgoFor(postNumber) {
|
closestDaysAgoFor(postNumber) {
|
||||||
const timelineLookup = this.get("timelineLookup") || [];
|
const timelineLookup = this.get("timelineLookup") || [];
|
||||||
|
|
||||||
let low = 0,
|
let low = 0;
|
||||||
high = timelineLookup.length - 1;
|
let high = timelineLookup.length - 1;
|
||||||
|
|
||||||
while (low <= high) {
|
while (low <= high) {
|
||||||
const mid = Math.floor(low + (high - low) / 2);
|
const mid = Math.floor(low + (high - low) / 2);
|
||||||
const midValue = timelineLookup[mid][0];
|
const midValue = timelineLookup[mid][0];
|
||||||
@ -732,9 +733,7 @@ export default RestModel.extend({
|
|||||||
}
|
}
|
||||||
|
|
||||||
const val = timelineLookup[high] || timelineLookup[low];
|
const val = timelineLookup[high] || timelineLookup[low];
|
||||||
if (val) {
|
if (val) return val[1];
|
||||||
return val[1];
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
// Find a postId for a postNumber, respecting gaps
|
// Find a postId for a postNumber, respecting gaps
|
||||||
|
@ -153,7 +153,13 @@ createWidget("timeline-scrollarea", {
|
|||||||
const daysAgo = postStream.closestDaysAgoFor(current);
|
const daysAgo = postStream.closestDaysAgoFor(current);
|
||||||
let date;
|
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 = new Date();
|
||||||
date.setDate(date.getDate() - daysAgo || 0);
|
date.setDate(date.getDate() - daysAgo || 0);
|
||||||
} else {
|
} else {
|
||||||
|
@ -151,6 +151,9 @@ QUnit.test("closestDaysAgoFor", assert => {
|
|||||||
assert.equal(postStream.closestDaysAgoFor(-1), 10);
|
assert.equal(postStream.closestDaysAgoFor(-1), 10);
|
||||||
assert.equal(postStream.closestDaysAgoFor(0), 10);
|
assert.equal(postStream.closestDaysAgoFor(0), 10);
|
||||||
assert.equal(postStream.closestDaysAgoFor(10), 1);
|
assert.equal(postStream.closestDaysAgoFor(10), 1);
|
||||||
|
|
||||||
|
postStream.set("timelineLookup", []);
|
||||||
|
assert.equal(postStream.closestDaysAgoFor(1), undefined);
|
||||||
});
|
});
|
||||||
|
|
||||||
QUnit.test("closestDaysAgoFor - empty", assert => {
|
QUnit.test("closestDaysAgoFor - empty", assert => {
|
||||||
|
Reference in New Issue
Block a user