FIX: Latest post created_at on topic-timeline not updating (#20665)

# Context
https://meta.discourse.org/t/timeline-timestamp-not-updating/256447/1

During the upgrade of the topic-timeline to glimmer the "latest post" timestamp was not updating on the timeline in relation to the relative age of the post. It was only updating on a hard refresh.

# Fix
Use the `age-with-tooltip` helper to update the created_at date automatically as time passes.

# Additional
Add the ability to pass params to `age-with-tooltip` so that we can include options like `addAgo` and `defaultFormat`
This commit is contained in:
Isaac Janzen 2023-03-14 11:08:23 -05:00 committed by GitHub
parent 22a7818399
commit dfd6d6b999
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 20 deletions

View File

@ -105,13 +105,9 @@
</div> </div>
<div class="timeline-date-wrapper"> <div class="timeline-date-wrapper">
<a <a class="now-date" onClick={{this.updatePercentage}}>
class="now-date"
onClick={{this.updatePercentage}}
title={{this.nowDate}}
>
<span> <span>
{{this.nowDate}} {{age-with-tooltip this.nowDate this.nowDateOptions}}
</span> </span>
</a> </a>
</div> </div>

View File

@ -1,7 +1,6 @@
import Component from "@glimmer/component"; import Component from "@glimmer/component";
import { tracked } from "@glimmer/tracking"; import { tracked } from "@glimmer/tracking";
import { action } from "@ember/object"; import { action } from "@ember/object";
import { relativeAge } from "discourse/lib/formatter";
import I18n from "I18n"; import I18n from "I18n";
import { htmlSafe } from "@ember/template"; import { htmlSafe } from "@ember/template";
import { inject as service } from "@ember/service"; import { inject as service } from "@ember/service";
@ -153,22 +152,21 @@ export default class TopicTimelineScrollArea extends Component {
return this.lastReadTop > bottom ? bottom : this.lastReadTop; return this.lastReadTop > bottom ? bottom : this.lastReadTop;
} }
get bottomAge() {
return relativeAge(
new Date(this.args.model.last_posted_at || this.args.model.created_at),
{
addAgo: true,
defaultFormat: timelineDate,
}
);
}
get startDate() { get startDate() {
return timelineDate(this.args.model.createdAt); return timelineDate(this.args.model.createdAt);
} }
get nowDateOptions() {
return {
addAgo: true,
defaultFormat: timelineDate,
};
}
get nowDate() { get nowDate() {
return this.bottomAge; return (
this.args.model.get("last_posted_at") || this.args.model.get("created_at")
);
} }
get lastReadHeight() { get lastReadHeight() {

View File

@ -10,8 +10,14 @@ import { registerUnbound } from "discourse-common/lib/helpers";
registerUnbound("raw-date", (dt) => htmlSafe(longDate(new Date(dt)))); registerUnbound("raw-date", (dt) => htmlSafe(longDate(new Date(dt))));
registerUnbound("age-with-tooltip", (dt) => registerUnbound("age-with-tooltip", (dt, params) =>
htmlSafe(autoUpdatingRelativeAge(new Date(dt), { title: true })) htmlSafe(
autoUpdatingRelativeAge(new Date(dt), {
title: true,
addAgo: params.addAgo || false,
...(params.defaultFormat && { defaultFormat: params.defaultFormat }),
})
)
); );
registerUnbound("number", (orig, params) => { registerUnbound("number", (orig, params) => {