your personal website on atproto - mirror
blento.app
1import type { CardDefinition } from '../../types';
2import UpcomingEventsCard from './UpcomingEventsCard.svelte';
3import type { Did } from '@atcute/lexicons';
4import type { EventData } from '../EventCard';
5
6const EVENT_COLLECTION = 'community.lexicon.calendar.event';
7
8export const UpcomingEventsCardDefinition = {
9 type: 'upcomingEvents',
10 contentComponent: UpcomingEventsCard,
11 createNew: (card) => {
12 card.w = 4;
13 card.h = 4;
14 card.mobileW = 8;
15 card.mobileH = 6;
16 },
17 minW: 2,
18 minH: 3,
19
20 loadData: async (_items, { did }) => {
21 const { listRecords } = await import('$lib/atproto/methods');
22 const records = await listRecords({
23 did: did as Did,
24 collection: EVENT_COLLECTION,
25 limit: 100
26 });
27
28 const now = new Date();
29 const events: Array<EventData & { rkey: string }> = [];
30
31 for (const record of records) {
32 const event = record.value as EventData;
33 const endsAt = event.endsAt ? new Date(event.endsAt) : null;
34 const startsAt = new Date(event.startsAt);
35
36 if ((endsAt && endsAt >= now) || (!endsAt && startsAt >= now)) {
37 const uri = record.uri as string;
38 const rkey = uri.split('/').pop() || '';
39 events.push({ ...event, rkey });
40 }
41 }
42
43 events.sort((a, b) => new Date(a.startsAt).getTime() - new Date(b.startsAt).getTime());
44
45 return { events };
46 },
47
48 name: 'Upcoming Events',
49 keywords: ['events', 'hosting', 'calendar', 'upcoming'],
50 groups: ['Social'],
51 icon: `<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" class="size-4"><path stroke-linecap="round" stroke-linejoin="round" d="M6.75 3v2.25M17.25 3v2.25M3 18.75V7.5a2.25 2.25 0 0 1 2.25-2.25h13.5A2.25 2.25 0 0 1 21 7.5v11.25m-18 0A2.25 2.25 0 0 0 5.25 21h13.5A2.25 2.25 0 0 0 21 18.75m-18 0v-7.5A2.25 2.25 0 0 1 5.25 9h13.5A2.25 2.25 0 0 1 21 11.25v7.5m-9-6h.008v.008H12v-.008ZM12 15h.008v.008H12V15Zm0 2.25h.008v.008H12v-.008ZM9.75 15h.008v.008H9.75V15Zm0 2.25h.008v.008H9.75v-.008ZM7.5 15h.008v.008H7.5V15Zm0 2.25h.008v.008H7.5v-.008Zm6.75-4.5h.008v.008h-.008v-.008Zm0 2.25h.008v.008h-.008V15Zm0 2.25h.008v.008h-.008v-.008Zm2.25-4.5h.008v.008H16.5v-.008Zm0 2.25h.008v.008H16.5V15Z" /></svg>`
52} as CardDefinition & { type: 'upcomingEvents' };