Show calendar errors in the upcoming events widget

Render the calendar service's error in the widget instead of the empty state, and clear a stale error at the start of each successful refresh cycle.
This commit is contained in:
raucao committed 2026-10-28 00:05:31 +04:00
1 parent ec2eab2e3d
commit b8705a5032
4 files changed
+54 -2

No files matched your search

+10 -2
View File
@@ -18,6 +18,10 @@ export default class UpcomingEventsComponent extends Component {
return this.events.today.length > 0 || this.events.days.length > 0;
}
get showEmptyState() {
return !this.hasEvents && !this.calendar.error;
}
// A fixed column keeps the rows aligned; it only needs room for a day period
// when the active format shows one (12-hour).
get timeColumnWidth() {
@@ -58,6 +62,10 @@ export default class UpcomingEventsComponent extends Component {
class="max-w-full max-h-full rounded-md bg-gray-950/10 p-6 text-white"
data-test-upcoming-events
>
{{#if this.calendar.error}}
<p class="mb-2 text-sm text-red-300">{{this.calendar.error}}</p>
{{/if}}
{{#if this.events.today.length}}
<h2
class="text-xs font-semibold tracking-wide text-white/70 uppercase"
@@ -96,9 +104,9 @@ export default class UpcomingEventsComponent extends Component {
</ul>
{{/each}}
{{#unless this.hasEvents}}
{{#if this.showEmptyState}}
<p class="text-base text-white/80">No upcoming events</p>
{{/unless}}
{{/if}}
</div>
{{/if}}
</template>
+4
View File
@@ -112,6 +112,7 @@ export default class CalendarService extends Service {
try {
await this.sockethub.acquire(CALENDAR_CONSUMER);
this.error = null;
} catch (err) {
console.error('Error connecting to Sockethub for calendars:', err);
this.error = classifyCalendarError(err);
@@ -296,6 +297,9 @@ export default class CalendarService extends Service {
return;
}
// A fresh cycle clears a stale error; failures set it again below.
this.error = null;
this.refreshPromise = Promise.all(
this.instances.map((instance) => this.refreshInstance(instance))
).finally(() => {
@@ -75,6 +75,21 @@ module('Integration | Component | upcoming-events', function (hooks) {
assert.dom().containsText('No upcoming events');
});
test('shows the calendar error instead of the empty state', async function (assert) {
registerServices(this.owner, {
enabled: true,
error: 'Unable to reach the Sockethub server',
events: { today: [], days: [] },
});
await render(<template><UpcomingEvents /></template>);
assert
.dom('[data-test-upcoming-events]')
.containsText('Unable to reach the Sockethub server');
assert.dom().doesNotContainText('No upcoming events');
});
test('labels all-day events', async function (assert) {
registerServices(this.owner, {
enabled: true,
+25
View File
@@ -223,6 +223,31 @@ module('Unit | Service | calendar', function (hooks) {
service.stopPolling();
});
test('a successful refresh clears a previous error', async function (assert) {
const { service } = await setup(this, {
handler: (message) =>
message.type === 'query' ? { items: [EVENT] } : { items: [] },
});
await service.configureCaldav({
url: 'https://cal.example/dav/',
username: 'alice',
password: 'secret',
calendars: [CALENDAR],
selectedCalendarIds: ['c1'],
});
// Let the refresh started by polling settle before starting a new cycle.
await service.refreshAll();
service.error = 'stale error';
await service.refreshAll();
assert.strictEqual(service.error, null);
service.stopPolling();
});
test('events groups cached events from enabled sources', async function (assert) {
const { service, cache } = await setup(this);