Add the upcoming events widget
Reads the calendar service's cached events and renders today plus the next two days that have events, top-left on the dashboard.
This commit is contained in:
1 parent
e68d5cf23c
commit
e241c95fdb
2 files changed
+100
No files matched your search
@@ -0,0 +1,93 @@
|
||||
import Component from '@glimmer/component';
|
||||
import { service } from '@ember/service';
|
||||
|
||||
// Read-only dashboard widget. It renders the combined upcoming events from the
|
||||
// calendar service (which reads the persistent cache), so opening a tab does
|
||||
// not trigger a fetch.
|
||||
export default class UpcomingEventsComponent extends Component {
|
||||
@service calendar;
|
||||
|
||||
get events() {
|
||||
return this.calendar.events;
|
||||
}
|
||||
|
||||
get hasEvents() {
|
||||
return this.events.today.length > 0 || this.events.days.length > 0;
|
||||
}
|
||||
|
||||
formatTime(event) {
|
||||
if (event.allDay) {
|
||||
return 'All day';
|
||||
}
|
||||
|
||||
const date = new Date(event.startTime);
|
||||
return new Intl.DateTimeFormat(undefined, {
|
||||
hour: 'numeric',
|
||||
minute: '2-digit',
|
||||
}).format(date);
|
||||
}
|
||||
|
||||
formatDay(date) {
|
||||
const today = new Date();
|
||||
today.setHours(0, 0, 0, 0);
|
||||
|
||||
const tomorrow = new Date(today);
|
||||
tomorrow.setDate(tomorrow.getDate() + 1);
|
||||
|
||||
if (date.getTime() === tomorrow.getTime()) {
|
||||
return 'Tomorrow';
|
||||
}
|
||||
|
||||
return new Intl.DateTimeFormat(undefined, {
|
||||
weekday: 'long',
|
||||
month: 'short',
|
||||
day: 'numeric',
|
||||
}).format(date);
|
||||
}
|
||||
|
||||
<template>
|
||||
{{#if this.calendar.enabled}}
|
||||
<div class="w-64 text-white text-shadow-lg" data-test-upcoming-events>
|
||||
{{#if this.events.today.length}}
|
||||
<h2
|
||||
class="text-xs font-semibold tracking-wide text-white/70 uppercase"
|
||||
>
|
||||
Today
|
||||
</h2>
|
||||
<ul class="mt-2 space-y-1">
|
||||
{{#each this.events.today as |event|}}
|
||||
<li class="flex gap-2 text-sm">
|
||||
<span
|
||||
class="w-16 shrink-0 tabular-nums text-white/80"
|
||||
>{{this.formatTime event}}</span>
|
||||
<span class="font-medium">{{event.name}}</span>
|
||||
</li>
|
||||
{{/each}}
|
||||
</ul>
|
||||
{{/if}}
|
||||
|
||||
{{#each this.events.days as |day|}}
|
||||
<h2
|
||||
class="mt-4 text-xs font-semibold tracking-wide text-white/70 uppercase"
|
||||
>
|
||||
{{this.formatDay day.date}}
|
||||
</h2>
|
||||
<ul class="mt-2 space-y-1">
|
||||
{{#each day.events as |event|}}
|
||||
<li class="flex gap-2 text-sm">
|
||||
<span
|
||||
class="w-16 shrink-0 tabular-nums text-white/80"
|
||||
>{{this.formatTime event}}</span>
|
||||
<span class="font-medium">{{event.name}}</span>
|
||||
</li>
|
||||
{{/each}}
|
||||
</ul>
|
||||
{{/each}}
|
||||
|
||||
{{#unless this.hasEvents}}
|
||||
<p class="text-sm text-white/80">No upcoming events</p>
|
||||
{{/unless}}
|
||||
</div>
|
||||
{{/if}}
|
||||
</template>
|
||||
}
|
||||
@@ -3,6 +3,7 @@ import DefaultClock from '../components/default-clock.gjs';
|
||||
import BitcoinTicker from '../components/bitcoin-ticker.gjs';
|
||||
import SiteLinks from '../components/site-links.gjs';
|
||||
import IntegrationsToolbar from '../components/integrations-toolbar.gjs';
|
||||
import UpcomingEvents from '../components/upcoming-events.gjs';
|
||||
|
||||
<template>
|
||||
{{pageTitle "New Tab"}}
|
||||
@@ -13,6 +14,12 @@ import IntegrationsToolbar from '../components/integrations-toolbar.gjs';
|
||||
<IntegrationsToolbar />
|
||||
</div>
|
||||
|
||||
<div
|
||||
class="col-start-1 row-start-1 flex items-start justify-start pt-12 pl-12"
|
||||
>
|
||||
<UpcomingEvents />
|
||||
</div>
|
||||
|
||||
<div class="col-start-3 row-start-1 flex items-start justify-end pt-12 pr-12">
|
||||
<SiteLinks />
|
||||
</div>
|
||||
|
||||
Reference in new issue
Block a user