mirror of
https://github.com/discourse/discourse.git
synced 2025-05-25 19:01:27 +08:00
UX: Always use relative age for post notices.
This commit is contained in:
@ -13,7 +13,7 @@ import {
|
|||||||
formatUsername
|
formatUsername
|
||||||
} from "discourse/lib/utilities";
|
} from "discourse/lib/utilities";
|
||||||
import hbs from "discourse/widgets/hbs-compiler";
|
import hbs from "discourse/widgets/hbs-compiler";
|
||||||
import { relativeAge } from "discourse/lib/formatter";
|
import { durationTiny } from "discourse/lib/formatter";
|
||||||
|
|
||||||
function transformWithCallbacks(post) {
|
function transformWithCallbacks(post) {
|
||||||
let transformed = transformBasicPost(post);
|
let transformed = transformBasicPost(post);
|
||||||
@ -461,12 +461,10 @@ createWidget("post-notice", {
|
|||||||
text = I18n.t("post.notice.first", { user });
|
text = I18n.t("post.notice.first", { user });
|
||||||
} else if (attrs.postNoticeType === "returning") {
|
} else if (attrs.postNoticeType === "returning") {
|
||||||
icon = "far-smile";
|
icon = "far-smile";
|
||||||
|
const distance = (new Date() - new Date(attrs.postNoticeTime)) / 1000;
|
||||||
text = I18n.t("post.notice.return", {
|
text = I18n.t("post.notice.return", {
|
||||||
user,
|
user,
|
||||||
time: relativeAge(attrs.postNoticeTime, {
|
time: durationTiny(distance, { addAgo: true })
|
||||||
format: "tiny",
|
|
||||||
addAgo: true
|
|
||||||
})
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -874,11 +874,13 @@ widgetTest("pm map", {
|
|||||||
widgetTest("post notice - with username", {
|
widgetTest("post notice - with username", {
|
||||||
template: '{{mount-widget widget="post" args=args}}',
|
template: '{{mount-widget widget="post" args=args}}',
|
||||||
beforeEach() {
|
beforeEach() {
|
||||||
|
const date_2d_ago = new Date();
|
||||||
|
date_2d_ago.setDate(date_2d_ago.getDate() - 2);
|
||||||
this.siteSettings.prioritize_username_in_ux = true;
|
this.siteSettings.prioritize_username_in_ux = true;
|
||||||
this.siteSettings.old_post_notice_days = 14;
|
this.siteSettings.old_post_notice_days = 14;
|
||||||
this.set("args", {
|
this.set("args", {
|
||||||
postNoticeType: "returning",
|
postNoticeType: "returning",
|
||||||
postNoticeTime: new Date(2010, 0, 1),
|
postNoticeTime: date_2d_ago,
|
||||||
username: "codinghorror",
|
username: "codinghorror",
|
||||||
name: "Jeff",
|
name: "Jeff",
|
||||||
created_at: new Date()
|
created_at: new Date()
|
||||||
@ -889,7 +891,7 @@ widgetTest("post notice - with username", {
|
|||||||
find(".post-notice.returning-user:not(.old)")
|
find(".post-notice.returning-user:not(.old)")
|
||||||
.text()
|
.text()
|
||||||
.trim(),
|
.trim(),
|
||||||
I18n.t("post.notice.return", { user: "codinghorror", time: "Jan '10" })
|
I18n.t("post.notice.return", { user: "codinghorror", time: "2d ago" })
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user