This repository has been archived on 2023-03-18. You can view files and clone it, but cannot push or open issues or pull requests.
osr-discourse-src/app/assets/javascripts/discourse/widgets/time-gap.js.es6
Sam 42572ff138 Revert font awesome 5 changes
We are still pushing ahead on this 100% just need a bit longer to prepare
all plugins
2018-11-08 16:12:18 +11:00

29 lines
828 B
JavaScript

import { createWidget } from "discourse/widgets/widget";
import { h } from "virtual-dom";
import { iconNode } from "discourse-common/lib/icon-library";
function description(attrs) {
const daysSince = attrs.daysSince;
if (daysSince < 30) {
return I18n.t("dates.later.x_days", { count: daysSince });
} else if (daysSince < 365) {
const gapMonths = Math.round(daysSince / 30);
return I18n.t("dates.later.x_months", { count: gapMonths });
} else {
const gapYears = Math.round(daysSince / 365);
return I18n.t("dates.later.x_years", { count: gapYears });
}
}
export default createWidget("time-gap", {
tagName: "div.time-gap.small-action.clearfix",
html(attrs) {
return [
h("div.topic-avatar", iconNode("fw")),
h("div.small-action-desc.timegap", description(attrs))
];
}
});