2016-01-04 15:18:09 -05:00
|
|
|
import { createWidget } from 'discourse/widgets/widget';
|
|
|
|
import { h } from 'virtual-dom';
|
|
|
|
import { iconNode } from 'discourse/helpers/fa-icon';
|
|
|
|
|
|
|
|
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.floor(daysSince / 30);
|
|
|
|
return I18n.t('dates.later.x_months', {count: gapMonths});
|
|
|
|
} else {
|
|
|
|
const gapYears = Math.floor(daysSince / 365);
|
|
|
|
return I18n.t('dates.later.x_years', {count: gapYears});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default createWidget('time-gap', {
|
2016-02-08 12:14:34 -05:00
|
|
|
tagName: 'div.time-gap.small-action.clearfix',
|
2016-01-04 15:18:09 -05:00
|
|
|
|
|
|
|
html(attrs) {
|
|
|
|
return [h('div.topic-avatar', iconNode('clock-o')),
|
|
|
|
h('div.small-action-desc', description(attrs))];
|
|
|
|
}
|
|
|
|
});
|