your personal website on atproto - mirror
blento.app
1import { parseUri } from '$lib/atproto';
2import type { CardDefinition } from '../types';
3import CreateEventCardModal from './CreateEventCardModal.svelte';
4import EventCard from './EventCard.svelte';
5
6const EVENT_COLLECTION = 'community.lexicon.calendar.event';
7
8export type EventData = {
9 mode: string;
10 name: string;
11 status: string;
12 startsAt: string;
13 endsAt?: string;
14 description?: string;
15 locations?: Array<{
16 address?: {
17 locality?: string;
18 region?: string;
19 country?: string;
20 };
21 }>;
22 media?: Array<{
23 alt?: string;
24 role?: string;
25 content?: {
26 ref?: {
27 $link: string;
28 };
29 mimeType?: string;
30 };
31 aspect_ratio?: {
32 width: number;
33 height: number;
34 };
35 }>;
36 countGoing?: number;
37 countInterested?: number;
38 url: string;
39};
40
41export const EventCardDefinition = {
42 type: 'event',
43 contentComponent: EventCard,
44 creationModalComponent: CreateEventCardModal,
45 createNew: (card) => {
46 card.w = 4;
47 card.h = 4;
48 card.mobileW = 8;
49 card.mobileH = 6;
50 },
51
52 loadData: async (items) => {
53 const eventDataMap: Record<string, EventData> = {};
54
55 for (const item of items) {
56 const uri = item.cardData?.uri;
57 if (!uri) continue;
58
59 const parsedUri = parseUri(uri);
60 if (!parsedUri || !parsedUri.rkey || !parsedUri.repo) continue;
61
62 try {
63 const response = await fetch(
64 `https://smokesignal.events/xrpc/community.lexicon.calendar.GetEvent?repository=${encodeURIComponent(parsedUri.repo)}&record_key=${encodeURIComponent(parsedUri.rkey)}`
65 );
66
67 if (response.ok) {
68 const data = await response.json();
69 eventDataMap[item.id] = data as EventData;
70 }
71 } catch (error) {
72 console.error('Failed to fetch event data:', error);
73 }
74 }
75
76 return eventDataMap;
77 },
78
79 onUrlHandler: (url, item) => {
80 // Match smokesignal.events URLs: https://smokesignal.events/{did}/{rkey}
81 const smokesignalMatch = url.match(/^https?:\/\/smokesignal\.events\/(did:[^/]+)\/([^/?#]+)/);
82 if (smokesignalMatch) {
83 const [, did, rkey] = smokesignalMatch;
84 item.w = 4;
85 item.h = 4;
86 item.mobileW = 8;
87 item.mobileH = 6;
88 item.cardType = 'event';
89 item.cardData.uri = `at://${did}/${EVENT_COLLECTION}/${rkey}`;
90 return item;
91 }
92
93 // Match AT URIs: at://{did}/community.lexicon.calendar.event/{rkey}
94 const atUriMatch = url.match(/^at:\/\/(did:[^/]+)\/([^/]+)\/([^/?#]+)/);
95 if (atUriMatch) {
96 const [, did, collection, rkey] = atUriMatch;
97 if (collection === EVENT_COLLECTION) {
98 item.w = 4;
99 item.h = 4;
100 item.mobileW = 8;
101 item.mobileH = 6;
102 item.cardType = 'event';
103 item.cardData.uri = `at://${did}/${collection}/${rkey}`;
104 return item;
105 }
106 }
107
108 return null;
109 },
110
111 urlHandlerPriority: 5,
112
113 name: 'Event',
114
115 keywords: ['calendar', 'meetup', 'schedule', 'date', 'rsvp'],
116 groups: ['Social'],
117 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.5" /></svg>`
118} as CardDefinition & { type: 'event' };