Omit year for current year, tweak layout
CI / Lint (pull_request) Successful in 1m2s
CI / Test (pull_request) Successful in 1m17s
Release Drafter / Update release notes draft (pull_request) Successful in 4s

This commit is contained in:
raucao committed 2026-08-29 15:50:49 -06:00
1 parent 919c0335eb
commit 23444a49a8
5 files changed
+124 -18

No files matched your search

+12 -11
View File
@@ -82,17 +82,18 @@ export default class ActivityZapItem extends Component {
</div>
{{/if}}
</div>
<span class="zap-context-text">
{{#if this.placeName}}
{{this.placeName}}
{{else if this.placeNameLoading}}
<span class="contribution-name-loading">Loading…</span>
{{else}}
<span class="contribution-name-loading">Unnamed place</span>
{{/if}}
·
{{formatRelativeDate @item.createdAt}}
</span>
<div class="zap-context-text">
<span class="zap-place-name">
{{#if this.placeName}}
{{this.placeName}}
{{else if this.placeNameLoading}}
<span class="contribution-name-loading">Loading…</span>
{{else}}
<span class="contribution-name-loading">Unnamed place</span>
{{/if}}
</span>
<span class="zap-date">{{formatRelativeDate @item.createdAt}}</span>
</div>
</div>
{{#if this.item.message}}
+18 -3
View File
@@ -2793,9 +2793,24 @@ button.create-place {
}
& .zap-context-text {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
display: flex;
align-items: baseline;
gap: 6px;
flex: 1 1 auto;
min-width: 0;
& .zap-place-name {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
flex: 1 1 auto;
min-width: 0;
}
& .zap-date {
flex-shrink: 0;
white-space: nowrap;
}
}
}
}
+2 -1
View File
@@ -26,9 +26,10 @@ export function formatRelativeDate(timestamp) {
if (diffMin < 60) return `${diffMin} min ago`;
if (diffHr < 24) return `${diffHr} hr ago`;
if (diffDay < 7) return `${diffDay} day${diffDay === 1 ? '' : 's'} ago`;
const isCurrentYear = date.getFullYear() === now.getFullYear();
return date.toLocaleDateString(undefined, {
year: 'numeric',
month: 'short',
day: 'numeric',
...(isCurrentYear ? {} : { year: 'numeric' }),
});
}
@@ -226,4 +226,71 @@ module('Integration | Component | activity-zap-item', function (hooks) {
.dom('.zap-context-text .contribution-name-loading')
.hasText('Unnamed place', 'Fallback name is displayed');
});
test('it displays place name in zap-place-name and date in zap-date', async function (assert) {
this.item = new ActivityEntry({
photoEventId: 'photo-1',
photo: null,
placeIdentifier: 'osm:node:12345',
senderPubkey: 'b'.repeat(64),
amountSats: 21,
message: null,
createdAt: Math.floor(Date.now() / 1000) - 3600, // 1 hour ago
});
this.item.senderName = 'Alice';
this.item.senderProfileLoading = false;
this.item.placeName = 'Café Central';
this.item.placeNameLoading = false;
await render(
<template>
<ActivityZapItem @item={{this.item}} @onSelect={{this.noop}} />
</template>
);
const placeNameEl = this.element.querySelector('.zap-place-name');
const dateEl = this.element.querySelector('.zap-date');
assert.ok(placeNameEl, 'zap-place-name element exists');
assert.ok(dateEl, 'zap-date element exists');
assert.ok(
placeNameEl.textContent.includes('Café Central'),
'Place name is in zap-place-name'
);
assert.ok(dateEl.textContent.includes('hr ago'), 'Date contains hr ago');
assert.notOk(
placeNameEl.textContent.includes('hr ago'),
'Place name does not contain date'
);
assert.notOk(
dateEl.textContent.includes('Café Central'),
'Date does not contain place name'
);
});
test('it truncates long place names with ellipsis while keeping date visible', async function (assert) {
this.item = new ActivityEntry({
photoEventId: 'photo-1',
photo: null,
placeIdentifier: 'osm:node:12345',
senderPubkey: 'b'.repeat(64),
amountSats: 21,
message: null,
createdAt: Math.floor(Date.now() / 1000) - 3600,
});
this.item.senderName = 'Alice';
this.item.senderProfileLoading = false;
this.item.placeName =
'A Very Long Place Name That Should Be Truncated With Ellipsis';
this.item.placeNameLoading = false;
await render(
<template>
<ActivityZapItem @item={{this.item}} @onSelect={{this.noop}} />
</template>
);
assert.dom('.zap-place-name').exists('zap-place-name element exists');
assert.dom('.zap-date').hasText('1 hr ago', 'Date is still visible');
});
});
+25 -3
View File
@@ -55,12 +55,34 @@ module('Unit | Utility | format-text', function () {
test('formatRelativeDate returns an absolute date for timestamps older than a week', function (assert) {
const now = Math.floor(Date.now() / 1000);
const oldTimestamp = now - 86400 * 30; // 30 days ago
const oldTimestamp = now - 86400 * 400; // 400 days ago (previous year)
const result = formatRelativeDate(oldTimestamp);
// The exact format depends on the locale, but it should contain a year
assert.ok(
result.includes(String(new Date().getFullYear())),
'Contains the year'
result.includes(String(new Date().getFullYear() - 1)),
'Contains the previous year'
);
});
test('formatRelativeDate omits year for same-year dates older than a week', function (assert) {
const now = Math.floor(Date.now() / 1000);
const sameYearTimestamp = now - 86400 * 30; // 30 days ago (same year)
const result = formatRelativeDate(sameYearTimestamp);
// Should NOT contain the current year
assert.notOk(
result.includes(String(new Date().getFullYear())),
'Does not contain the current year'
);
// Should contain month and day
const expectedMonth = new Date(sameYearTimestamp * 1000).toLocaleDateString(
undefined,
{ month: 'short' }
);
const expectedDay = new Date(sameYearTimestamp * 1000).toLocaleDateString(
undefined,
{ day: 'numeric' }
);
assert.ok(result.includes(expectedMonth), 'Contains month');
assert.ok(result.includes(expectedDay), 'Contains day');
});
});