mirror of
https://github.com/discourse/discourse.git
synced 2025-01-26 15:00:44 +08:00
27 lines
816 B
JavaScript
27 lines
816 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))];
|
|
}
|
|
});
|