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